Elm-format: Proposal: Add a --verify flag

Created on 9 May 2016  路  4Comments  路  Source: avh4/elm-format

Motivation

I have open-source projects on which I use elm-format. Sometimes I merge PRs from people who don't use elm-format, only to discover later that I've ended up with elm-format diffs. These are annoying, especially if I've already started coding and don't realize I have diffs to clean up (ideally in a separate commit), at which point I have to double back and fix them before proceeding with what I actually want to be doing.

It would be better to be able to handle these proactively, by adding something like an elm-format --verify step to my Travis config which would fail the build if elm-format would produce any diffs with the current file structure.

Proposed Change

Add a --verify flag to the CLI. When set, instead of generating any actual files, elm-format instead compares what it intends to generate with what's currently on the file system.

The CLI output is either:

  • A success message and exit code 0 if there are no diffs
  • A list of files that have diffs and a nonzero exit code. (Textual diffs do not seem useful, as no matter what, the prescription is to run elm-format on those files and end up with zero diffs.)

Most helpful comment

@rtfeldman Here is what's implemented:

Docs:

--validate               Check if files are formatted without changing them.

Output of elm-format file.elm --validate when file is formatted (exit code 0):

Processing file file.elm

Output of elm-format file.elm --validate when file is not formatted (exit code 1):

Processing file file.elm
File would be changed file.elm

I think the output format can/should be cleaned up a bit, but that should probably be a separate issue.

All 4 comments

@rtfeldman Here is what's implemented:

Docs:

--validate               Check if files are formatted without changing them.

Output of elm-format file.elm --validate when file is formatted (exit code 0):

Processing file file.elm

Output of elm-format file.elm --validate when file is not formatted (exit code 1):

Processing file file.elm
File would be changed file.elm

I think the output format can/should be cleaned up a bit, but that should probably be a separate issue.

Awesome!!! 馃帀 馃帀 馃帀

Can't wait to integrate this into my builds! 馃樃

Is worth flagging up that if anyone is running elm-format with the --validate flag in travis CI then it is well worth using the solution mentioned in https://github.com/elm/compiler/issues/1473#issuecomment-245704142 to speed up the linting which will otherwise take an exceptionally long time.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

conradwt picture conradwt  路  8Comments

ahstro picture ahstro  路  4Comments

ahstro picture ahstro  路  3Comments

yonigibbs picture yonigibbs  路  7Comments

rtfeldman picture rtfeldman  路  4Comments