eslint-config-leroymerlin
LeroyMerlin's ESLint config for Node.js apps
- Requires Node.js
>=14
- Requires ESLint
>=8
Using with Javascript apps
@leroymerlin/eslint-config-leroymerlin/node/javascript
Install & Usage
npm install --save-dev eslint prettier @leroymerlin/eslint-config-leroymerlin
Note: It recommends a use of the "engines" field of package.json. The "engines" field is used by node/no-unsupported-features/*
rules.
package.json
{
/*
...
*/
"engines": {
"node": "14"
}
}
.eslintrc.js (An example)
'use strict';
module.exports = {
root: true,
extends: ['@leroymerlin/eslint-config-leroymerlin/node/javascript'],
rules: {
/*
Add any additional rules here
*/
'no-console': 'warn',
},
};
Using with Typescript apps
@leroymerlin/eslint-config-leroymerlin/node/typescript
Install & Usage
npm install --save-dev eslint prettier @leroymerlin/eslint-config-leroymerlin @typescript-eslint/eslint-plugin
.eslintrc.js (An example)
'use strict';
module.exports = {
root: true,
parserOptions: {
project: 'tsconfig.json',
},
extends: ['@leroymerlin/eslint-config-leroymerlin/node/typescript'],
rules: {
/*
Add any additional rules here
*/
'no-console': 'warn',
},
};
Additional Configuration
Please, use it config with husky
To use git-hooks, install required dependencies via npm:
npx husky-init && npm install \
&& npm install --save-dev lint-staged
.husky/pre-commit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no-install lint-staged
lint-staged.config.js (Javascript apps)
'use strict';
module.exports = {
'*.{js,json,md,y*ml}': ['prettier --write'],
'*.js': ['eslint --cache --fix'],
};
lint-staged.config.js (Typescript apps)
const fs = require('fs');
function generateTSConfig(stagedFilenames) {
const tsconfig = JSON.parse(fs.readFileSync('tsconfig.json', 'utf8'));
tsconfig.include = stagedFilenames;
fs.writeFileSync('tsconfig.lint.json', JSON.stringify(tsconfig));
return 'tsc --noEmit --project tsconfig.lint.json';
}
module.exports = {
'*.{js,ts,json,md,y*ml}': ['prettier --write'],
'*.ts': ['eslint --cache --fix', generateTSConfig],
};
License
@leroymerlin/eslint-config-leroymerlin is MIT.