Skip to content

Fix the code using --fix #104

Closed
Closed
@hyperknot

Description

@hyperknot

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.

Activity

roadhump

roadhump commented on Nov 22, 2015

@roadhump
Collaborator

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.

hyperknot

hyperknot commented on Nov 24, 2015

@hyperknot
Author

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.

darkred

darkred commented on Dec 5, 2015

@darkred

For reference: what the --fix option currently (v1.10.3) offers (1, 2) is that:

When you run ESLint on the command line with the --fix flag, it will automatically fix any problems that it can (not all problems are fixable at once) and will not report the problems that were fixed.

and

This option instructs ESLint to try to fix as many issues as possible. The fixes are made to the actual files themselves and only the remaining unfixed issues are output.

i.e. running it like this:
eslint --fix myscript.js
it will replace the file with one having as many issues as possible fixed (i.e. it wont create a 2nd file),
and it doesn't report in its output which errors it just fixed
but only which unfixed issues remain, like this:

$ eslint --fix myscript.js

C:\Users\Kostas\Desktop\New folder\myscript.user.js
   26:18  error    Multiline support is limited to browsers supporting ES5 only                                   no-multi-str
   48:1   error    "GM_addStyle" is not defined                                                                   no-undef
   48:1   error    A function with a name starting with an uppercase letter should only be used as a constructor  new-cap
   73:1   warning  "time" was used before it was defined                                                          no-use-before-define
   75:1   error    String prototype is read only, properties should not be added                                  no-extend-native
   96:5   error    Identifier 'base_url' is not in camel case                                                     camelcase

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).
softwarespot

softwarespot commented on Jan 5, 2016

@softwarespot

I am going to create a small sublime text plugin (first one by the way). So watch this space! =)

joerideg

joerideg commented on Jan 12, 2016

@joerideg

I'll be watching you @softwarespot :D

mummybot

mummybot commented on Jan 22, 2016

@mummybot

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:

This setting specifies extra arguments to pass to an external binary. This is useful when a linter binary supports an option that is not part of the linter’s settings.
http://www.sublimelinter.com/en/latest/linter_settings.html#args

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:

{
    "args": "--foo=bar --bar=7 --no-baz"
}

{
    "args": [
        "--foo=bar",
        "--bar=7",
        "--no-baz"
    ]
}

The following does not lint on my Sublime 3.0, removing the "--fix" and it does.

{
    "args": "--fix"
}

And yet the following works fine

eslint --fix myJsFile.js

Does not compute!

bdefore

bdefore commented on Jan 26, 2016

@bdefore

Would also love to see --fix support! 👍

joerideg

joerideg commented on Jan 28, 2016

@joerideg

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

roadhump

roadhump commented on Jan 30, 2016

@roadhump
Collaborator

@mummybot Plugin uses stdin as input (--stdin option of eslint). It does not work with --fix, as I know.

karolyi

karolyi commented on Feb 18, 2016

@karolyi

+1

jorgenbs

jorgenbs commented on Mar 8, 2016

@jorgenbs

+1

gblazex

gblazex commented on Mar 17, 2016

@gblazex

+1

glenjamin

glenjamin commented on Apr 23, 2016

@glenjamin
Contributor

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 --stdin when the file has been saved. And then --fix could be passed in that scenario.

softwarespot

softwarespot commented on Apr 23, 2016

@softwarespot

This was released 6 days ago >> https://github.com/TheSavior/ESLint-Formatter. It's JSCS Formatter renamed

20 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kaste@joeybaker@kzap@mummybot@bdefore

        Issue actions

          Fix the code using --fix · Issue #104 · SublimeLinter/SublimeLinter-eslint