Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ profile. This started with version 0.26.0.
instead of only some.
(#2737, @v-gb)

- \* Removed unecessary line breaks in several places (#2778, @Julow)
Many line breaks were caused by a bug in the implementation of `Format`
rather than a deliberate choice.

### Internal

- Added information on writing tests to `CONTRIBUTING.md` (#2838, @WardBrian)
Expand Down
20 changes: 10 additions & 10 deletions bin/ocamlformat-rpc/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ let info =
; `P
"Before the client and the server agree on a common version to use \
the following commands are available: $(b,Halt) to close the \
connection to the RPC; $(b,Version) $(i,v) to ask the server to \
use version $(i,v). If the server agrees upon the version he will \
send the reply $(b,Version) $(i,v) and the protocol version is set \
to $(i,v), to use another version later the client has to close \
the connexion and start a new one. If the server cannot use \
version $(i,v) he might propose another version $(i,w) by sending \
the reply $(b,Version) $(i,w) that the client can accept by \
sending the same request for version $(i,w), or propose another \
version. If the server cannot propose another version it will \
close the connection. Unknown commands are ignored."
connection to the RPC; $(b,Version) $(i,v) to ask the server to use \
version $(i,v). If the server agrees upon the version he will send \
the reply $(b,Version) $(i,v) and the protocol version is set to \
$(i,v), to use another version later the client has to close the \
connexion and start a new one. If the server cannot use version \
$(i,v) he might propose another version $(i,w) by sending the reply \
$(b,Version) $(i,w) that the client can accept by sending the same \
request for version $(i,w), or propose another version. If the \
server cannot propose another version it will close the connection. \
Unknown commands are ignored."
; `P
"Once the client and the server agree on a common version, the \
requests you can send may differ from one version to another."
Expand Down
28 changes: 14 additions & 14 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ type cls = Let_match | Match | Non_apply | Sequence | Then | ThenElse
module Token = struct
let is_infix = function
| Parser.AMPERAMPER | AMPERSAND | ANDOP _ | BAR | BARBAR | COLON
|COLONCOLON | COLONEQUAL | DOTDOT | DOTOP _ | EQUAL | GREATER
|HASHOP _ | INFIXOP0 _ | INFIXOP1 _ | INFIXOP2 _ | INFIXOP3 _
|INFIXOP4 _ | LESS | LESSMINUS | LETOP _ | MINUS | MINUSDOT
|MINUSGREATER | PERCENT | PLUS | PLUSDOT | PLUSEQ | SLASH | STAR ->
|COLONCOLON | COLONEQUAL | DOTDOT | DOTOP _ | EQUAL | GREATER | HASHOP _
|INFIXOP0 _ | INFIXOP1 _ | INFIXOP2 _ | INFIXOP3 _ | INFIXOP4 _ | LESS
|LESSMINUS | LETOP _ | MINUS | MINUSDOT | MINUSGREATER | PERCENT | PLUS
|PLUSDOT | PLUSEQ | SLASH | STAR ->
true
| _ -> false
end
Expand Down Expand Up @@ -1307,8 +1307,8 @@ end = struct
|Pexp_send _ | Pexp_sequence _ | Pexp_setfield _ | Pexp_setinstvar _
|Pexp_tuple _ | Pexp_unreachable | Pexp_variant _ | Pexp_while _
|Pexp_hole | Pexp_beginend _ | Pexp_parens _ | Pexp_cons _
|Pexp_letopen _ | Pexp_indexop_access _ | Pexp_prefix _
|Pexp_infix _ | Pexp_construct_unit_beginend _ ->
|Pexp_letopen _ | Pexp_indexop_access _ | Pexp_prefix _ | Pexp_infix _
|Pexp_construct_unit_beginend _ ->
assert false
| Pexp_extension (_, ext) -> assert (check_extensions ext)
| Pexp_object ({pcstr_self; _}, _) ->
Expand Down Expand Up @@ -1650,8 +1650,8 @@ end = struct
| Ptyp_alias _ -> Some (As, Non)
| Ptyp_constr (_, _ :: _ :: _) -> Some (Comma, Non)
| Ptyp_constr _ -> Some (Apply, Non)
| Ptyp_any | Ptyp_var _ | Ptyp_object _ | Ptyp_class _
|Ptyp_variant _ | Ptyp_package _ | Ptyp_extension _ | Ptyp_open _ ->
| Ptyp_any | Ptyp_var _ | Ptyp_object _ | Ptyp_class _ | Ptyp_variant _
|Ptyp_package _ | Ptyp_extension _ | Ptyp_open _ ->
None )
| {ctx= Cty {pcty_desc; _}; ast= Typ typ; _} -> (
match pcty_desc with
Expand Down Expand Up @@ -1743,8 +1743,8 @@ end = struct
match pcl_desc with Pcl_apply _ -> Some (Apply, Non) | _ -> None )
| { ctx= Exp _
; ast=
( Pld _ | Top | Tli _ | Pat _ | Cl _ | Mty _ | Mod _ | Sig _
| Str _ | Clf _ | Ctf _ | Rep | Mb _ | Md _ ) }
( Pld _ | Top | Tli _ | Pat _ | Cl _ | Mty _ | Mod _ | Sig _ | Str _
| Clf _ | Ctf _ | Rep | Mb _ | Md _ ) }
|{ctx= Fpe _ | Fpc _; ast= _}
|{ctx= _; ast= Fpe _ | Fpc _}
|{ctx= Vc _; ast= _}
Expand All @@ -1767,8 +1767,8 @@ end = struct
( Pld _ | Top | Tli _ | Typ _ | Cty _ | Pat _ | Mty _ | Mod _
| Sig _ | Str _ | Clf _ | Ctf _ | Rep | Mb _ | Md _ )
; ast=
( Pld _ | Top | Tli _ | Pat _ | Exp _ | Cl _ | Mty _ | Mod _
| Sig _ | Str _ | Clf _ | Ctf _ | Rep | Mb _ | Md _ ) } ->
( Pld _ | Top | Tli _ | Pat _ | Exp _ | Cl _ | Mty _ | Mod _ | Sig _
| Str _ | Clf _ | Ctf _ | Rep | Mb _ | Md _ ) } ->
None

(** [prec_ast ast] is the precedence of [ast]. Meaningful for binary
Expand All @@ -1783,8 +1783,8 @@ end = struct
| Ptyp_arrow _ | Ptyp_poly _ -> Some MinusGreater
| Ptyp_tuple _ -> Some InfixOp3
| Ptyp_alias _ -> Some As
| Ptyp_any | Ptyp_var _ | Ptyp_constr _ | Ptyp_object _
|Ptyp_class _ | Ptyp_variant _ | Ptyp_extension _ | Ptyp_open _ ->
| Ptyp_any | Ptyp_var _ | Ptyp_constr _ | Ptyp_object _ | Ptyp_class _
|Ptyp_variant _ | Ptyp_extension _ | Ptyp_open _ ->
None )
| Td _ -> None
| Cty {pcty_desc; _} -> (
Expand Down
97 changes: 48 additions & 49 deletions lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ let profile =
existing code. General guidelines that have directed the design \
include: Legibility, in the sense of making it as hard as possible \
for quick visual parsing to give the wrong interpretation, is of \
highest priority; Whenever possible the high-level structure of \
the code should be obvious by looking only at the left margin, in \
highest priority; Whenever possible the high-level structure of the \
code should be obvious by looking only at the left margin, in \
particular, it should not be necessary to visually jump from left \
to right hunting for critical keywords, tokens, etc; All else \
equal compact code is preferred as reading without scrolling is \
easier, so indentation or white space is avoided unless it helps \
to right hunting for critical keywords, tokens, etc; All else equal \
compact code is preferred as reading without scrolling is easier, \
so indentation or white space is avoided unless it helps \
legibility; Attention has been given to making some syntactic \
gotchas visually obvious."
; Decl.Value.make ~name:"janestreet" `janestreet
Expand Down Expand Up @@ -376,8 +376,8 @@ module Formatting = struct
the end of the line and breaks after it if the whole assignment \
expression does not fit on a single line."
; Decl.Value.make ~name:"begin-line" `Begin_line
"$(b,begin-line) positions assignment operators (`:=` and `<-`) \
at the beginning of the line and breaks before it if the whole \
"$(b,begin-line) positions assignment operators (`:=` and `<-`) at \
the beginning of the line and breaks before it if the whole \
assignment expression does not fit on a single line." ]
in
Decl.choice ~names ~all ~default ~doc ~kind
Expand Down Expand Up @@ -440,11 +440,11 @@ module Formatting = struct
let names = ["break-collection-expressions"] in
let all =
[ Decl.Value.make ~name:"fit-or-vertical" `Fit_or_vertical
"$(b,fit-or-vertical) vertically breaks expressions if they do \
not fit on a single line."
"$(b,fit-or-vertical) vertically breaks expressions if they do not \
fit on a single line."
; Decl.Value.make ~name:"wrap" `Wrap
"$(b,wrap) will group simple expressions and try to format them \
in a single line." ]
"$(b,wrap) will group simple expressions and try to format them in \
a single line." ]
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt ->
Expand Down Expand Up @@ -506,11 +506,11 @@ module Formatting = struct
let names = ["break-infix"] in
let all =
[ Decl.Value.make ~name:"wrap" `Wrap
"$(b,wrap) will group simple expressions and try to format them \
in a single line."
"$(b,wrap) will group simple expressions and try to format them in \
a single line."
; Decl.Value.make ~name:"fit-or-vertical" `Fit_or_vertical
"$(b,fit-or-vertical) vertically breaks expressions if they do \
not fit on a single line."
"$(b,fit-or-vertical) vertically breaks expressions if they do not \
fit on a single line."
; Decl.Value.make ~name:"wrap-or-vertical" `Wrap_or_vertical
"$(b,wrap-or-vertical) behaves like $(b,wrap) for high precedence \
operators and behaves like $(b,fit-or-vertical) for low \
Expand Down Expand Up @@ -570,8 +570,8 @@ module Formatting = struct
let names = ["break-string-literals"] in
let all =
[ Decl.Value.make ~name:"auto" `Auto
"$(b,auto) mode breaks lines at newlines and wraps string \
literals at the margin."
"$(b,auto) mode breaks lines at newlines and wraps string literals \
at the margin."
; Decl.Value.make ~name:"never" `Never
"$(b,never) mode formats string literals as they are parsed, in \
particular, with escape sequences expanded." ]
Expand Down Expand Up @@ -629,9 +629,8 @@ module Formatting = struct
[ Decl.Value.make ~name:"normal" `Normal
"$(b,normal) indents as it would any other expression."
; Decl.Value.make ~name:"compact" `Compact
"$(b,compact) forces an indentation of 2, unless \
$(b,nested-match) is set to $(b,align) and we're on the last \
case." ]
"$(b,compact) forces an indentation of 2, unless $(b,nested-match) \
is set to $(b,align) and we're on the last case." ]
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt ->
Expand Down Expand Up @@ -660,9 +659,9 @@ module Formatting = struct
declarations because that would change their meaning and on \
structures, signatures and objects for readability."
; Decl.Value.make ~name:"before-except-val" `Before_except_val
"$(b,before-except-val) puts doc comments before the \
corresponding code, but puts doc comments of $(b,val) and \
$(b,external) declarations after the corresponding declarations."
"$(b,before-except-val) puts doc comments before the corresponding \
code, but puts doc comments of $(b,val) and $(b,external) \
declarations after the corresponding declarations."
; Decl.Value.make ~name:"before" `Before
"$(b,before) puts comments before the corresponding code." ]
in
Expand Down Expand Up @@ -705,8 +704,8 @@ module Formatting = struct
let names = ["doc-comments-val"] in
let msg =
"If you are using `doc-comments-val=before` in combination with \
`doc-comments=before` then only `doc-comments=before` is now \
required to achive the same behavior. If you are using \
`doc-comments=before` then only `doc-comments=before` is now required \
to achive the same behavior. If you are using \
`doc-comments-val=before` in combination with `doc-comments=after` \
this behavior is not available anymore. If you are using \
`doc-comments-val=after` in combination with `doc-comments=before` \
Expand Down Expand Up @@ -749,8 +748,8 @@ module Formatting = struct
let names = ["exp-grouping"] in
let all =
[ Decl.Value.make ~name:"preserve" `Preserve
"$(b,preserve) preserves the original grouping syntax \
(parentheses or $(i,begin)/$(i,end))."
"$(b,preserve) preserves the original grouping syntax (parentheses \
or $(i,begin)/$(i,end))."
; Decl.Value.make ~name:"parens" `Parens
"$(b,parens) groups expressions using parentheses." ]
in
Expand Down Expand Up @@ -786,8 +785,8 @@ module Formatting = struct
; Decl.Value.make ~name:"tight" `Tight
"$(b,tight) does not use a space."
; Decl.Value.make ~name:"tight-decl" `Tight_decl
"$(b,tight-decl) is $(b,tight) for declarations and $(b,loose) \
for instantiations." ]
"$(b,tight-decl) is $(b,tight) for declarations and $(b,loose) for \
instantiations." ]
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt -> update conf ~f:(fun f -> {f with field_space= elt}))
Expand Down Expand Up @@ -835,8 +834,8 @@ module Formatting = struct
; Decl.Value.make ~name:"vertical" `Vertical
"$(b,vertical) always vertically breaks branches."
; Decl.Value.make ~name:"keyword-first" `Keyword_first
"$(b,keyword-first) formats if-then-else expressions such that \
the if-then-else keywords are the first on the line."
"$(b,keyword-first) formats if-then-else expressions such that the \
if-then-else keywords are the first on the line."
; Decl.Value.make ~name:"k-r" `K_R
"$(b,k-r) formats if-then-else expressions with parentheses that \
match the K&R style." ]
Expand Down Expand Up @@ -933,8 +932,8 @@ module Formatting = struct
let names = ["let-and"] in
let all =
[ Decl.Value.make ~name:"compact" `Compact
"$(b,compact) will try to format `let p = e and p = e` in a \
single line."
"$(b,compact) will try to format `let p = e and p = e` in a single \
line."
; Decl.Value.make ~name:"sparse" `Sparse
"$(b,sparse) will always break between them." ]
in
Expand Down Expand Up @@ -1005,17 +1004,17 @@ module Formatting = struct
let names = ["letop-punning"] in
let all =
[ Decl.Value.make ~name:"preserve" `Preserve
"$(b,preserve) uses let-punning only when it exists in the \
source; the code \"$(i,let* foo and* z = z in ...)\" will be \
left unchanged."
"$(b,preserve) uses let-punning only when it exists in the source; \
the code \"$(i,let* foo and* z = z in ...)\" will be left \
unchanged."
; Decl.Value.make ~name:"always" `Always
"$(b,always) uses let-punning whenever possible; the code \
\"$(i,let* foo and* z = z in ...)\" will be rewritten to \
\"$(i,let* foo and* z in ...)\"."
; Decl.Value.make ~name:"never" `Never
"$(b,never) never uses let-punning; the code \"$(i,let* foo and* \
z = z in ...)\" will be rewritten to \"$(i,let* foo = foo and* z \
= z in ...)\". " ]
"$(b,never) never uses let-punning; the code \"$(i,let* foo and* z \
= z in ...)\" will be rewritten to \"$(i,let* foo = foo and* z = \
z in ...)\". " ]
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt -> update conf ~f:(fun f -> {f with letop_punning= elt}))
Expand Down Expand Up @@ -1168,8 +1167,8 @@ module Formatting = struct
[ Decl.Value.make ~name:"always" `Always
"$(b,always) always uses parentheses around tuples."
; Decl.Value.make ~name:"multi-line-only" `Multi_line_only
"$(b,multi-line-only) mode will try to skip parens for \
single-line tuples." ]
"$(b,multi-line-only) mode will try to skip parens for single-line \
tuples." ]
in
Decl.choice ~names ~all ~default ~doc ~kind
(fun conf elt -> update conf ~f:(fun f -> {f with parens_tuple= elt}))
Expand All @@ -1180,8 +1179,8 @@ module Formatting = struct
let names = ["parens-tuple-patterns"] in
let all =
[ Decl.Value.make ~name:"multi-line-only" `Multi_line_only
"$(b,multi-line-only) mode will try to skip parens for \
single-line tuple patterns."
"$(b,multi-line-only) mode will try to skip parens for single-line \
tuple patterns."
; Decl.Value.make ~name:"always" `Always
"$(b,always) always uses parentheses around tuples patterns." ]
in
Expand Down Expand Up @@ -1211,8 +1210,8 @@ module Formatting = struct
let names = ["sequence-blank-line"] in
let all =
[ Decl.Value.make ~name:"preserve-one" `Preserve_one
"$(b,preserve) will keep a blank line between two expressions of \
a sequence if the input contains at least one."
"$(b,preserve) will keep a blank line between two expressions of a \
sequence if the input contains at least one."
; Decl.Value.make ~name:"compact" `Compact
"$(b,compact) will not keep any blank line between expressions of \
a sequence." ]
Expand Down Expand Up @@ -1314,8 +1313,8 @@ module Formatting = struct
let type_decl_indent =
let docv = "COLS" in
let doc =
"Indentation of type declarations ($(docv) columns) if they do not \
fit on a single line."
"Indentation of type declarations ($(docv) columns) if they do not fit \
on a single line."
in
let names = ["type-decl-indent"] in
Decl.int ~names ~default ~doc ~docv ~kind ~allow_inline:false
Expand All @@ -1328,8 +1327,8 @@ module Formatting = struct
"Comments are divided into paragraphs by open lines (two or more \
consecutive newlines), and each paragraph is wrapped at the margin. \
Multi-line comments with vertically-aligned asterisks on the left \
margin are not wrapped. Consecutive comments with both left and \
right margin aligned are not wrapped either."
margin are not wrapped. Consecutive comments with both left and right \
margin aligned are not wrapped either."
in
Decl.flag ~default ~names:["wrap-comments"] ~doc ~kind
(fun conf elt -> update conf ~f:(fun f -> {f with wrap_comments= elt}))
Expand Down
4 changes: 2 additions & 2 deletions lib/Conf_t.ml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ module Error = struct
| Bad_value (name, msg) -> Format.sprintf "For option %S: %s" name msg
| Version_mismatch {read; installed} ->
Format.sprintf
"Project should be formatted using ocamlformat version %S, but \
the installed version is %S"
"Project should be formatted using ocamlformat version %S, but the \
installed version is %S"
read installed
end

Expand Down
Loading
Loading