From ca55c40c5bb75850008b896ea21f5da28d124167 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Tue, 17 May 2022 14:03:38 +0100 Subject: [PATCH 1/2] Remove profiles 'compact' and 'sparse' --- CHANGES.md | 2 + lib/Conf.ml | 66 +-------- lib/Version.ml | 11 +- lib/Version.mli | 10 +- ocamlformat-help.txt | 260 ++++++++++++++--------------------- test/cli/deprecated_option.t | 9 -- 6 files changed, 131 insertions(+), 227 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 95476760af..c80d6f8738 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ### Removed +- Profiles `compact` and `sparse` are now removed (#, @gpetiot) + ### Deprecated - Cancel the deprecations of options that are not set by the preset profiles (#2074, @gpetiot) diff --git a/lib/Conf.ml b/lib/Conf.ml index d4b27ed99d..52b4469ac2 100644 --- a/lib/Conf.ml +++ b/lib/Conf.ml @@ -1568,61 +1568,6 @@ let conventional_profile = let default_profile = conventional_profile -let compact_profile = - { ocamlformat_profile with - break_before_in= `Auto - ; break_cases= `Fit - ; break_collection_expressions= `Wrap - ; break_infix= `Wrap - ; break_fun_decl= `Wrap - ; break_fun_sig= `Wrap - ; break_sequences= false - ; break_struct= false - ; doc_comments_tag_only= `Fit - ; exp_grouping= `Parens - ; field_space= `Tight - ; if_then_else= `Compact - ; indicate_nested_or_patterns= `Space - ; leading_nested_match_parens= false - ; let_and= `Compact - ; let_binding_spacing= `Compact - ; let_module= `Compact - ; module_item_spacing= `Compact - ; single_case= `Compact - ; space_around_arrays= false - ; space_around_lists= false - ; space_around_records= false - ; space_around_variants= false - ; type_decl= `Compact - ; wrap_fun_args= true } - -let sparse_profile = - { ocamlformat_profile with - break_before_in= `Fit_or_vertical - ; break_cases= `Nested - ; break_collection_expressions= `Fit_or_vertical - ; break_infix= `Fit_or_vertical - ; break_fun_decl= `Smart - ; break_fun_sig= `Smart - ; break_sequences= true - ; break_struct= true - ; field_space= `Loose - ; if_then_else= `Keyword_first - ; indicate_nested_or_patterns= `Space - ; leading_nested_match_parens= true - ; let_and= `Sparse - ; let_binding_spacing= `Sparse - ; let_module= `Sparse - ; module_item_spacing= `Sparse - ; single_case= `Sparse - ; sequence_blank_line= `Preserve_one - ; space_around_arrays= true - ; space_around_lists= true - ; space_around_records= true - ; space_around_variants= true - ; type_decl= `Sparse - ; wrap_fun_args= false } - let janestreet_profile = { align_constructors_decl= false ; align_cases= false @@ -1702,14 +1647,6 @@ let (_profile : fmt_opts option C.t) = \"conventional\" appearing as the available options allow." ; C.Value.make ~name:"default" (Some default_profile) "$(b,default) is an alias for the $(b,conventional) profile." - ; C.Value.make ~name:"compact" (Some compact_profile) - ~deprecated:deprecated_orphan - "The $(b,compact) profile is similar to $(b,ocamlformat) but opts \ - for a generally more compact code style." - ; C.Value.make ~name:"sparse" (Some sparse_profile) - ~deprecated:deprecated_orphan - "The $(b,sparse) profile is similar to $(b,ocamlformat) but opts \ - for a generally more sparse code style." ; C.Value.make ~name:"ocamlformat" (Some ocamlformat_profile) "The $(b,ocamlformat) profile aims to take advantage of the \ strengths of a parsetree-based auto-formatter, and to limit the \ @@ -1731,6 +1668,9 @@ let (_profile : fmt_opts option C.t) = "The $(b,janestreet) profile is used at Jane Street." ] in C.choice ~names ~all ~doc ~kind:C.Formatting + ~removed_values: + [ C.Value_removed.make ~name:"compact" ~since:V0_22_0 ~msg:"" + ; C.Value_removed.make ~name:"sparse" ~since:V0_22_0 ~msg:"" ] (fun conf p -> selected_profile_ref := p ; let new_fmt_opts = Option.value p ~default:conf.fmt_opts in diff --git a/lib/Version.ml b/lib/Version.ml index cdf88f58de..03de50d52c 100644 --- a/lib/Version.ml +++ b/lib/Version.ml @@ -9,7 +9,15 @@ (* *) (**************************************************************************) -type t = V0_10_0 | V0_12_0 | V0_14_2 | V0_16_0 | V0_17_0 | V0_20_0 | V1_0_0 +type t = + | V0_10_0 + | V0_12_0 + | V0_14_2 + | V0_16_0 + | V0_17_0 + | V0_20_0 + | V0_22_0 + | V1_0_0 let to_string = function | V0_10_0 -> "0.10.0" @@ -18,6 +26,7 @@ let to_string = function | V0_16_0 -> "0.16.0" | V0_17_0 -> "0.17.0" | V0_20_0 -> "0.20.0" + | V0_22_0 -> "0.22.0" | V1_0_0 -> "1.0.0" let pp fs v = Format.fprintf fs "%s" (to_string v) diff --git a/lib/Version.mli b/lib/Version.mli index b440706480..a3bc9ec87e 100644 --- a/lib/Version.mli +++ b/lib/Version.mli @@ -9,7 +9,15 @@ (* *) (**************************************************************************) -type t = V0_10_0 | V0_12_0 | V0_14_2 | V0_16_0 | V0_17_0 | V0_20_0 | V1_0_0 +type t = + | V0_10_0 + | V0_12_0 + | V0_14_2 + | V0_16_0 + | V0_17_0 + | V0_20_0 + | V0_22_0 + | V1_0_0 val to_string : t -> string diff --git a/ocamlformat-help.txt b/ocamlformat-help.txt index a823852601..c69ca3e73d 100644 --- a/ocamlformat-help.txt +++ b/ocamlformat-help.txt @@ -52,6 +52,13 @@ OPTIONS (CODE FORMATTING STYLE) assignment expression does not fit on a single line. The default value is end-line. + --break-before-in={fit-or-vertical|auto} + Whether the line should break before the in keyword of a let + binding. fit-or-vertical will always break the line before the in + keyword if the whole let binding does not fit on a single line. + auto will only break the line if the in keyword does not fit on + the previous line. The default value is fit-or-vertical. + --break-cases={fit|nested|toplevel|fit-or-vertical|all} Break pattern match cases. Specifying fit lets pattern matches break at the margin naturally. nested forces a break after nested @@ -59,28 +66,29 @@ OPTIONS (CODE FORMATTING STYLE) indicate-nested-or-patterns option is not needed, and so ignored. toplevel forces top-level cases (i.e. not nested or-patterns) to break across lines, otherwise break naturally at the margin. - Warning: Value `toplevel` is deprecated since version 0.20.0. It - will be removed by version 1.0.0. fit-or-vertical tries to fit all - or-patterns on the same line, otherwise breaks. all forces all - pattern matches to break across lines. Warning: Value `all` is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. The default value is fit. + fit-or-vertical tries to fit all or-patterns on the same line, + otherwise breaks. all forces all pattern matches to break across + lines. The default value is fit. + + --break-collection-expressions={fit-or-vertical|wrap} + Break collection expressions (lists and arrays) elements by + elements. fit-or-vertical vertically breaks expressions if they do + not fit on a single line. wrap will group simple expressions and + try to format them in a single line. The default value is + fit-or-vertical. --break-fun-decl={wrap|fit-or-vertical|smart} Style for function declarations and types. wrap breaks only if necessary. fit-or-vertical vertically breaks arguments if they do not fit on a single line. smart is like fit-or-vertical but try to - fit arguments on their line if they fit. Warning: Value `smart` is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. The default value is wrap. + fit arguments on their line if they fit. The default value is + wrap. --break-fun-sig={wrap|fit-or-vertical|smart} Style for function signatures. wrap breaks only if necessary. fit-or-vertical vertically breaks arguments if they do not fit on a single line. smart is like fit-or-vertical but try to fit - arguments on their line if they fit. Warning: Value `smart` is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. The default value is wrap. + arguments on their line if they fit. The default value is wrap. --break-infix={wrap|fit-or-vertical} Break sequence of infix operators. wrap will group simple @@ -104,6 +112,17 @@ OPTIONS (CODE FORMATTING STYLE) Force sequence expressions to break irrespective of margin. The flag is set by default. + --break-string-literals={auto|never} + Break string literals. auto mode breaks lines at newlines and + wraps string literals at the margin. never mode formats string + literals as they are parsed, in particular, with escape sequences + expanded. The default value is auto. + + --break-struct={force|natural} + Break struct-end module items. force will break struct-end phrases + unconditionally. natural will break struct-end phrases naturally + at the margin. The default value is force. + --cases-exp-indent=COLS Indentation of cases expressions (COLS columns). See also the cases-matching-exp-indent and nested-match options. The default @@ -115,6 +134,10 @@ OPTIONS (CODE FORMATTING STYLE) compact forces an indentation of 2, unless nested-match is set to align and we're on the last case. The default value is normal. + --disambiguate-non-breaking-match + Add parentheses around matching constructs that fit on a single + line. The flag is unset by default. + --doc-comments={after-when-possible|before-except-val|before} Doc comments position. after-when-possible puts doc comments after the corresponding code. This option has no effect on variant @@ -146,6 +169,10 @@ OPTIONS (CODE FORMATTING STYLE) (parentheses or begin/end). The default value is parens. Cannot be set in attributes. + --extension-indent=COLS + Indentation of items inside extension nodes (COLS columns). The + default value is 2. + --field-space={loose|tight|tight-decl} Whether or not to use a space between a field name and the rhs. This option affects records and objects. loose does. tight does @@ -153,27 +180,37 @@ OPTIONS (CODE FORMATTING STYLE) (`:` or `=`). tight-decl is tight for declarations and loose for instantiations. The default value is loose. + --function-indent=COLS + Indentation of function cases (COLS columns). The default value is + 2. + + --function-indent-nested={never|always|auto} + Whether the function-indent parameter should be applied even when + in a sub-block. never only applies function-indent if the function + block starts a line. always always apply function-indent. auto + applies function-indent when seen fit. The default value is never. + --if-then-else={compact|fit-or-vertical|keyword-first|k-r} If-then-else formatting. compact tries to format an if-then-else expression on a single line. fit-or-vertical vertically breaks - branches if they do not fit on a single line. Warning: Value - `fit-or-vertical` is deprecated since version 0.20.0. It will be - removed by version 1.0.0. keyword-first formats if-then-else - expressions such that the if-then-else keywords are the first on - the line. k-r formats if-then-else expressions with parentheses - that match the K&R style. Warning: Value `k-r` is deprecated since - version 0.20.0. It will be removed by version 1.0.0. The default + branches if they do not fit on a single line. keyword-first + formats if-then-else expressions such that the if-then-else + keywords are the first on the line. k-r formats if-then-else + expressions with parentheses that match the K&R style. The default value is compact. + --indent-after-in=COLS + Indentation (COLS columns) after `let ... in`, unless followed by + another `let`. The default value is 0. Cannot be set in + attributes. + --indicate-multiline-delimiters={no|space|closing-on-separate-line} How to indicate that two matching delimiters live on different lines. no doesn't do anything special to indicate the closing delimiter. space prints a space inside the delimiter to indicate the matching one is on a different line. closing-on-separate-line - makes sure that the closing delimiter is on its own line. Warning: - Value `closing-on-separate-line` is deprecated since version - 0.20.0. It will be removed by version 1.0.0. The default value is - no. + makes sure that the closing delimiter is on its own line. The + default value is no. --indicate-nested-or-patterns={unsafe-no|space} Control whether or not to indicate nested or-pattern using @@ -200,15 +237,18 @@ OPTIONS (CODE FORMATTING STYLE) in a single line. sparse will always break between them. The default value is compact. + --let-binding-indent=COLS + Indentation of let binding expressions (COLS columns) if they do + not fit on a single line. The default value is 2. Cannot be set in + attributes. + --let-binding-spacing={compact|sparse|double-semicolon} Spacing between let binding. compact spacing separates adjacent let bindings in a module according to module-item-spacing. sparse places two open lines between a multi-line module-level let - binding and the next. Warning: Value `sparse` is deprecated since - version 0.20.0. It will be removed by version 1.0.0. - double-semicolon places double semicolons and an open line between - a multi-line module-level let binding and the next. The default - value is compact. + binding and the next. double-semicolon places double semicolons + and an open line between a multi-line module-level let binding and + the next. The default value is compact. --let-module={compact|sparse} Module binding formatting. compact does not break a line after the @@ -226,6 +266,16 @@ OPTIONS (CODE FORMATTING STYLE) Format code to fit within COLS columns. The default value is 80. Cannot be set in attributes. + --match-indent=COLS + Indentation of match/try cases (COLS columns). The default value + is 0. + + --match-indent-nested={never|always|auto} + Whether the match-indent parameter should be applied even when in + a sub-block. never only applies match-indent if the match block + starts a line. always always apply match-indent. auto applies + match-indent when seen fit. The default value is never. + --max-indent=COLS Maximum offset (COLS columns) added to a new line in addition to the offset of the previous line. The default value is 68. Cannot @@ -236,9 +286,14 @@ OPTIONS (CODE FORMATTING STYLE) not leave open lines between one-liners of similar sorts. sparse will always break a line between two items. preserve will not leave open lines between one-liners of similar sorts unless there - is an open line in the input. Warning: Value `preserve` is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. The default value is compact. + is an open line in the input. The default value is compact. + + --nested-match={wrap|align} + Style of a pattern-matching nested in the last case of another + pattern-matching. wrap wraps the nested pattern-matching with + parentheses and adds indentation. align vertically aligns the + nested pattern-matching under the encompassing pattern-matching. + The default value is wrap. --no-break-infix-before-func Unset break-infix-before-func. @@ -246,6 +301,9 @@ OPTIONS (CODE FORMATTING STYLE) --no-break-sequences Unset break-sequences. + --no-disambiguate-non-breaking-match + Unset disambiguate-non-breaking-match. + --no-dock-collection-brackets Unset dock-collection-brackets. @@ -286,18 +344,12 @@ OPTIONS (CODE FORMATTING STYLE) Attempt to generate output which does not change (much) when post-processing with ocp-indent. The flag is unset by default. - -p {conventional|default|compact|sparse|ocamlformat|janestreet}, - --profile={conventional|default|compact|sparse|ocamlformat|janestreet} + -p {conventional|default|ocamlformat|janestreet}, + --profile={conventional|default|ocamlformat|janestreet} Select a preset profile which sets all options, overriding lower priority configuration. The conventional profile aims to be as familiar and "conventional" appearing as the available options allow. default is an alias for the conventional profile. The - compact profile is similar to ocamlformat but opts for a generally - more compact code style. Warning: Value `compact` is deprecated - since version 0.20.0. It will be removed by version 1.0.0. The - sparse profile is similar to ocamlformat but opts for a generally - more sparse code style. Warning: Value `sparse` is deprecated - since version 0.20.0. It will be removed by version 1.0.0. The ocamlformat profile aims to take advantage of the strengths of a parsetree-based auto-formatter, and to limit the consequences of the weaknesses imposed by the current implementation. This is a @@ -324,6 +376,12 @@ OPTIONS (CODE FORMATTING STYLE) tuples. multi-line-only mode will try to skip parens for single-line tuples. The default value is always. + --parens-tuple-patterns={multi-line-only|always} + Parens tuple patterns. multi-line-only mode will try to skip + parens for single-line tuple patterns. always always uses + parentheses around tuples patterns. The default value is + multi-line-only. + --parse-docstrings Parse and format docstrings. The flag is unset by default. @@ -341,9 +399,7 @@ OPTIONS (CODE FORMATTING STYLE) --sequence-style={terminator|separator|before} Style of sequence. terminator only puts spaces after semicolons. separator puts spaces before and after semicolons. before breaks - the sequence before semicolons. Warning: Value `before` is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. The default value is terminator. + the sequence before semicolons. The default value is terminator. --single-case={compact|sparse} Style of pattern matching expressions with only a single case. @@ -367,12 +423,21 @@ OPTIONS (CODE FORMATTING STYLE) Add a space inside the delimiters of variants. The flag is set by default. + --stritem-extension-indent=COLS + Indentation of structure items inside extension nodes (COLS + columns). The default value is 0. + --type-decl={compact|sparse} Style of type declaration. compact will try to format constructors and records definition in a single line. sparse will always break between constructors and record fields. The default value is compact. + --type-decl-indent=COLS + Indentation of type declarations (COLS columns) if they do not fit + on a single line. The default value is 2. Cannot be set in + attributes. + --wrap-comments Wrap comments and docstrings. Comments and docstrings are divided into paragraphs by open lines (two or more consecutive newlines), @@ -432,99 +497,10 @@ OPTIONS (DEPRECATED) default. Warning: This option is deprecated since version 0.20.0. It will be removed by version 1.0.0. - --break-before-in={fit-or-vertical|auto} - Whether the line should break before the in keyword of a let - binding. fit-or-vertical will always break the line before the in - keyword if the whole let binding does not fit on a single line. - auto will only break the line if the in keyword does not fit on - the previous line. The default value is fit-or-vertical. Warning: - This option is deprecated since version 0.20.0. It will be removed - by version 1.0.0. - - --break-collection-expressions={fit-or-vertical|wrap} - Break collection expressions (lists and arrays) elements by - elements. fit-or-vertical vertically breaks expressions if they do - not fit on a single line. wrap will group simple expressions and - try to format them in a single line. The default value is - fit-or-vertical. Warning: This option is deprecated since version - 0.20.0. It will be removed by version 1.0.0. - - --break-string-literals={auto|never} - Break string literals. auto mode breaks lines at newlines and - wraps string literals at the margin. never mode formats string - literals as they are parsed, in particular, with escape sequences - expanded. The default value is auto. Warning: This option is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. - - --break-struct={force|natural} - Break struct-end module items. force will break struct-end phrases - unconditionally. natural will break struct-end phrases naturally - at the margin. The default value is force. Warning: This option is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. - --disable-outside-detected-project Warning: this option is deprecated and will be removed by OCamlFormat v1.0. - --disambiguate-non-breaking-match - Add parentheses around matching constructs that fit on a single - line. The flag is unset by default. Warning: This option is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. - - --extension-indent=COLS - Indentation of items inside extension nodes (COLS columns). The - default value is 2. Warning: This option is deprecated since - version 0.20.0. It will be removed by version 1.0.0. - - --function-indent=COLS - Indentation of function cases (COLS columns). The default value is - 2. Warning: This option is deprecated since version 0.20.0. It - will be removed by version 1.0.0. - - --function-indent-nested={never|always|auto} - Whether the function-indent parameter should be applied even when - in a sub-block. never only applies function-indent if the function - block starts a line. always always apply function-indent. auto - applies function-indent when seen fit. The default value is never. - Warning: This option is deprecated since version 0.20.0. It will - be removed by version 1.0.0. - - --indent-after-in=COLS - Indentation (COLS columns) after `let ... in`, unless followed by - another `let`. The default value is 0. Cannot be set in - attributes. Warning: This option is deprecated since version - 0.20.0. It will be removed by version 1.0.0. - - --let-binding-indent=COLS - Indentation of let binding expressions (COLS columns) if they do - not fit on a single line. The default value is 2. Cannot be set in - attributes. Warning: This option is deprecated since version - 0.20.0. It will be removed by version 1.0.0. - - --match-indent=COLS - Indentation of match/try cases (COLS columns). The default value - is 0. Warning: This option is deprecated since version 0.20.0. It - will be removed by version 1.0.0. - - --match-indent-nested={never|always|auto} - Whether the match-indent parameter should be applied even when in - a sub-block. never only applies match-indent if the match block - starts a line. always always apply match-indent. auto applies - match-indent when seen fit. The default value is never. Warning: - This option is deprecated since version 0.20.0. It will be removed - by version 1.0.0. - - --nested-match={wrap|align} - Style of a pattern-matching nested in the last case of another - pattern-matching. wrap wraps the nested pattern-matching with - parentheses and adds indentation. align vertically aligns the - nested pattern-matching under the encompassing pattern-matching. - The default value is wrap. Warning: This option is deprecated - since version 0.20.0. It will be removed by version 1.0.0. - --no-align-cases Unset align-cases. @@ -534,28 +510,6 @@ OPTIONS (DEPRECATED) --no-align-variants-decl Unset align-variants-decl. - --no-disambiguate-non-breaking-match - Unset disambiguate-non-breaking-match. - - --parens-tuple-patterns={multi-line-only|always} - Parens tuple patterns. multi-line-only mode will try to skip - parens for single-line tuple patterns. always always uses - parentheses around tuples patterns. The default value is - multi-line-only. Warning: This option is deprecated since version - 0.20.0. It will be removed by version 1.0.0. - - --stritem-extension-indent=COLS - Indentation of structure items inside extension nodes (COLS - columns). The default value is 0. Warning: This option is - deprecated since version 0.20.0. It will be removed by version - 1.0.0. - - --type-decl-indent=COLS - Indentation of type declarations (COLS columns) if they do not fit - on a single line. The default value is 2. Cannot be set in - attributes. Warning: This option is deprecated since version - 0.20.0. It will be removed by version 1.0.0. - OPTIONS Unless mentioned otherwise non-formatting options cannot be set in attributes or .ocamlformat files. diff --git a/test/cli/deprecated_option.t b/test/cli/deprecated_option.t index e659e477bc..5a25ce247f 100644 --- a/test/cli/deprecated_option.t +++ b/test/cli/deprecated_option.t @@ -7,17 +7,8 @@ Setting a deprecated option or a deprecated option value on the command line sho $ ocamlformat a.ml --disambiguate-non-breaking-match let x = y - $ ocamlformat a.ml --profile sparse - Warning: option `profile`: value `sparse` is deprecated since version 0.20.0. It will be removed by version 1.0.0. - let x = y - A warning is also reported if a deprecated option or a deprecated option value is set in an .ocamlformat file: $ echo 'disambiguate-non-breaking-match = true' > .ocamlformat $ ocamlformat a.ml let x = y - - $ echo 'profile = sparse' > .ocamlformat - $ ocamlformat a.ml - Warning: option `profile`: value `sparse` is deprecated since version 0.20.0. It will be removed by version 1.0.0. - let x = y From 97bfdd1b5c1ec319f1a03f4fce2bea2b6104a1d7 Mon Sep 17 00:00:00 2001 From: Guillaume Petiot Date: Tue, 17 May 2022 14:10:08 +0100 Subject: [PATCH 2/2] Update CHANGES.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c80d6f8738..321405558e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,7 @@ ### Removed -- Profiles `compact` and `sparse` are now removed (#, @gpetiot) +- Profiles `compact` and `sparse` are now removed (#2075, @gpetiot) ### Deprecated