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

Newer jslint editions has a 0 index for lines and columns #5

Closed
nomego opened this issue Jul 13, 2015 · 3 comments
Closed

Newer jslint editions has a 0 index for lines and columns #5

nomego opened this issue Jul 13, 2015 · 3 comments

Comments

@nomego
Copy link

nomego commented Jul 13, 2015

If you switch to edition "latest", "2015-05-08" or "es6" in the current node-jslint, the indexes for line and column in error reporting is now 0.

The default edition is still an old jslint from 2013 though, so I guess SublimeLinter-contrib-jslint needs a configuration option whether to adjust the lines and columns with one or not.

@devdoc
Copy link
Owner

devdoc commented Jul 20, 2015

Thanks for reporting. Indeed the new JSLint seems to use zero-based indexing for columns and lines. It does include a new option ("fudge", see http://www.jslint.com/help.html) that seems to provide a way to revert to the usual 1-based indexing used by most text editors. However, this option does not seem to be supported by node-jslint yet.

I tried using fudge as an inline setting (by including /*jslint fudge: true in a .js-file to be linted), but it didn't seem to affect what was reported by node-jslint. Not sure why that is, but on jslint.com the inline fudge directive seems to work as advertised.

I would argue that this feature should really be implemented in node-jslint rather than SublimeLinter-jslint (node-jslint is the immediate wrapper for jslint, which already seems to support 1-based line/column numbering through the fudge option), so I don't think I will officially release a new version of SublimeLinter-jslint at this stage (I did create an issue at reid/node-jslint#135). That said, I did try the following modifications locally, which seemed to work with node-jslint's "latest" edition, so if you want to manually install SublimeLinter-jslint you could do these modifications locally:

In linter.py you should add at the bottom:

    def split_match(self, match):
        """
        We override this method because new versions of jslint report line/col
        numbers starting with 0 instead of 1, necessiating use of a setting to
        allow transforming the numbers into matching line/col numbers in
        Sublime Text
        """

        startFromZero = self.get_view_settings().get('startFromZero', False)

        match, line, col, error, warning, message, near = super().split_match(match)

        if startFromZero:
            line = line + 1
            col = col + 1

        return match, line, col, error, warning, message, near

Then, in SublimeLinter.sublime-settings (find them e.g. via Preferences > Package Settings > SublimeLinter > Settings - User) you should modify the jslint section as follows:

            "jslint": {
                "@disable": false,
                "args": [
                    "--edition=latest"
                ],
                "startFromZero": true,
                "excludes": []
            },

The startFromZero option will indicate to the modified linter.py that row/column numbers need to be transformed to 1-based numbers before being handed over to SublimeLinter.

@devdoc devdoc mentioned this issue Dec 7, 2015
@pmw57
Copy link

pmw57 commented Apr 12, 2016

You'll find that jslint.com is fudging the reported line/col numbers from the report.js script.

node-jslint would need to adjust their own reporter.js script to make use of the data.option.fudge value.

@devdoc
Copy link
Owner

devdoc commented May 23, 2016

node-jslint now (as of version 0.10.0) supports fudging thanks to a recently merged PR (reid/node-jslint#150) by @pmw57, which means you can edit the jslint section in you SublimeLinter.sublime-settings (find them e.g. via Preferences > Package Settings > SublimeLinter > Settings - User) as follows to make it use the latest (es6 enabled) version of JSLint and still get 1-based line numbers which allow linting errors to be highlighted at the correct spots in your code.

            "jslint": {
                "@disable": false,
                "args": [
                    "--edition=latest",
                    "--fudge"
                ],
                "excludes": []
            },

Kudos to @pmw57 for expediting fudge support!

@devdoc devdoc closed this as completed May 23, 2016
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

No branches or pull requests

3 participants