Skip to content

Improve: add margin check#1110

Merged
gpetiot merged 5 commits intoocaml-ppx:masterfrom
gpetiot:check-margin
Nov 6, 2019
Merged

Improve: add margin check#1110
gpetiot merged 5 commits intoocaml-ppx:masterfrom
gpetiot:check-margin

Conversation

@gpetiot
Copy link
Copy Markdown
Collaborator

@gpetiot gpetiot commented Oct 29, 2019

Fix #1107
before merging this we would need to redirect stderr to other files in the test, otherwise the warnings may appear during inplace formatting and generate incorrect files.
Edit: actually we don't need it until it is set by default for the tests (that can wait)

@gpetiot gpetiot marked this pull request as ready for review October 29, 2019 14:09
@gpetiot gpetiot requested a review from Julow October 29, 2019 14:10
@emillon
Copy link
Copy Markdown
Collaborator

emillon commented Oct 29, 2019

This is useful but I think it should wait 0.13.

Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
I have nothing against waiting for the release.

List.iteri (String.split_lines fmted) ~f:(fun i line ->
if String.length line > conf.margin then
Format.fprintf Format.err_formatter
"Warning: %s:%i exceeds the margin\n%!" filename i)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not print warnings the same way as Compat.print_warning. That would require using ocaml's internal warning system, though. Maybe we need our own formatting function for warning/error messages ?

@gpetiot
Copy link
Copy Markdown
Collaborator Author

gpetiot commented Nov 5, 2019

Should we "hide" this option like --check for example? (not in the Conf.t type and not listed in ocamlformat --help)

I think it's more of a developer option and it makes no sense of having it in profiles.

Copy link
Copy Markdown
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we "hide" this option like --check for example? (not in the Conf.t type and not listed in ocamlformat --help)

I think it's more of a developer option and it makes no sense of having it in profiles.

--check is not hidden. Yes, it would make sense to remove it from Conf.t as it's not needed in Fmt_ast.

@gpetiot gpetiot requested a review from Julow November 5, 2019 18:39
@gpetiot gpetiot merged commit a95f2e6 into ocaml-ppx:master Nov 6, 2019
@gpetiot gpetiot deleted the check-margin branch November 6, 2019 14:40
Julow added a commit to Julow/opam-repository that referenced this pull request Jan 28, 2020
CHANGES:

#### New features

  + Add an option `--margin-check` to emit a warning if the formatted output exceeds the margin (ocaml-ppx/ocamlformat#1110) (Guillaume Petiot)
  + Preserve comment indentation when `wrap-comments` is unset (ocaml-ppx/ocamlformat#1138, ocaml-ppx/ocamlformat#1159) (Jules Aguillon)
  + Improve error messages (ocaml-ppx/ocamlformat#1147) (Jules Aguillon)
  + Display standard output in the emacs plugin even when ocamlformat does not fail (ocaml-ppx/ocamlformat#1189) (Guillaume Petiot)

#### Removed

  + Remove `ocamlformat_reason` (ocaml-ppx/ocamlformat#254, ocaml-ppx/ocamlformat#1185) (Etienne Millon).
    This tool has never been released to opam, has no known users, and overlaps
    with what `refmt` can do.
  + Remove `ocamlformat-diff` (ocaml-ppx/ocamlformat#1205) (Guillaume Petiot)
    This tool has never been released to opam, has no known users, and overlaps
    with what `merge-fmt` can do.

#### Packaging

  + Work with base v0.13.0 (ocaml-ppx/ocamlformat#1163) (Jules Aguillon)

#### Bug fixes

  + Fix placement of comments just before a '|' (ocaml-ppx/ocamlformat#1203) (Jules Aguillon)
  + Fix build version detection when building in the absence of a git root (ocaml-ppx/ocamlformat#1198) (Anil Madhavapeddy)
  + Fix wrapping of or-patterns in presence of comments with `break-cases=fit` (ocaml-ppx/ocamlformat#1167) (Jules Aguillon)
    This also fixes an unstable comment bug in or-patterns
  + Fix an unstable comment bug in variant declarations (ocaml-ppx/ocamlformat#1108) (Jules Aguillon)
  + Fix: break multiline comments (ocaml-ppx/ocamlformat#1122) (Guillaume Petiot)
  + Fix: types on named arguments were wrapped incorrectly when preceding comments (ocaml-ppx/ocamlformat#1124) (Guillaume Petiot)
  + Fix the indentation produced by max-indent (ocaml-ppx/ocamlformat#1118) (Guillaume Petiot)
  + Fix break after Psig_include depending on presence of docstring (ocaml-ppx/ocamlformat#1125) (Guillaume Petiot)
  + Remove some calls to if_newline and break_unless_newline and fix break before closing brackets (ocaml-ppx/ocamlformat#1168) (Guillaume Petiot)
  + Fix unstable cmt in or-pattern (ocaml-ppx/ocamlformat#1173) (Guillaume Petiot)
  + Fix location of comment attached to the underscore of an open record (ocaml-ppx/ocamlformat#1208) (Guillaume Petiot)
  + Fix parentheses around optional module parameter (ocaml-ppx/ocamlformat#1212) (Christian Barcenas)
  + Fix grouping of horizontally aligned comments (ocaml-ppx/ocamlformat#1209) (Guillaume Petiot)
  + Fix dropped comments around module pack expressions (ocaml-ppx/ocamlformat#1214) (Jules Aguillon)
  + Fix regression of comment position in list patterns (ocaml-ppx/ocamlformat#1141) (Josh Berdine)
  + Fix: adjust definition of Location.is_single_line to reflect margin (ocaml-ppx/ocamlformat#1102) (Josh Berdine)

#### Documentation

  + Fix documentation of option `version-check` (ocaml-ppx/ocamlformat#1135) (Wilfred Hughes)
  + Fix hint when using `break-separators=after-and-docked` (ocaml-ppx/ocamlformat#1130) (Greta Yorsh)
bogdan2412 pushed a commit to bogdan2412/ocamlformat that referenced this pull request Mar 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: automatic margin check

4 participants