@setel/eslint-config-setel
v1.0.18
Published
Setel's internal centralized eslint config
Readme
Intro
This package provide strict ESLint rule which can be consistent across Setel. On top of that the package also provides formatter which turns ESLint errors and warnings into a single HTML page.
Getting Started
Installation
- Run
npm install @setel/eslint-config-setel --devin your repo - Add / Update
package.jsonby adding"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" -f ./node_modules/@setel/eslint-config-setel/dist/formatter.js --output-file .eslint/index.html" - Update
eslintrc.jstomodule.exports = { parserOptions: { project: 'tsconfig.json', sourceType: 'module' }, extends: ["@setel/eslint-config-setel"], root: true, rules: {} };- If you encounter any error on
eslintrc.jsfile- Remove any eslint configs
- Do clean npm install
- Make sure tsconfig.json follows
{ "compilerOptions": { "module": "commonjs", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "allowSyntheticDefaultImports": true, "target": "es2017", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "incremental": true, "skipLibCheck": true }, "include": ["src", "test", ".eslintrc.js"], "exclude": [ "node_modules", "dist" ] }
- Run
npm run lintin your terminal - You should see
.eslint/index.htmlfile.
Build the package
- Run
npm run build- This will run
tsc
- This will run
- Javascript files can be viewed at
./dist/*
Architecture
ESLint
ESLint extends @typescript-eslint/eslint-recommended, @typescript-eslint/recommended, eslint-plugin-sonarjs and prettier. This is defined in index.js.
Formatter
ESLint will pass two objects results and context to formatter.
Result object has the following type:
{
filePath: string;
messages: {
ruleId: string; // keys of context.rulesMeta
severity: number; // 1 = warning , 2 = error
message: string;
line: number;
column: number;
nodeType: string; // the type of the node in the AST
}[];
errorCount: number;
warningCount: number;
fixableErrorCount: number;
fixableWarningCount: number;
source: string // entire file
}[]Context object has the following type:
{
cwd: string; // The current working directory
maxWarningsExceeded: {
maxWarnings: number;
foundWarnings: number;
};
rulesMeta: {
string: {
type: string; // "problem", "suggestion", or "layout":
docs: {
description: string;
recommended: boolean;
url: string; // link to actual error description in github or npm
};
fixable: string; // "code" or "whitespace"
schema: []
}
};
}Further details can be found here
Formatter will go over items in Result array and get the rule using ruleId and form and accordion for each file.
Formatter will produce HTML including CSS and JS scripts.
