Search code examples
sublimetext3babeljssublime-text-plugineslint

eslint parse error on first colon in config file?


Using eslint 2.9.0 with babel-eslint 6.0.4 through SublimeLinter in Sublime Text 3114. Since recently eslint cannot parse the '.eslintrc.js' at the root of my web dir anymore. Whenever I open a js file I recieve the error:

Cannot read config file: /usr/share/nginx/html/.eslintrc.js
Error: Unexpected token :
/usr/share/nginx/html/.eslintrc.js:2
    "parser": "babel-eslint",
            ^
SyntaxError: Unexpected token :
    at Object.exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:513:28)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at module.exports (/usr/lib/node_modules/eslint/node_modules/require-uncached/index.js:14:12)
    at loadJSConfigFile (/usr/lib/node_modules/eslint/lib/config/config-file.js:161:16) 

Here is the full .eslintrc.js:

{
    "parser": "babel-eslint",
    "env": {
        "browser": true,
        "node": true
    },
    "root": true
}

What's going on? I don't understand what's the issue..


Solution

  • eslint apparently expects different formats depending on the configuration file extension.

    Solution 1

    Rename .eslintrc.js to .eslintrc.json

    Solution 2

    Use the following format for .eslintrc.js:

    module.exports = {
        "root": true,
        "parser": "babel-eslint",
        "env": {
            "browser": true,
            "jquery": true
        },
    };