-
Notifications
You must be signed in to change notification settings - Fork 88
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
Fix the code using --fix #104
Comments
SublimeLinter does not support anything except linting and there is no easy way to add this formatting command separately to this plugin. I guess we should wait when such possiblity will land in SublimeLinter, probably create an issue, or create separate plugin, like https://github.com/TheSavior/SublimeJSCSFormatter/blob/master/JSCS-Formatter.py for jscs. |
I'll open an issue in linter, to let them know about the need for the feature. Probably a separate plugin would be the most reliable way of implementing it, but it'd be a pity to not use all the config management which is already implemented in linter and in this plugin. |
For reference: what the
and
i.e. running it like this:
Also, Atom's `linter-eslint` plugin since [version 5.2.0](https://github.com/AtomLinter/linter-eslint/releases) offers "`linter-eslint: Fix file`" command _(via Command Palette)_. It works on the currently opened file, provided that you have just saved it (i.e. it has no unsaved changes). |
I am going to create a small sublime text plugin (first one by the way). So watch this space! =) |
I'll be watching you @softwarespot :D |
How is the plugin going? :) TBH I am surprised at this as the Sublime Linter documentation, at least in plain english, implies that it passes the argument to the binary:
Yet I haven't been able to get --fix or --globals to work. What is the point of the args in SublimeLinter if not to allow arguments to passed to the run time? The example provided in the SublimeLinter documentation even implies cmd syntax:
The following does not lint on my Sublime 3.0, removing the "--fix" and it does.
And yet the following works fine
Does not compute! |
Would also love to see |
Somebody who knows pyton (not me :( ) could fork https://github.com/TheSavior/SublimeJSCSFormatter/ and probably make an eslint version. The api of jscs and eslint are pretty much the same. @softwarespot |
@mummybot Plugin uses stdin as input ( |
+1 |
2 similar comments
+1 |
+1 |
If it is possible in SumblimeLinter to tell the difference between an as-you-type lint and a has-hit-save lint, a good approach might be to use the real file instead of |
This was released 6 days ago >> https://github.com/TheSavior/ESLint-Formatter. It's JSCS Formatter renamed |
I just created a new build system and made shortcut:
I don't know if that's the best solution, but works for me. |
@RichardForrester Can you give instructions on how to install this? Where should I put that line? |
@RichardForrester A slightly better option might be: |
@Overload119 There isn't anything to install. Just go through the menu: Tools > Build System > New Build System @joeybaker is correct, a slightly better path is as he suggests.
So basically you just save that as a build and then you can |
+1 to supports: {
"linters": {
"eslint": {
"args": [
"--fix"
]
}
}
} |
For anybody that isn't using projects like me and just opens Sublime with a directory using { "shell_cmd": "$folder/node_modules/.bin/eslint --fix $file" } 💥 |
For me being on windows and having local eslint installed via npm you can also use { "shell_cmd": "%appdata%/npm/eslint --fix $file" } |
guys this plugin is available, its for formatting using eslint Use that instead of asking for this feature. |
i find a way solve this problem, and i create a pull request, it works fine on load/save lint mode. |
@RichardForrester I created a new build system, Sublime asked me to save it, I did -- but running "Build" still says "No Build System". @kzap: ESLint-Formatter is too smart for its own good. Instead of assuming that eslint is in the path, like most eslint-related plugins do, it wants to know where node is, eslint, etc. My node path changes since I use nvm. |
As far as I can see, the problem is here: From ESLint's documentation
So
I was able to come up with the following proof of concept by modifying - cmd = ('eslint', '--format', 'compact', '--stdin', '--stdin-filename', '@')
+ cmd = ('eslint', '--format', 'compact', '@')
+ tempfile_suffix = '-' I am a JavaScript developer. I don't know alot of Python and I have no idea what the Now, whenever I save a file (see Lint Modes), it is linted and fixed thanks to the following {
"linters": {
"eslint": {
"@disable": false,
"args": [
"--fix"
],
"excludes": []
}
}
}
If I remove It would be great if this change could be made after someone is able to evaluate the impact it would have of stability and performance. Unfortunately that is currently outside of what I am capable of. Hopefully this will give someone a head start in creating a pull request for Related: SublimeLinter/SublimeLinter#375 |
My workaround does have a problem. It hits the filesystem twice. First when you initially save the file, and again when This is less than ideal, including that it would require debouncing of any file watcher, including editor plugins, build systems, or other pieces of software that may be outside a developer's control. |
In the end, my attempt to work around the problem was limited by my knowledge of Python and limitations in both Prettier and ESLint. It ended up being more reasonable for me to change my workflow than attempting to get a single package to do it all. Long story short, I was able to get The following may be worth keeping an eye on: |
Hello @npetruzzelli I have the same setting now, but it seems the linter is executed before the formatter with the format_on_save option, so the file is formatted correctly, but the linter still reports the issues. |
I'm afraid I haven't run into any issues like that. Keep in mind that the ESLint-Formatter can only work on a saved file. It won't work if you have an open document with unsaved changes. I typically lint as a background process or on file save. Then I will use the keyboard shortcut when I want to format. I think it is Not all problems can be autofixed, so sometimes you will have to manually resolve ESLint errors. Unfortunately, I don't know of any way to control the order in which Formatter and Linter execute or to get one to wait for the other. |
We've decided (at least for the foreseeable future) that such functionality is out of scope for SL. More info: SublimeLinter/SublimeLinter#375 |
Proof of Concept PR is #254 |
{ "shell_cmd": "npx eslint --fix $file" } @sheepsteak's idea nice, but feel slowly.
Can improve speed with eslint_d. yarn global add eslint_d { "shell_cmd": "eslint_d --fix $file --no-ignore" } // use current .eslintrc
|
eslint provides a really nice
--fix
option, which is perfectly usable for fixing smaller things, like indentation, styling issues, etc.Please make a command which runs
--fix
on the actual code, so a quick eslint style fixing would be possible in Sublime.The text was updated successfully, but these errors were encountered: