Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --list option that outputs names of files changed #1459

Closed
ArturGajowy opened this issue Jul 20, 2019 · 7 comments
Closed

Add --list option that outputs names of files changed #1459

ArturGajowy opened this issue Jul 20, 2019 · 7 comments

Comments

@ArturGajowy
Copy link

Currently, running:

scalafmt Foo.scala

on a non-formatted file outputs:

Reformatting...

I'd expect it to list all the files that were changed during reformatting, or provide an option to do so.

Similarly, running:

scalafmt --test Foo.scala

will output the diffs of files needing formatting - but ideally there'd be an option to just list the names.

@tanishiking
Copy link
Member

tanishiking commented Jul 20, 2019

It would be nice for scalafmt to list all the formating files (if scalafmt receives the list of files to format) without any options 👍

@ArturGajowy
Copy link
Author

ArturGajowy commented Jul 20, 2019

Not sure if I understand: so if run
scalafmt Foo.scala Bar.scala
and only Foo.scala changes due to formatting, what would be the output?

If I just run:
scalafmt
and that changes just Foo.scala - what would be the the output?

I'm not sure if you mean the outputs to be:

  1. Foo.scala in both cases
  2. Foo.scala and Bar.scala in the first case, nothing in the second case

?

@tanishiking
Copy link
Member

  • scalafmt Foo.scala Bar.scala
    • it should print Foo.scala and Bar.scala because those two files are the target (even if Bar.scala doesn't have any change by scalafmt)
  • scalafmt
    • it shouldn't show any filenames in any cases.

@ArturGajowy
Copy link
Author

That would be useful debugging info, but would not help my use case - I'd like to see the files that changed (when running without --test) or need changing (when running with --test). So I'm after option 1. above.

Maybe there should be two flags: --list and --list-not-formatted?

@mroth
Copy link

mroth commented Jul 22, 2019

Also strong want this, and suspect my use case is the same as @ArturGajowy -- I want a list of all files that "would be re-formatted". In my case, it's because we want to run this in CI, and warn if a file was not scalafmt'd. The standard "diff" format is useful for writing changes to a file, but not as an error message.

For comparison, similar options with other formatters:

In the case of Prettier, you then get output such as:

Checking formatting...
src/fileA.js
src/fileB.js
Code style issues found in the above file(s). Forgot to run Prettier?

This is a much nicer error message to give someone in a failed CI check than dumping many screens of diffs.

@tanishiking
Copy link
Member

I want a list of all files that "would be re-formatted".

Ah, finally I got it.
It would be nice to have an option --list or something whose behavior is equivalent to gofmt -l (list files whose formatting differs from scalafmt's)

@tanishiking
Copy link
Member

Closed by #1466 👍

mroth added a commit to openlawteam/scalafmt-ci that referenced this issue Aug 12, 2019
As requested in scalameta/scalafmt#1459, and
introduced in scalameta/scalafmt#1466, which was
release in v2.0.1 which we pinned to in previous commit.  Yay!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants