Skip to content

Commit

Permalink
Automate list of differing defaults for styles (#874)
Browse files Browse the repository at this point in the history
Update docstrings of BlueStyle, SciMLStyle, and YASStyle to contain the
computed list of options that are different from DefaultStyle.
  • Loading branch information
jonas-schulze authored Oct 5, 2024
1 parent 140ca77 commit 5f704e8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 55 deletions.
12 changes: 12 additions & 0 deletions src/JuliaFormatter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ include("fst.jl")
include("passes.jl")
include("align.jl")

function list_different_defaults(style)
options_style = pairs(options(style))
options_default = pairs(options(DefaultStyle()))
options_changed = setdiff(options_style, options_default)
sort!(options_changed; by = first)
io = IOBuffer()
for (key, val) in options_changed
println(io, "- `$key` = $val")
end
String(take!(io))
end

include("styles/default/pretty.jl")
include("styles/default/nest.jl")
include("styles/yas/pretty.jl")
Expand Down
37 changes: 15 additions & 22 deletions src/styles/blue/pretty.jl
Original file line number Diff line number Diff line change
@@ -1,25 +1,3 @@
"""
BlueStyle()
Formatting style based on [BlueStyle](https://github.com/invenia/BlueStyle)
and [JuliaFormatter#283](https://github.com/domluna/JuliaFormatter.jl/issues/283).
!!! note
This style is still work-in-progress, and does not yet implement all of the
BlueStyle guide.
Configurable options with different defaults to [`DefaultStyle`](@ref) are:
- `always_use_return` = true
- `short_to_long_function_def` = true
- `whitespace_ops_in_indices` = true
- `remove_extra_newlines` = true
- `always_for_in` = true
- `import_to_using` = true
- `pipe_to_function_call` = true
- `whitespace_in_kwargs` = false
- `annotate_untyped_fields_with_any` = false
- `separate_kwargs_with_semicolon` = true
"""
struct BlueStyle <: AbstractStyle
innerstyle::AbstractStyle
end
Expand Down Expand Up @@ -59,6 +37,21 @@ function options(style::BlueStyle)
)
end

@doc """
BlueStyle()
Formatting style based on [BlueStyle](https://github.com/invenia/BlueStyle)
and [JuliaFormatter#283](https://github.com/domluna/JuliaFormatter.jl/issues/283).
!!! note
This style is still work-in-progress, and does not yet implement all of the
BlueStyle guide.
Configurable options with different defaults to [`DefaultStyle`](@ref) are:
$(list_different_defaults(BlueStyle()))
"""
BlueStyle

function is_binaryop_nestable(::BlueStyle, cst::CSTParser.EXPR)
is_assignment(cst) && is_iterable(cst[end]) && return false
return is_binaryop_nestable(DefaultStyle(), cst)
Expand Down
28 changes: 13 additions & 15 deletions src/styles/sciml/pretty.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""
SciMLStyle()
Formatting style based on [SciMLStyle](https://github.com/SciML/SciMLStyle).
!!! note
This style is still work-in-progress.
Configurable options with different defaults to [`DefaultStyle`](@ref) are:
- `whitespace_ops_in_indices` = true
- `remove_extra_newlines` = true
- `always_for_in` = true
- `whitespace_typedefs` = true,
- `normalize_line_endings` = "unix"
"""
struct SciMLStyle <: AbstractStyle
innerstyle::AbstractStyle
end
Expand Down Expand Up @@ -53,6 +38,19 @@ function options(style::SciMLStyle)
)
end

@doc """
SciMLStyle()
Formatting style based on [SciMLStyle](https://github.com/SciML/SciMLStyle).
!!! note
This style is still work-in-progress.
Configurable options with different defaults to [`DefaultStyle`](@ref) are:
$(list_different_defaults(SciMLStyle()))
"""
SciMLStyle

function is_binaryop_nestable(::SciMLStyle, cst::CSTParser.EXPR)
(CSTParser.defines_function(cst) || is_assignment(cst)) && return false
((cst[2]::CSTParser.EXPR).val in ("=>", "->", "in")) && return false
Expand Down
29 changes: 11 additions & 18 deletions src/styles/yas/pretty.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
"""
YASStyle()
Formatting style based on [YASGuide](https://github.com/jrevels/YASGuide)
and [JuliaFormatter#198](https://github.com/domluna/JuliaFormatter.jl/issues/198).
Configurable options with different defaults to [`DefaultStyle`](@ref) are:
- `always_for_in` = true
- `whitespace_ops_in_indices` = true
- `remove_extra_newlines` = true
- `import_to_using` = true
- `pipe_to_function_call` = true
- `short_to_long_function_def` = true
- `always_use_return` = true
- `whitespace_in_kwargs` = false
- `join_lines_based_on_source` = true
- `separate_kwargs_with_semicolon` = true
"""
struct YASStyle <: AbstractStyle
innerstyle::AbstractStyle
end
Expand Down Expand Up @@ -55,6 +37,17 @@ function options(style::YASStyle)
)
end

@doc """
YASStyle()
Formatting style based on [YASGuide](https://github.com/jrevels/YASGuide)
and [JuliaFormatter#198](https://github.com/domluna/JuliaFormatter.jl/issues/198).
Configurable options with different defaults to [`DefaultStyle`](@ref) are:
$(list_different_defaults(YASStyle()))
"""
YASStyle

function is_binaryop_nestable(::YASStyle, cst::CSTParser.EXPR)
(CSTParser.defines_function(cst) || is_assignment(cst)) && return false
(cst[2].val == "=>" || cst[2].val == "->") && return false
Expand Down

0 comments on commit 5f704e8

Please sign in to comment.