I use Sublime Text for my programming, which uses the Node edition of JSLint for its code linter, but I grow tired of it being out of date.

C:\Users\paulm>jslint --edition=latest --version
node-jslint version: 0.11.0 JSLint edition 2015-10-29

A more recent 2018-05-30 edition is available from jslint.com, but that’s not in the node-jslint library that I use. It’s time to add it there.

Where to put things?

Finding out where to put things is the first challenge, but by giving an unused edition I can learn where the files are stored.

C:\Users\paulm>jslint --edition=2018-05-30 --version
Unable to load edition 2018-05-30, reverting to default. Error: ENOENT:
  no such file or directory, open 'C:\Users\paulm\AppData\Roaming\
  npm\node_modules\jslint\lib\jslint-2018-05-30.js'

Converting the code

I can save the jslint.com/jslint.js file to that location, but the code isn’t understood by node. It has a more primitive understanding of JavaScript code.

C:\Users\paulm>jslint --edition=2018-05-30 --version
evalmachine.:4898
export default function jslint(source, option_object, global_array) {
^^^^^^

SyntaxError: Unexpected token export

This problem occurs because Node doesn’t use ES6 module syntax, but instead uses a different CommonJS syntax.

It’s possible to use babel-preset-env to automatically convert the code, but with the code being globally used via Sublime Text I don’t know where the .babelrc config file should be put.

Instead, I can run the code through Babel to replace the fancy ES6 code from 2015 with older techniques and see how that goes.

C:\Users\paulm\OneDrive>jslint --edition=2018-05-30 --version
evalmachine.:3
Object.defineProperty(exports, "__esModule", {
 ^

ReferenceError: exports is not defined

One last problem to deal with is to add an exports object to the code.

var exports = {};
Object.defineProperty(exports, "__esModule", {

And the code seems to be accepted.

C:\Users\paulm\OneDrive>jslint --edition=2018-05-30 --version
node-jslint version: 0.11.0 JSLint edition 2018-05-30

Configure SublimeLinter

In SublimeText I can now edit the SublimeLinter settings to tell it to use the 2018-05-30 edition.

// SublimeLinter Settings - User
{
    "linters": {
        "jslint": {
            "args": [
                "--edition=2018-05-30",
                "--fudge"
            ]
        }
    }
}

And the newest JSLint linter is now being used by my Sublime Text code editor. Sweet!

Advertisements