3

I am trying to add a linter to my Express application and am getting several linter errors about ES6, i.e. ‘export’ is only available in ES6 (use esnext option), ’const’ is only available in JavaScript 1.7, and ’arrow function syntax’ is only available in Javascript 1.7. I’m not sure how to get rid of these errors—any help would be appreciated. I currently have tried installing several things, including Sublime Text 2 linter and babel-eslint, but might be approaching this wrong.

From relevant package.json:

{
"dependencies": {
  "babel-cli": "^6.10.1",
  "babel-preset-es2015": "^6.9.0",
  "babel-preset-stage-2": "^6.5.0",
  "bcrypt-nodejs": "0.0.3",
  "botkit-sms": "^1.1.0",
  "dotenv": "^2.0.0",
  "express": "^4.14.0",
  "jwt-simple": "^0.5.0",
  "mongoose": "^4.6.3",
  "passport": "^0.3.2",
  "passport-jwt": "^2.2.1",
  "passport-local": "^1.0.0",
  "request": "^2.76.0",
  "routific": "0.0.2"
},
"devDependencies": {
  "babel-eslint": "^6.1.2",
  "eslint": "^2.13.1",
  "eslint-config-airbnb": "^9.0.1",
  "eslint-plugin-import": "^1.16.0",
  "eslint-plugin-jsx-a11y": "^1.4.2",
  "eslint-plugin-react": "^5.1.1",
  "nodemon": "^1.9.2"
}

}

.babelrc:

{
   "presets": ["es2015", "stage-2"]
}

.eslintrc:

{
extends: ["airbnb", "esnext"],
parser: "babel-eslint",
env: {
  browser: false,
  node: true,
  es6: true
},
rules: {
  strict: 0,
  quotes: [2, "single"],
  no-else-return: 0,
  new-cap: ["error", {"capIsNewExceptions": ["Router"]}],
  no-console: 0,
  import/no-unresolved: [2, { commonjs: true}],
  no-unused-vars: ["error", { "vars": "all", "args": "none" }],
  no-underscore-dangle: 0,
  arrow-body-style: ["error", "always"],
  no-shadow: ["error", { "allow": ["done", "res", "cb", "err", "resolve", "reject"] }],
  no-use-before-define: ["error", { "functions": false }],
  max-len: 0
},
plugins: [
  'import'
],
ecmaFeatures: {
  jsx: true,
  modules: true
}
}
user3802348
  • 2,502
  • 11
  • 36
  • 49

3 Answers3

2

Setting the esnext to true in Preferences -> Package Settings -> Sublimelinter -> Settings-User worked for me

{
  "jshint_options":
    {
        "esnext": true
    }
}
Thu San
  • 1,400
  • 1
  • 17
  • 29
0

I think you must get rid of esnext This is my node .eslintrc:

    {
  "extends" : "airbnb",
  "rules": {
   // disable requiring trailing commas because it might be nice to revert to
   // being JSON at some point, and I don t want to make big changes now.
   "comma-dangle": 0,
   // we can use escape and template strings
   "quotes": [1, "single", {"avoidEscape": true, "allowTemplateLiterals": true}],
   "max-len": [0],
   "no-console": 0,
   "no-param-reassign": 0
 },
 "globals": { "ENV": true },
 "env": {
    "browser": true,
    "node": true,
    "jasmine": true
  }
}

And these are my devDependencies

  "devDependencies": {
    "babel-cli": "^6.9.0",
    "babel-core": "^6.9.0",
    "babel-preset-es2015": "^6.9.0",
    "babel-preset-stage-0": "^6.5.0",
    "eslint": "^3.1.1",
    "eslint-config-airbnb": "^12.0.0",
    "eslint-plugin-import": "1.16.0",
    "eslint-plugin-jsx-a11y": "2.2.3",
    "eslint-plugin-react": "6.4.1",
    "nodemon": "^1.9.2"
  }
Slumber86
  • 673
  • 6
  • 8
0

The ecmaFeatures configuration setting goes under parserOptions.

...
plugins: [
  'import'
],
parserOptions: {
    ecmaFeatures: {
        jsx: true
    },
    ecmaVersion: 6,
    sourceType: 'module'
},
...

And you should use sourceType: 'module' instead of modules: true.

cartant
  • 57,105
  • 17
  • 163
  • 197