chore: Add eslintrc flavors

This commit is contained in:
Sören Beye 2022-07-21 12:45:13 +02:00
parent e10313dc75
commit b3843f8bd3
11 changed files with 429 additions and 20 deletions

View File

@ -0,0 +1,18 @@
{
"rules": {
"brace-style": ["error", "1tbs"],
"no-trailing-spaces": ["error", { "ignoreComments": true }],
"keyword-spacing": "error",
"eol-last": ["error", "always"],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"semi": ["error", "always"],
"quotes": ["error", "double"],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
]
}
}

View File

@ -35,7 +35,6 @@
"block-scoped-var": "error",
"no-new": "error",
"no-multi-str": "error",
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"no-new-wrappers": "error",
"no-sequences": "error",
"no-self-compare": "error",
@ -43,19 +42,6 @@
"no-whitespace-before-property": "error",
"no-magic-numbers": ["off", { "ignoreArrayIndexes": true }],
"no-unused-vars": ["error", { "args": "none" }],
"semi": ["error", "always"],
"quotes": ["error", "double"],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"brace-style": ["error", "1tbs"],
"no-trailing-spaces": ["error", { "ignoreComments": true }],
"keyword-spacing": "error",
"eol-last": ["error", "always"],
"jsdoc/check-alignment": "error",
"jsdoc/check-param-names": "error",
"jsdoc/check-tag-names": "error",
@ -72,7 +58,23 @@
"operator-linebreak": ["error", "after"],
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
"arrow-body-style": ["error", "always"],
"regexp/no-unused-capturing-group": "off"
"regexp/no-unused-capturing-group": "off",
"brace-style": ["off", "1tbs"],
"no-trailing-spaces": ["off", { "ignoreComments": true }],
"keyword-spacing": "off",
"eol-last": ["off", "always"],
"no-multi-spaces": ["off", { "ignoreEOLComments": true }],
"semi": ["off", "always"],
"quotes": ["off", "double"],
"indent": [
"off",
4,
{
"SwitchCase": 1
}
]
},
"overrides": [
{

View File

@ -0,0 +1,5 @@
{
"rules": {
"no-magic-numbers": ["error", { "ignoreArrayIndexes": true }]
}
}

View File

@ -0,0 +1,68 @@
{
"overrides": [
{
"files": [
"lib/**/index.js"
],
"rules": {
"sort-keys-fix/sort-keys-fix": "warn"
}
},
{
"files": [
"index.js",
"lib/**/*.js",
"util/**/*.js"
],
"parserOptions": {
"ecmaVersion": 2020
},
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"rules": {
"no-process-exit": "off",
"node/no-process-exit": "off"
}
}
],
"rules": {
"brace-style": [
"error",
"1tbs"
],
"no-trailing-spaces": [
"error",
{
"ignoreComments": true
}
],
"keyword-spacing": "error",
"eol-last": [
"error",
"always"
],
"no-multi-spaces": [
"error",
{
"ignoreEOLComments": true
}
],
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double"
],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
]
}
}

View File

@ -0,0 +1,74 @@
{
"overrides": [
{
"files": [
"lib/**/index.js"
],
"rules": {
"sort-keys-fix/sort-keys-fix": "warn"
}
},
{
"files": [
"index.js",
"lib/**/*.js",
"util/**/*.js"
],
"parserOptions": {
"ecmaVersion": 2020
},
"extends": [
"eslint:recommended",
"plugin:node/recommended"
],
"rules": {
"no-process-exit": "off",
"node/no-process-exit": "off"
}
}
],
"rules": {
"brace-style": [
"error",
"1tbs"
],
"no-trailing-spaces": [
"error",
{
"ignoreComments": true
}
],
"keyword-spacing": "error",
"eol-last": [
"error",
"always"
],
"no-multi-spaces": [
"error",
{
"ignoreEOLComments": true
}
],
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double"
],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"no-magic-numbers": [
"error",
{
"ignoreArrayIndexes": true
}
]
}
}

View File

@ -20,8 +20,9 @@
"scripts": {
"start": "node index.js",
"start:dev": "cross-env VALETUDO_CONFIG_PATH=../local/valetudo_config.json npm run start",
"lint": "eslint .",
"lint_fix": "eslint . --fix",
"lint": "eslint -c .automated.eslintrc.json .",
"lint_fix": "eslint -c .automated.eslintrc.json . --fix",
"lint_pedantic": "eslint -c .pedantic.eslintrc.json .",
"ts-check": "tsc --noEmit",
"test": "mocha \"test/**/*_spec.js\"",
"prepare_commit": "npm run lint_fix && npm run ts-check && npm run test",

View File

@ -0,0 +1,88 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"react",
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
},
"linkComponents": [
"Hyperlink",
{
"name": "Link",
"linkAttribute": "to"
}
]
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"warn",
{
"varsIgnorePattern": "^_",
"args": "none"
}
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"brace-style": [
"error",
"1tbs"
],
"no-trailing-spaces": [
"error",
{
"ignoreComments": true
}
],
"keyword-spacing": "error",
"eol-last": [
"error",
"always"
],
"no-multi-spaces": [
"error",
{
"ignoreEOLComments": true
}
],
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double"
],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
]
}
}

View File

@ -0,0 +1,94 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:@typescript-eslint/recommended"
],
"plugins": [
"react",
"@typescript-eslint"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"settings": {
"react": {
"version": "detect"
},
"linkComponents": [
"Hyperlink",
{
"name": "Link",
"linkAttribute": "to"
}
]
},
"rules": {
"@typescript-eslint/no-unused-vars": [
"warn",
{
"varsIgnorePattern": "^_",
"args": "none"
}
],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
"react/prop-types": "off",
"brace-style": [
"error",
"1tbs"
],
"no-trailing-spaces": [
"error",
{
"ignoreComments": true
}
],
"keyword-spacing": "error",
"eol-last": [
"error",
"always"
],
"no-multi-spaces": [
"error",
{
"ignoreEOLComments": true
}
],
"semi": [
"error",
"always"
],
"quotes": [
"error",
"double"
],
"indent": [
"error",
4,
{
"SwitchCase": 1
}
],
"no-magic-numbers": [
"error",
{
"ignoreArrayIndexes": true
}
]
}
}

View File

@ -7,8 +7,9 @@
"eject": "react-scripts eject",
"watch": "cra-build-watch -p ''",
"ts-check": "tsc --noEmit --skipLibCheck",
"lint": "eslint .",
"lint_fix": "eslint . --fix",
"lint": "eslint -c .automated.eslintrc.json .",
"lint_fix": "eslint -c .automated.eslintrc.json . --fix",
"lint_pedantic": "eslint -c .pedantic.eslintrc.json .",
"prepare_commit": "npm run lint_fix && npm run ts-check"
},
"eslintConfig": {

View File

@ -21,7 +21,8 @@
"build_release_manifest": "node util/build_release_manifest.js",
"check_dependencies_for_update": "npx check-outdated --ignore-pre-releases --ignore-packages react-router-dom",
"generate_changelog": "npx auto-changelog --commit-limit false --tag-pattern .+ --handlebars-setup ./util/res/auto_changelog_handlebars_helpers.js --template ./util/res/auto_changelog_template.hbs --output ./build/changelog.md",
"generate_nightly_changelog": "npx auto-changelog --commit-limit false --tag-pattern .+ --unreleased-only --handlebars-setup ./util/res/auto_changelog_handlebars_helpers.js --template ./util/res/auto_changelog_template.hbs --output ./build/changelog_nightly.md"
"generate_nightly_changelog": "npx auto-changelog --commit-limit false --tag-pattern .+ --unreleased-only --handlebars-setup ./util/res/auto_changelog_handlebars_helpers.js --template ./util/res/auto_changelog_template.hbs --output ./build/changelog_nightly.md",
"generate_eslintrc_flavors": "node util/generate_eslintrc_flavors.js"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "5.25.0",

View File

@ -0,0 +1,57 @@
const fs = require("fs");
const backendEslintRc = JSON.parse(fs.readFileSync("./backend/.eslintrc.json").toString());
const frontendEslintRc = JSON.parse(fs.readFileSync("./frontend/.eslintrc.json").toString());
backendEslintRc.rules = backendEslintRc.rules ?? {};
frontendEslintRc.rules = frontendEslintRc.rules ?? {};
/*
This file serves two purposes
1)
To avoid constantly seeing red squiggly lines for things that one is currently working on,
all of these useful but not useful in this context rules have been moved to the .automated_overrides.eslintrc.json
and will only be used for the package.json scripts lint and lint_fix instead of IDE annotations
2)
Some eslint rules are known to produce a lot of false positive noise. They however also occasionally surface
some issues that other rules don't and help as nudges to revisit old code.
Thus, it makes sense to run them from time to time but definitely not daily
These rules also extend the automated ones
*/
const automatedOverrides = JSON.parse(fs.readFileSync("./.automated_overrides.eslintrc.json").toString());
const backendAutomatedEslintRc = JSON.parse(JSON.stringify(backendEslintRc));
const frontendAutomatedEslintRc = JSON.parse(JSON.stringify(frontendEslintRc));
Object.keys(automatedOverrides.rules).forEach(ruleName => {
backendAutomatedEslintRc.rules[ruleName] = automatedOverrides.rules[ruleName];
frontendAutomatedEslintRc.rules[ruleName] = automatedOverrides.rules[ruleName];
});
fs.writeFileSync("./backend/.automated.eslintrc.json", JSON.stringify(backendAutomatedEslintRc, null, 2));
fs.writeFileSync("./frontend/.automated.eslintrc.json", JSON.stringify(frontendAutomatedEslintRc, null, 2));
const pedanticOverrides = JSON.parse(fs.readFileSync("./.pedantic_overrides.eslintrc.json").toString());
const backendPedanticEslintRc = JSON.parse(JSON.stringify(backendAutomatedEslintRc));
const frontendPedanticEslintRc = JSON.parse(JSON.stringify(frontendAutomatedEslintRc));
Object.keys(pedanticOverrides.rules).forEach(ruleName => {
backendPedanticEslintRc.rules[ruleName] = pedanticOverrides.rules[ruleName];
frontendPedanticEslintRc.rules[ruleName] = pedanticOverrides.rules[ruleName];
});
fs.writeFileSync("./backend/.pedantic.eslintrc.json", JSON.stringify(backendPedanticEslintRc, null, 2));
fs.writeFileSync("./frontend/.pedantic.eslintrc.json", JSON.stringify(frontendPedanticEslintRc, null, 2));