From 6973926a341223d6ef8783c23132c29aa400e275 Mon Sep 17 00:00:00 2001 From: VWSCoronaDashboard22 <93981265+VWSCoronaDashboard22@users.noreply.github.com> Date: Wed, 16 Feb 2022 09:53:26 +0100 Subject: [PATCH] Created a eslint base config and extend from this in each package (#4038) --- eslint-config.json | 18 +++++ eslint-overrides.json | 38 ++++++++++ package.json | 1 + packages/app/.eslintrc.json | 47 ++---------- packages/cli/.eslintrc.json | 18 +++++ packages/cli/package.json | 6 +- .../src/schema/create-validate-function.ts | 2 +- .../schema/custom-validations/choropleth.ts | 8 +- .../calculate-bounding-box-municipalities.ts | 2 +- .../cli/src/scripts/validate-json-single.ts | 2 +- packages/cms/.eslintrc.json | 4 +- packages/common/.eslintrc.json | 75 ++----------------- packages/e2e/.eslintrc.json | 75 ++----------------- packages/icons/.eslintrc.js | 35 --------- packages/icons/.eslintrc.json | 18 +++++ yarn.lock | 4 + 16 files changed, 134 insertions(+), 219 deletions(-) create mode 100644 eslint-config.json create mode 100644 eslint-overrides.json create mode 100644 packages/cli/.eslintrc.json delete mode 100644 packages/icons/.eslintrc.js create mode 100644 packages/icons/.eslintrc.json diff --git a/eslint-config.json b/eslint-config.json new file mode 100644 index 0000000000..d63beac541 --- /dev/null +++ b/eslint-config.json @@ -0,0 +1,18 @@ +{ + "extends": [ + "eslint:recommended", + "prettier" + ], + "env": { + "es6": true, + "node": true + }, + "rules": { + "no-console": [ + 2, + { + "allow": ["warn", "error"] + } + ] + } +} diff --git a/eslint-overrides.json b/eslint-overrides.json new file mode 100644 index 0000000000..9542695829 --- /dev/null +++ b/eslint-overrides.json @@ -0,0 +1,38 @@ +{ + "overrides": [ + { + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint", "risxss"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "files": ["*.ts", "*.tsx"], + "rules": { + "@typescript-eslint/explicit-function-return-type": 0, + "@typescript-eslint/explicit-member-accessibility": 0, + "@typescript-eslint/indent": 0, + "@typescript-eslint/member-delimiter-style": 0, + "@typescript-eslint/ban-ts-comment": 0, + "@typescript-eslint/no-explicit-any": 0, + "@typescript-eslint/no-var-requires": 0, + "@typescript-eslint/explicit-module-boundary-types": 0, + "@typescript-eslint/no-use-before-define": 0, + "@typescript-eslint/no-unused-vars": [ + 2, + { + "argsIgnorePattern": "^_" + } + ], + "no-restricted-imports": [ + "error", + { + "name": "next/link", + "message": "Please use the custom ~/utils/link instead" + } + ] + } + } + ] +} diff --git a/package.json b/package.json index b29d471475..ad246fb8fe 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "nuke": "yarn workspaces foreach run nuke && npx rimraf node_modules", "typecheck": "yarn workspaces foreach run typecheck", "lint": "yarn workspaces foreach run lint", + "lint:fix": "yarn workspaces foreach run lint --fix", "format": "yarn workspaces foreach run format", "dev": "yarn workspace @corona-dashboard/app dev", "download": "yarn workspace @corona-dashboard/app download", diff --git a/packages/app/.eslintrc.json b/packages/app/.eslintrc.json index e18085f02a..6be9a7c6e4 100644 --- a/packages/app/.eslintrc.json +++ b/packages/app/.eslintrc.json @@ -1,9 +1,8 @@ { "extends": [ - "eslint:recommended", "plugin:react/recommended", "plugin:react-hooks/recommended", - "prettier" + "../../eslint-config" ], "settings": { "react": { @@ -11,9 +10,7 @@ } }, "env": { - "es6": true, - "browser": true, - "node": true + "browser": true }, "parserOptions": { "ecmaVersion": 2020, @@ -25,24 +22,14 @@ "rules": { "react/react-in-jsx-scope": 0, "react/display-name": 0, - "react/prop-types": 0, - "no-console": [ - 2, - { - "allow": ["warn", "error"] - } - ] + "react/prop-types": 0 }, "overrides": [ { - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint", "risxss"], "extends": [ - "eslint:recommended", + "../../eslint-overrides", "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:@typescript-eslint/recommended", - "prettier" + "plugin:react-hooks/recommended" ], "files": ["*.ts", "*.tsx"], "rules": { @@ -54,29 +41,7 @@ ], "react/react-in-jsx-scope": 0, "react/display-name": 0, - "react/prop-types": 0, - "@typescript-eslint/explicit-function-return-type": 0, - "@typescript-eslint/explicit-member-accessibility": 0, - "@typescript-eslint/indent": 0, - "@typescript-eslint/member-delimiter-style": 0, - "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/no-var-requires": 0, - "@typescript-eslint/explicit-module-boundary-types": 0, - "@typescript-eslint/no-use-before-define": 0, - "@typescript-eslint/no-unused-vars": [ - 2, - { - "argsIgnorePattern": "^_" - } - ], - "no-restricted-imports": [ - "error", - { - "name": "next/link", - "message": "Please use the custom ~/utils/link instead" - } - ] + "react/prop-types": 0 } } ] diff --git a/packages/cli/.eslintrc.json b/packages/cli/.eslintrc.json new file mode 100644 index 0000000000..8df4f52183 --- /dev/null +++ b/packages/cli/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": [ + "../../eslint-config" + ], + "parserOptions": { + "ecmaVersion": 2020, + "sourceType": "module" + }, + "overrides": [ + { + "extends": ["../../eslint-overrides"], + "files": ["*.ts", "*.tsx"], + "rules": { + "no-console": 0 + } + } + ] +} diff --git a/packages/cli/package.json b/packages/cli/package.json index 5f07be2dfd..1afce8ff92 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -29,7 +29,7 @@ "test": "echo 'No tests available for @corona-dashboard/cli'", "test:ci": "echo 'No tests available for @corona-dashboard/cli'", "format": "prettier --write \"src/**/*.{js,ts,tsx}\" \"*.{js,json,md,yml}\"", - "lint": "echo 'No linter configured for @corona-dashboard/cli'", + "lint": "eslint .", "typecheck": "tsc --pretty --noEmit", "calculate-boundingboxes": "yarn workspace @corona-dashboard/common build && ts-node src/scripts/calculate-bounding-box-municipalities.ts", "validate-json": "yarn run validate-json-all", @@ -43,6 +43,10 @@ "@types/node": "^16.11.11", "@types/semver": "^7.3.9", "@types/topojson-client": "^3.1.0", + "@typescript-eslint/eslint-plugin": "^5.5.0", + "@typescript-eslint/parser": "^5.5.0", + "eslint": "^7.32.0", + "eslint-config-prettier": "^8.3.0", "ts-node": "^10.4.0", "typescript": "^4.4.4" } diff --git a/packages/cli/src/schema/create-validate-function.ts b/packages/cli/src/schema/create-validate-function.ts index e104937357..366ab66553 100644 --- a/packages/cli/src/schema/create-validate-function.ts +++ b/packages/cli/src/schema/create-validate-function.ts @@ -80,7 +80,7 @@ function disableFeatureFlagMetrics(schema: any, features: Feature[]) { export function createValidateFunction( schemaOrFilename: string | object, schemaBasePath: string, - skipFeatureDisable: boolean = false + skipFeatureDisable = false ) { const schema = typeof schemaOrFilename === 'string' diff --git a/packages/cli/src/schema/custom-validations/choropleth.ts b/packages/cli/src/schema/custom-validations/choropleth.ts index f3de0698cc..0127215f81 100644 --- a/packages/cli/src/schema/custom-validations/choropleth.ts +++ b/packages/cli/src/schema/custom-validations/choropleth.ts @@ -118,7 +118,9 @@ function validateCommonPropertyEquality( } function getCommonProperties(left: UnknownObject, right: UnknownObject) { - return Object.keys(left).filter((key) => right.hasOwnProperty(key)); + return Object.keys(left).filter((key) => + Object.prototype.hasOwnProperty.call(right, key) + ); } function getCommonDataProperties( @@ -130,6 +132,8 @@ function getCommonDataProperties( .filter(([, values]) => typeof values === 'object') .map(([key]) => key) .filter( - (key) => right.hasOwnProperty(key) && !excludedProperties.includes(key) + (key) => + Object.prototype.hasOwnProperty.call(right, key) && + !excludedProperties.includes(key) ); } diff --git a/packages/cli/src/scripts/calculate-bounding-box-municipalities.ts b/packages/cli/src/scripts/calculate-bounding-box-municipalities.ts index 0048df5c40..1f912f2b43 100644 --- a/packages/cli/src/scripts/calculate-bounding-box-municipalities.ts +++ b/packages/cli/src/scripts/calculate-bounding-box-municipalities.ts @@ -52,7 +52,7 @@ const fileHeader = `/** This file was generated by a CLI package script return acc; } - let bbox = turf.bbox(region.geometry); + const bbox = turf.bbox(region.geometry); /** * Enlarge the bounding slightly because the map is rendered in a larger boundingbox * than just the safetyregion. (some surrounding municipals are also visible). diff --git a/packages/cli/src/scripts/validate-json-single.ts b/packages/cli/src/scripts/validate-json-single.ts index d730214889..260b75260a 100644 --- a/packages/cli/src/scripts/validate-json-single.ts +++ b/packages/cli/src/scripts/validate-json-single.ts @@ -105,7 +105,7 @@ if (!fs.existsSync(path.join(jsonBasePath, jsonFileName))) { } const schemaBasePath = path.join(schemaDirectory, schemaName); -let rootSchema = metricName +const rootSchema = metricName ? loadStrippedSchema(metricName, schemaBasePath) : '__index.json'; diff --git a/packages/cms/.eslintrc.json b/packages/cms/.eslintrc.json index 3d4b08dcc7..6a037d9216 100644 --- a/packages/cms/.eslintrc.json +++ b/packages/cms/.eslintrc.json @@ -1,9 +1,7 @@ { "extends": [ - "eslint:recommended", "plugin:react/recommended", - "plugin:react-hooks/recommended", - "prettier" + "plugin:react-hooks/recommended" ], "settings": { "react": { diff --git a/packages/common/.eslintrc.json b/packages/common/.eslintrc.json index c89cd983a0..a7c1e9f22f 100644 --- a/packages/common/.eslintrc.json +++ b/packages/common/.eslintrc.json @@ -1,77 +1,18 @@ { - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:prettier/recommended" - ], - "settings": { - "react": { - "version": "16.13.1" - } - }, - "env": { - "es6": true, - "browser": true, - "node": true - }, + "extends": ["../../eslint-config"], "parserOptions": { "ecmaVersion": 2020, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "rules": { - "react/react-in-jsx-scope": 0, - "react/display-name": 0, - "react/prop-types": 0, - "no-console": [ - 2, - { - "allow": ["warn", "error"] - } - ] + "sourceType": "module" }, "overrides": [ { - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:@typescript-eslint/recommended", - "prettier" + "../../eslint-overrides" ], - "files": ["*.ts", "*.tsx"], - "rules": { - "react/react-in-jsx-scope": 0, - "react/display-name": 0, - "react/prop-types": 0, - "@typescript-eslint/explicit-function-return-type": 0, - "@typescript-eslint/explicit-member-accessibility": 0, - "@typescript-eslint/indent": 0, - "@typescript-eslint/member-delimiter-style": 0, - "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/no-var-requires": 0, - "@typescript-eslint/explicit-module-boundary-types": 0, - "@typescript-eslint/no-use-before-define": 0, - "@typescript-eslint/no-unused-vars": [ - 2, - { - "argsIgnorePattern": "^_" - } - ], - "no-restricted-imports": [ - "error", - { - "name": "next/link", - "message": "Please use the custom ~/utils/link instead" - } - ] - } + "files": [ + "*.ts", + "*.tsx" + ] } ] -} +} \ No newline at end of file diff --git a/packages/e2e/.eslintrc.json b/packages/e2e/.eslintrc.json index c89cd983a0..a7c1e9f22f 100644 --- a/packages/e2e/.eslintrc.json +++ b/packages/e2e/.eslintrc.json @@ -1,77 +1,18 @@ { - "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:prettier/recommended" - ], - "settings": { - "react": { - "version": "16.13.1" - } - }, - "env": { - "es6": true, - "browser": true, - "node": true - }, + "extends": ["../../eslint-config"], "parserOptions": { "ecmaVersion": 2020, - "sourceType": "module", - "ecmaFeatures": { - "jsx": true - } - }, - "rules": { - "react/react-in-jsx-scope": 0, - "react/display-name": 0, - "react/prop-types": 0, - "no-console": [ - 2, - { - "allow": ["warn", "error"] - } - ] + "sourceType": "module" }, "overrides": [ { - "parser": "@typescript-eslint/parser", - "plugins": ["@typescript-eslint"], "extends": [ - "eslint:recommended", - "plugin:react/recommended", - "plugin:react-hooks/recommended", - "plugin:@typescript-eslint/recommended", - "prettier" + "../../eslint-overrides" ], - "files": ["*.ts", "*.tsx"], - "rules": { - "react/react-in-jsx-scope": 0, - "react/display-name": 0, - "react/prop-types": 0, - "@typescript-eslint/explicit-function-return-type": 0, - "@typescript-eslint/explicit-member-accessibility": 0, - "@typescript-eslint/indent": 0, - "@typescript-eslint/member-delimiter-style": 0, - "@typescript-eslint/ban-ts-comment": 0, - "@typescript-eslint/no-explicit-any": 0, - "@typescript-eslint/no-var-requires": 0, - "@typescript-eslint/explicit-module-boundary-types": 0, - "@typescript-eslint/no-use-before-define": 0, - "@typescript-eslint/no-unused-vars": [ - 2, - { - "argsIgnorePattern": "^_" - } - ], - "no-restricted-imports": [ - "error", - { - "name": "next/link", - "message": "Please use the custom ~/utils/link instead" - } - ] - } + "files": [ + "*.ts", + "*.tsx" + ] } ] -} +} \ No newline at end of file diff --git a/packages/icons/.eslintrc.js b/packages/icons/.eslintrc.js deleted file mode 100644 index 235423c229..0000000000 --- a/packages/icons/.eslintrc.js +++ /dev/null @@ -1,35 +0,0 @@ -const path = require('path'); - -module.exports = { - parser: '@babel/eslint-parser', - parserOptions: { - sourceType: 'module', - ecmaVersion: 2021, - ecmaFeatures: { - jsx: true, - impliedStrict: true, - }, - babelOptions: { - configFile: path.resolve(__dirname, '.babelrc'), - }, - }, - settings: { - react: { - version: 'detect', - }, - }, - env: { - node: true, - browser: true, - }, - extends: [ - 'eslint:recommended', - 'plugin:react/recommended', - 'plugin:react-hooks/recommended', - 'prettier', - ], - rules: { - 'arrow-body-style': 0, - 'react/jsx-filename-extension': [1, { extensions: ['.js', '.jsx'] }], - }, -}; diff --git a/packages/icons/.eslintrc.json b/packages/icons/.eslintrc.json new file mode 100644 index 0000000000..5503c829b9 --- /dev/null +++ b/packages/icons/.eslintrc.json @@ -0,0 +1,18 @@ +{ + "extends": ["../../eslint-config"], + "parserOptions": { + "ecmaVersion": 2020, + "sourceType": "module" + }, + "overrides": [ + { + "extends": [ + "../../eslint-overrides" + ], + "files": ["*.js", "*.ts"], + "rules": { + "no-console": 0 + } + } + ] +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index bb50b34f02..f3af1aaf97 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2694,9 +2694,13 @@ __metadata: "@types/node": ^16.11.11 "@types/semver": ^7.3.9 "@types/topojson-client": ^3.1.0 + "@typescript-eslint/eslint-plugin": ^5.5.0 + "@typescript-eslint/parser": ^5.5.0 ajv: ^8.8.2 chalk: ^4.1.2 dotenv: ^10.0.0 + eslint: ^7.32.0 + eslint-config-prettier: ^8.3.0 flat: ^5.0.2 json-schema-to-typescript: ^10.1.5 lodash: ^4.17.21