Skip to content

Commit

Permalink
Add MinimalStyle (#606)
Browse files Browse the repository at this point in the history
* Add MinimalStyle

* Format files
  • Loading branch information
davidanthoff authored Jun 17, 2022
1 parent 4bbe2d0 commit 5f2cc86
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/JuliaFormatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ include("styles/blue/pretty.jl")
include("styles/blue/nest.jl")
include("styles/sciml/pretty.jl")
include("styles/sciml/nest.jl")
include("styles/minimal/pretty.jl")

include("nest_utils.jl")

Expand Down Expand Up @@ -832,14 +833,20 @@ function parse_config(tomlfile)
end
if (style = get(config_dict, "style", nothing)) !== nothing
@assert (
style == "default" || style == "yas" || style == "blue" || style == "sciml"
) "currently $(CONFIG_FILE_NAME) accepts only \"default\" or \"yas\", \"blue\", or \"sciml\" for the style configuration"
style == "default" ||
style == "yas" ||
style == "blue" ||
style == "sciml" ||
style == "minimal"
) "currently $(CONFIG_FILE_NAME) accepts only \"default\" or \"yas\", \"blue\", \"sciml\", or \"minimal\" for the style configuration"
config_dict["style"] = if (style == "yas" && @isdefined(YASStyle))
YASStyle()
elseif (style == "blue" && @isdefined(BlueStyle))
BlueStyle()
elseif (style == "sciml" && @isdefined(SciMLStyle))
SciMLStyle()
elseif (style == "minimal" && @isdefined(MinimalStyle))
MinimalStyle()
else
DefaultStyle()
end
Expand Down
2 changes: 1 addition & 1 deletion src/other/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ function _precompile_()
Base.precompile(Tuple{typeof(pretty),DefaultStyle,CSTParser.EXPR,State})
Base.precompile(Tuple{typeof(pretty),YASStyle,CSTParser.EXPR,State})
Base.precompile(Tuple{typeof(pretty),BlueStyle,CSTParser.EXPR,State})

Base.precompile(Tuple{typeof(pretty),MinimalStyle,CSTParser.EXPR,State})
end
38 changes: 38 additions & 0 deletions src/styles/minimal/pretty.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""
MinimalStyle()
"""
struct MinimalStyle <: AbstractStyle
innerstyle::Union{Nothing,AbstractStyle}
end
MinimalStyle() = MinimalStyle(nothing)

@inline getstyle(s::MinimalStyle) = s.innerstyle === nothing ? s : s.innerstyle

function options(style::MinimalStyle)
return (;
indent = 4,
annotate_untyped_fields_with_any = false,
join_lines_based_on_source = true,
trailing_comma = nothing,
margin = 10_000,
always_for_in = nothing,
whitespace_in_kwargs = false,
whitespace_typedefs = false,
whitespace_ops_in_indices = false,
remove_extra_newlines = false,
import_to_using = false,
pipe_to_function_call = false,
short_to_long_function_def = false,
always_use_return = false,
format_docstrings = false,
align_struct_field = false,
align_assignment = false,
align_conditional = false,
align_pair_arrow = false,
conditional_to_if = false,
normalize_line_endings = "auto",
align_matrix = false,
indent_submodule = false,
separate_kwargs_with_semicolon = false,
)
end

0 comments on commit 5f2cc86

Please sign in to comment.