From 5f704e89b253232c3b07ff3812446f28bef9325e Mon Sep 17 00:00:00 2001 From: Jonas Schulze Date: Sat, 5 Oct 2024 02:17:55 +0200 Subject: [PATCH] Automate list of differing defaults for styles (#874) Update docstrings of BlueStyle, SciMLStyle, and YASStyle to contain the computed list of options that are different from DefaultStyle. --- src/JuliaFormatter.jl | 12 ++++++++++++ src/styles/blue/pretty.jl | 37 +++++++++++++++---------------------- src/styles/sciml/pretty.jl | 28 +++++++++++++--------------- src/styles/yas/pretty.jl | 29 +++++++++++------------------ 4 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/JuliaFormatter.jl b/src/JuliaFormatter.jl index 43bf3e54e..427d7033d 100644 --- a/src/JuliaFormatter.jl +++ b/src/JuliaFormatter.jl @@ -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") diff --git a/src/styles/blue/pretty.jl b/src/styles/blue/pretty.jl index 5c01725d0..a0f15ed1d 100644 --- a/src/styles/blue/pretty.jl +++ b/src/styles/blue/pretty.jl @@ -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 @@ -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) diff --git a/src/styles/sciml/pretty.jl b/src/styles/sciml/pretty.jl index 01ff1f142..79d4cd8e5 100644 --- a/src/styles/sciml/pretty.jl +++ b/src/styles/sciml/pretty.jl @@ -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 @@ -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 diff --git a/src/styles/yas/pretty.jl b/src/styles/yas/pretty.jl index 86d5ffb11..e2e49766c 100644 --- a/src/styles/yas/pretty.jl +++ b/src/styles/yas/pretty.jl @@ -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 @@ -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