To use this package, the following packages must be installed in the consuming project.
- ESLint
- TypeScript
- Prettier
Recommended installation:
yarn add -D eslint typescript prettier @regionhalland/eslint-config
Sample configuration for package.json:
// package.json
{
...
"script": {
"lint": "eslint ./src",
"lint:fix": "eslint ./src --fix"
}
...
}
Configuration for React application:
-
@regionhalland/eslint-config
is standard config. -
@regionhalland/eslint-config/recommended
is recommended config with addition of the plugin simple-import-sort.
// .eslintrc.cjs
module.exports = {
extends: "@regionhalland/eslint-config",
rules: {
"no-restricted-imports": [
"error",
{
patterns: [
"@/features/*/*"
]
}
]
},
};
Configuration for Node.js application:
// .eslintrc.cjs
module.exports = {
extends: "@regionhalland/eslint-config/node",
};
Merge config:
// .eslintrc.cjs
const defaultConfig = require('@regionhalland/eslint-config/recommended');
const { mergeRules } = require('@regionhalland/eslint-config/utils');
// Modify a part of existing rule
const extendedRules = {
'@typescript-eslint/naming-convention': [
'warn',
{
selector: 'parameter',
format: ['camelCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
},
]
};
const eslintRules = mergeRules(defaultConfig['rules'], extendedRules);
module.exports = {
extends: "@regionhalland/eslint-config/recommended",
rules: {
...eslintRules
},
ignorePatterns: [
"*.cjs"
]
};