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

Using --stdin (without --stdout) sometimes does not cause formatted output to go to stdout #3632

Closed
1 task done
emdash-ie opened this issue Sep 6, 2023 · 2 comments · Fixed by #3633
Closed
1 task done

Comments

@emdash-ie
Copy link

emdash-ie commented Sep 6, 2023

  • latest version of CLI and latest version in .scalafmt.conf

Configuration (required)

Please paste the contents of your .scalafmt.conf file here:

version = 3.7.14
runner.dialect=scala213

maxColumn = 120
trailingCommas = always
align.preset = none
fileOverride {
  "glob:**/support-internationalisation/src/test/scala/**" {
     runner.dialect = scala3
  }
  "glob:**/support-internationalisation/src/main/scala/**" {
     runner.dialect = scala3
  }
}

Steps

Given Something.scala:

class Something() {
  def something() = {}
}

Running scalafmt --debug Something.scala produces this output and the file does not change (as expected):

Using core runner [3.7.14]
Working directory: /Users/emily_bourke/code/support-frontend/support-frontend/app/utils
parsed config (v3.7.14)
Files to be formatted:
/Users/emily_bourke/code/support-frontend/support-frontend/app/utils/Something.scala

Running scalafmt --debug --stdout Something.scala produces this output and the file does not change (as expected):

Using core runner [3.7.14]
Working directory: /Users/emily_bourke/code/support-frontend/support-frontend/app/utils
parsed config (v3.7.14)
Files to be formatted:
/Users/emily_bourke/code/support-frontend/support-frontend/app/utils/Something.scala
class Something() {
  def something() = {}
}

Running cat Something.scala | scalafmt --debug --stdin --stdout produces this output and the file does not change (as expected):

Using core runner [3.7.14]
Working directory: /Users/emily_bourke/code/support-frontend/support-frontend/app/utils
parsed config (v3.7.14)
class Something() {
  def something() = {}
}

Based on the help documentation (which says scalafmt --stdin # read from stdin and print to stdout) I would expect removing --stdout to make no difference, but running cat Something.scala | scalafmt --debug --stdin produces the following output and the file does not change.

Using core runner [3.7.14]
Working directory: /Users/emily_bourke/code/support-frontend/support-frontend/app/utils
parsed config (v3.7.14)

Why is the file not output onto stdout in this case? (This happens when the file is correctly formatted, and mostly doesn’t happen (or never happens – not sure) if the file needs formatting.)

Workaround

I can add the --stdout flag (and raise a PR to do that in format-all-mode).

Notes

  • I’m using fish as my shell
  • I came across this problem while using format-all-mode in Doom Emacs
  • Explanation and documentation of this behaviour would be acceptable to me instead of changing it
@emdash-ie emdash-ie changed the title Using --stdin sometimes does not cause formatted output to go to stdout Using --stdin (without --stdout) sometimes does not cause formatted output to go to stdout Sep 6, 2023
@kitbellew
Copy link
Collaborator

--stdin does not imply --stdout. the help needs to be adjusted.

@emdash-ie
Copy link
Author

--stdin does not imply --stdout. the help needs to be adjusted.

Perfect, thanks for clarifying :)

lassik pushed a commit to lassik/emacs-format-all-the-code that referenced this issue Sep 10, 2023
Sometimes, scalafmt does not produce formatted output to stdout with
only the `--stdin` flag provided. For example, this happens when there
are no formatting changes required to be made to the file. As-is, this
causes the formatter to clear the buffer when there are no formatting
changes required.

Fix by adding the `--stdout` flag.

See scalameta/scalafmt#3632 for more
information.
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 a pull request may close this issue.

2 participants