ESLint Rules
Project Zero uses a set of ESLint rules which extends upon the "eslint:recommended" rule set. These rules are marked by a checkmark at https://eslint.org/docs/rules/ . Keep in mind that ESLint might change these at any time. You can see the extended rules in /templates/.eslintrc.js
.
Most of these added rules are from Best Practices, Stylistic Issues and ECMAScript 6 sections. The main goal here is to have a base set of rules that prevents some common issues and improve code readability without restricting the developer too much.
Since we use '@babel/eslint-parser' as parser, you should make sure that you're using Node.js version 14+.
To make sure ESLint is properly configured in the project and its rules are applied correctly, there is a "pre-commit" git hook. With it, no code that doesn't pass linting will be pushed to production. Of course, it is possible for developers to use "eslint-disable" statements and these should be caught and questioned during code review.
To help find and fix possible linting errors on project basis, there are 2 npm scripts: npm run lint
and npm run lint:fix
.
"lint": "eslint .", // Lint project
"lint:fix": "eslint . --fix" // Lint project and fix auto-fixable issues
If you're using Visual Studio Code, following setup is recommended:
1 - Plugin: VS Code ESLint
2 - Settings:
{
// Auto-fix problems on file save
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
// Make sure it's looking at the correct directory
"eslint.workingDirectories": ["./templates"],
}