6.0.0 • Published 6 years ago
eslint-config-semipretty v6.0.0
eslint-config-semipretty
An ESLint config combining semistandard and prettier
Installation
- Run
npx install-peerdeps --dev eslint-config-semipretty
Setup
- Create an
.eslintrc.jsfile in the root of your project, with the following contents:
module.exports = {
extends: ['semipretty']
};- Create an
.eslintignorefile in the root of your project, to exclude all JavaScript files that do not need to be linted, such as generated build files and third party modules. For most projects, the simplest approach is to just copy the contents of your.gitignorefile, e.g.:
build/
logs/
node_modules/- Add
lintandlint-fixscripts to thescriptsobject in yourpackage.json:
"scripts": {
"lint": "eslint .",
"lint-fix": "eslint . --fix"
}Bonus: Automatically lint files on commit
husky allows you run commands automatically when Git events occur, such as when code is committed. lint-staged ensures that only new and modified files are linted, to that the process is as fast as possible.
1) Install husky: run npm install --save-dev husky lint-staged
2) Add the lint-staged and husky objects to your package.json:
"scripts": {
"lint": "eslint .",
"lint-fix": "eslint . --fix"
},
"lint-staged": {
"*.js": ["eslint --fix", "git add"]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}If you're using React
- Install
eslint-plugin-react: runnpm install --save-dev eslint-plugin-react - In your
.eslintrc.jsfile, add the plugin and extend the default configuration, e.g.
module.exports = {
extends: ['semipretty', 'plugin:react/recommended'],
plugins: ['react']
};If you're using Jest
- Install
eslint-plugin-jest:npm install --save-dev eslint-plugin-jest - In your
.eslintrc.jsfile, add the plugin and extend the default configuration, e.g.
module.exports = {
extends: ['semipretty', 'plugin:jest/recommended'],
plugins: ['jest']
};If you're using experimental JavaScript features
If you are using experimental JavaScript features such as class properties, you may encounter parsing errors which can be fixed by adding babel-eslint.
- Install
babel-eslint: Runnpm install --save-dev babel-eslint - Set
babel-eslintas the parser in your.eslintrc.jsfile, for example:
module.exports = {
extends: ['semipretty'],
parser: 'babel-eslint'
};