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

Format on pre-save #34

Open
bostrom opened this issue Feb 15, 2017 · 3 comments
Open

Format on pre-save #34

bostrom opened this issue Feb 15, 2017 · 3 comments

Comments

@bostrom
Copy link

bostrom commented Feb 15, 2017

Would it be possible to configure the formatter to format the file before it's saved (but after pressing Cmd-s) instead of after? Now it seems that the file is saved to disk, then the formatter formats the file and saves it again, resulting in two saves.

This is problematic in cases where saved files are watched for changes, as the first (unformatted) save triggers actions (babel-compiles etc), and the second (formatted) save goes by unnoticed since the action is already in progress.

@elicwhite
Copy link
Owner

The eslint format command can't read from stdin, it can only format files on disk.

For this to be possible this plugin would need to write the file to some temp location, run eslint on that file with the configuration of the original file's directory, and then replace the buffer with the contents of the temp file before saving.

I would guess that the impact to perf would not be great and the logic would make this fairly complicated. I'd be willing to accept a PR though, especially if it had tests. :)

@cristianl
Copy link

cristianl commented Nov 18, 2017

The eslint format command can't read from stdin, it can only format files on disk.

This is now supported through the --fix-dry-run flag, shipped in eslint v4.9.0 eslint/eslint#9073

CLI example: echo "startServer();;" | eslint --stdin --fix-dry-run --format json --stdin-filename lib/server2.js

@skeggse
Copy link
Collaborator

skeggse commented May 19, 2020

I added support for a very similar feature of eslint_d in #77; it should be pretty easy to update this to also support eslint itself.

This was referenced May 19, 2020
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

4 participants