Skip to content

Commit

Permalink
First draft of a diff-friendly profile
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Oct 7, 2022
1 parent 61f5f9d commit cadc1c1
Show file tree
Hide file tree
Showing 7 changed files with 10,905 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Format `.mld` files as odoc documentation files (#2008, @gpetiot)
- New value `vertical` for option `if-then-else` (#2174, @gpetiot)
- New value `vertical` for option `break-cases` (#2176, @gpetiot)
- New profile: `diff-friendly`, aiming to minimize the vertical diff (#2020, @gpetiot)

## 0.24.1 (2022-07-18)

Expand Down
65 changes: 65 additions & 0 deletions lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,69 @@ let conventional_profile =

let default_profile = conventional_profile

let diff_friendly_profile =
{ align_pattern_matching_bar= `Keyword
; assignment_operator= `End_line
; break_before_in= `Fit_or_vertical
; break_cases= `Vertical
; break_collection_expressions= `Fit_or_vertical
; break_colon= `After
; break_infix= `Fit_or_vertical
; break_infix_before_func= true
; break_fun_decl= `Fit_or_vertical
; break_fun_sig= `Fit_or_vertical
; break_separators= `After
; break_sequences= true
; break_string_literals= `Auto
; break_struct= true
; cases_exp_indent= 4
; cases_matching_exp_indent= `Compact
; disambiguate_non_breaking_match= false
; doc_comments= `Before_except_val
; doc_comments_padding= 2
; doc_comments_tag_only= `Default
; dock_collection_brackets= true
; exp_grouping= `Parens
; extension_indent= 2
; field_space= `Tight
; function_indent= 2
; function_indent_nested= `Never
; if_then_else= `Vertical
; indent_after_in= 0
; indicate_multiline_delimiters= `Closing_on_separate_line
; indicate_nested_or_patterns= `Unsafe_no
; infix_precedence= `Indent
; leading_nested_match_parens= false
; let_and= `Sparse
; let_binding_indent= 2
; let_binding_spacing= `Compact
; let_module= `Sparse
; line_endings= `Lf
; margin= 80
; match_indent= 0
; match_indent_nested= `Never
; max_indent= None
; module_item_spacing= `Sparse
; nested_match= `Wrap
; ocp_indent_compat= false
; parens_ite= false
; parens_tuple= `Always
; parens_tuple_patterns= `Multi_line_only
; parse_docstrings= false
; parse_toplevel_phrases= false
; sequence_blank_line= `Compact
; sequence_style= `Separator
; single_case= `Sparse
; space_around_arrays= false
; space_around_lists= false
; space_around_records= false
; space_around_variants= false
; stritem_extension_indent= 0
; type_decl= `Sparse
; type_decl_indent= 2
; wrap_comments= false
; wrap_fun_args= false }

let janestreet_profile =
{ align_pattern_matching_bar= `Keyword
; assignment_operator= `Begin_line
Expand Down Expand Up @@ -1643,6 +1706,8 @@ let profile =
\"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:"diff-friendly" (Some diff_friendly_profile)
"The $(b,diff_friendly) profile aims to minimize the vertical diff."
; 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 \
Expand Down
5 changes: 3 additions & 2 deletions ocamlformat-help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,13 @@ 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|ocamlformat|janestreet},
--profile={conventional|default|ocamlformat|janestreet}
-p {conventional|default|diff-friendly|ocamlformat|janestreet},
--profile={conventional|default|diff-friendly|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
diff_friendly profile aims to minimize the vertical diff. 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
Expand Down
18 changes: 18 additions & 0 deletions test/passing/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4750,6 +4750,24 @@
(package ocamlformat)
(action (diff tests/skip.ml.err skip.ml.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
(action
(with-stdout-to source-diff-friendly.ml.stdout
(with-stderr-to source-diff-friendly.ml.stderr
(run %{bin:ocamlformat} --margin-check --profile=diff-friendly --max-iters=3 %{dep:tests/source.ml})))))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/source-diff-friendly.ml.ref source-diff-friendly.ml.stdout)))

(rule
(alias runtest)
(package ocamlformat)
(action (diff tests/source-diff-friendly.ml.err source-diff-friendly.ml.stderr)))

(rule
(deps tests/.ocamlformat )
(package ocamlformat)
Expand Down
3 changes: 3 additions & 0 deletions test/passing/tests/source-diff-friendly.ml.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Warning: tests/source.ml:5410 exceeds the margin
Warning: tests/source.ml:7198 exceeds the margin
Warning: tests/source.ml:8123 exceeds the margin
2 changes: 2 additions & 0 deletions test/passing/tests/source-diff-friendly.ml.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--profile=diff-friendly
--max-iters=3
Loading

0 comments on commit cadc1c1

Please sign in to comment.