Skip to content

Instantly share code, notes, and snippets.

@jwill9999
Last active September 23, 2018 21:57
Show Gist options
  • Save jwill9999/de06b891596354ea5f1718f458f26ec4 to your computer and use it in GitHub Desktop.
Save jwill9999/de06b891596354ea5f1718f458f26ec4 to your computer and use it in GitHub Desktop.
Eslint and Prettier configuration for JavaScript VSCode
module.exports = {
"env": {
"mocha": true
},
"extends":[
"airbnb-base",
"prettier"
],
"plugins": [
"import",
"prettier"
],
"rules": {
"prettier/prettier": "error",
"linebreak-style": ["error", "windows"],
"no-console": 0,
"radix": 0,
"no-param-reassign": 0
},
"overrides": [
{
"files": ["*.spec.js", "*.test.js"],
"rules": {
"no-unused-expressions": 0
}
}
]
};

Ensure eslint is installed globally

Install vscode extension eslint.

Install dependencies

{
 "devDependencies": {     
    "eslint": "^5.6.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-config-prettier": "^3.1.0",
    "eslint-plugin-import": "^2.14.0",
    "eslint-plugin-prettier": "^2.6.2",
    "mocha": "^5.2.0",
    "prettier": "^1.14.3"    
}
}

eslint --init

ensure eslint user settings are configured

> NB. Do not enable the prettier extension for VSCode this can cause conflicts with eslint

EXAMPLE CODE

{
    "[javascript]": {
        "editor.formatOnSave": false
    },
     "eslint.autoFixOnSave": true,
     "editor.formatOnSave": true,
     "eslint.alwaysShowStatus": true
}

the .eslintrc file included here also contains overrides for testing conflicts

EXAMPLE CODE

   "env": {
        "mocha": true
    }, 
    "overrides": [
            {
                "files": ["*.spec.js", "*.test.js"],
                "rules": {
                    "no-unused-expressions": 0
                }
            }
        ]
    
{
"name": "test_server",
"version": "0.0.1",
"description": "node http server to serve static files when running tests.",
"main": "index.js",
"scripts": {
"test": "mocha --exit",
"start": "nodemon index.js"
},
"keywords": [
"test",
"testing",
"server",
"static",
"serve",
"http",
"createServer"
],
"author": {
"name": "Jason Williams",
"email": "[email protected]",
"url": "http://letuscode.co.uk"
},
"license": "ISC",
"devDependencies": {
"eslint": "^5.6.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-prettier": "^2.6.2",
"prettier": "^1.14.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment