Is there a lint for ES6 javascript


#1

I have this very simple javascript file with ES6 sintaxes. Such file runs perfectly in Chrome.

‘use strict’

let myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve(‘good’);
}, 1000);

setTimeout(() => {
reject(‘rejected’);
},500);
});

myPromise.then((res) => {
console.log((res));
});

Here are all my plugins:

Z:>apm list --installed
Community Packages (9) C:\Users\my-user.atom\packages
├── atom-ide-ui@0.12.0
├── busy-signal@1.4.3
├── intentions@1.1.5
├── jslint@1.5.1
├── linter@2.2.0
├── linter-jslint@11.1.0!
├── linter-ui-default@1.7.1
├── polymer-ide@0.4.0
└── termination@0.6.2

And it complains abourt “use strict” and “let”.


#2

When you choose a linter, you can either accept its default configuration or set it up according to your needs. To do the latter, you either specify your preferences in a rule configuration file (e.g. .eslintrc) or use presets – if the linter supports them. For example, eslint-config-airbnb is a popular preset for eslint (find out more), it defines the preferences the developers at Airbnb use.

Apart from that I have noticed that you’re using a .jshintrc with jslint, but that’s not a compatible setup. Use .jshintrc with jshint or .jslintrc with jslint.


#3

I am very new Atom user. Please, can you suggest some plugin and its rule configuration or presets that covers Javascript ES6? If I understood correctly, I have to set up either in some fconfiguration file that I want to use ES6, right? PS.: the “more” link is broken.


#5

I renamed .jshintrc to .jslintrc. I copied
{
“parserOptions”: {
“ecmaVersion”: 6,
“sourceType”: “module”,
“ecmaFeatures”: {
“jsx”: true
}
},
“rules”: {
“semi”: 2
}
}
from https://eslint.org/docs/user-guide/configuring expecting to get my jslint customized for ES6. Well, nothing changed at all. Please, could you either provide a tutorial how to setup lint for ES6 in Atom or at least a very basic example? It can be any lint plugin. I just need start use it and then I will evolve.


#6

Again: JSHint, JSLint and ESLint are three different linters with incompatible settings. You either need to use a valid JSLint configuration or switch to using ESLint.

I’m using ESLint myself, so I cannot make any recommendation for other linters.


#7

Idleberg, would be possible you share how you set up ESLint for JavaScript ES6?


#8

Sure, I have several in use and they differ depending on the use-case. Note that I’ve stored my config in the package.json rather than in .eslintrc. You can use whichever you prefer. Here’s the relevant part of it:

{
  "scripts: {
    "lint": "eslint src/*.js"
  },
  "devDependencies": {
      "eslint": "^4.19.1"
  },
  "eslintConfig": {
    "parserOptions": {
      "env": {
        "node": true
      },
      "ecmaVersion": 6,
      "sourceType": "module"
    },
    "rules": {
      "consistent-return": 0,
      "no-console": 0
    }
  }
}

If you prefer using .eslintrc, it would look like this:

"parserOptions": {
  "env": {
    "node": true
  },
  "ecmaVersion": 6,
  "sourceType": "module"
},
"rules": {
  "consistent-return": 0,
  "no-console": 0
}

Note: If you don’t use ES6 imports/exports, you don’t need to set sourceType to module. Also, you might want to use a env different setting, e.g. if you’re developing for the browser.

One last tip: you will find plenty of good setups on GitHub that match your needs better than my setup. For example, searching for “eslint web boilerplate” brings up some good configs for the browser.