From ede6c7f8cb9d5fae95f9d4c3291c7712087dee44 Mon Sep 17 00:00:00 2001 From: Kai Salmen Date: Tue, 7 Nov 2023 18:07:59 +0100 Subject: [PATCH] Unify eslint & tsconfig --- .eslintrc.js | 114 +++++++++++++++++++++-- .github/workflows/build.yml | 2 + configs/.eslintrc.js | 111 ---------------------- configs/base.tsconfig.json | 27 ------ examples/tsconfig.json | 8 +- package.json | 2 +- packages/generator-sprotty/tsconfig.json | 2 +- packages/sprotty-elk/tsconfig.json | 27 +++--- packages/sprotty-protocol/tsconfig.json | 5 +- packages/sprotty/tsconfig.json | 6 +- tsconfig.eslint.json | 15 --- tsconfig.json | 37 +++++++- yarn.lock | 6 +- 13 files changed, 176 insertions(+), 186 deletions(-) delete mode 100644 configs/.eslintrc.js delete mode 100644 configs/base.tsconfig.json delete mode 100644 tsconfig.eslint.json diff --git a/.eslintrc.js b/.eslintrc.js index 9a433bf6..ed507d73 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,14 +1,116 @@ /** @type {import('eslint').Linter.Config} */ module.exports = { - extends: ['./configs/.eslintrc.js'], + env: { + browser: true, + node: true + }, + extends: [ + 'prettier' + ], + parser: '@typescript-eslint/parser', ignorePatterns: [ '**/{node_modules,lib}', - // "**/src/**/*.spec.?(ts|tsx)", - // "**/src/utils/test-helper.ts", - "**/sprotty-local-template/**/*" + '**/sprotty-local-template/**/*' ], parserOptions: { tsconfigRootDir: __dirname, - project: 'tsconfig.eslint.json' + project: './tsconfig.json' + }, + plugins: [ + 'eslint-plugin-no-null', + '@typescript-eslint', + 'header' + ], + rules: { + '@typescript-eslint/indent': 'off', + '@typescript-eslint/naming-convention': 'off', + '@typescript-eslint/no-dynamic-delete': 'error', + '@typescript-eslint/no-explicit-any': 'off', + '@typescript-eslint/no-misused-new': 'error', + '@typescript-eslint/no-shadow': [ + 'warn', + { + 'hoist': 'all' + } + ], + '@typescript-eslint/no-unused-expressions': 'off', + '@typescript-eslint/semi': [ + 'error', + 'always' + ], + '@typescript-eslint/type-annotation-spacing': 'warn', + 'header/header': ['error', 'block', [{'pattern': '[\n\r]+ \\* Copyright \\([cC]\\) \\d{4}(-\\d{4})? .*[\n\r]+'}]], + 'brace-style': [ + 'warn', + '1tbs', + { 'allowSingleLine': true } + ], + 'comma-dangle': ['warn', { + 'arrays': 'only-multiline', + 'objects': 'only-multiline', + }], + 'constructor-super': 'error', + 'curly': 'off', + 'eol-last': 'warn', + 'eqeqeq': [ + 'warn', + 'smart' + ], + 'guard-for-in': 'warn', + 'id-blacklist': 'off', + 'id-match': 'off', + 'keyword-spacing': ['warn', { 'before': true }], + 'max-len': [ + 'warn', + { + 'code': 180 + } + ], + 'no-prototype-builtins': 'error', + 'no-caller': 'error', + 'no-console': 'off', + 'no-debugger': 'warn', + 'no-eval': 'error', + 'no-fallthrough': 'warn', + 'no-invalid-this': 'warn', + 'no-new-wrappers': 'warn', + 'no-null/no-null': 'off', + 'no-redeclare': 'off', + 'no-restricted-imports': [ + 'error', + '..', + '../index', + '../..', + '../../index' + ], + 'no-return-await': 'warn', + 'no-sequences': 'error', + 'no-throw-literal': 'error', + 'no-trailing-spaces': 'warn', + 'no-underscore-dangle': 'off', + 'no-unsafe-finally': 'error', + 'no-var': 'error', + 'prefer-const': [ + 'warn', + { + 'destructuring': 'all' + } + ], + 'prefer-object-spread': 'warn', + 'radix': 'warn', + 'spaced-comment': [ + 'warn', + 'always', + { + 'markers': [ + '/' + ], + 'exceptions': [ + '*' + ] + } + ], + 'space-infix-ops': 'warn', + 'use-isnan': 'warn' } -}; \ No newline at end of file +}; diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 73275365..9b532ee1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,5 +22,7 @@ jobs: node-version: '16' - name: Build run: yarn + - name: Lint + run: yarn lint - name: Test run: yarn test diff --git a/configs/.eslintrc.js b/configs/.eslintrc.js deleted file mode 100644 index 620e0aa6..00000000 --- a/configs/.eslintrc.js +++ /dev/null @@ -1,111 +0,0 @@ -module.exports = { - "env": { - "browser": true, - "node": true - }, - "extends": [ - "prettier" - ], - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "tsconfig.json", - "sourceType": "module" - }, - "plugins": [ - "eslint-plugin-no-null", - "@typescript-eslint", - "header" - ], - "rules": { - "@typescript-eslint/indent": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/no-dynamic-delete": "error", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-misused-new": "error", - "@typescript-eslint/no-shadow": [ - "warn", - { - "hoist": "all" - } - ], - "@typescript-eslint/no-unused-expressions": "off", - "@typescript-eslint/semi": [ - "error", - "always" - ], - "@typescript-eslint/type-annotation-spacing": "warn", - "header/header": ["error", "block", [{"pattern": "[\n\r]+ \\* Copyright \\([cC]\\) \\d{4}(-\\d{4})? .*[\n\r]+"}]], - "brace-style": [ - "warn", - "1tbs", - { "allowSingleLine": true } - ], - "comma-dangle": ["warn", { - "arrays": "only-multiline", - "objects": "only-multiline", - }], - "constructor-super": "error", - "curly": "off", - "eol-last": "warn", - "eqeqeq": [ - "warn", - "smart" - ], - "guard-for-in": "warn", - "id-blacklist": "off", - "id-match": "off", - "keyword-spacing": ["warn", { "before": true }], - "max-len": [ - "warn", - { - "code": 180 - } - ], - "no-prototype-builtins": "error", - "no-caller": "error", - "no-console": "off", - "no-debugger": "warn", - "no-eval": "error", - "no-fallthrough": "warn", - "no-invalid-this": "warn", - "no-new-wrappers": "warn", - "no-null/no-null": "off", - "no-redeclare": "off", - "no-restricted-imports": [ - "error", - "..", - "../index", - "../..", - "../../index" - ], - "no-return-await": "warn", - "no-sequences": "error", - "no-throw-literal": "error", - "no-trailing-spaces": "warn", - "no-underscore-dangle": "off", - "no-unsafe-finally": "error", - "no-var": "error", - "prefer-const": [ - "warn", - { - "destructuring": "all" - } - ], - "prefer-object-spread": "warn", - "radix": "warn", - "spaced-comment": [ - "warn", - "always", - { - "markers": [ - "/" - ], - "exceptions": [ - "*" - ] - } - ], - "space-infix-ops": "warn", - "use-isnan": "warn" - } -}; diff --git a/configs/base.tsconfig.json b/configs/base.tsconfig.json deleted file mode 100644 index 375d455e..00000000 --- a/configs/base.tsconfig.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "compilerOptions": { - "target": "ES2017", - "module": "commonjs", - "lib": [ - "ES2017", - "DOM" - ], - "types": [ - "reflect-metadata" - ], - "sourceMap": true, - "declaration": true, - "declarationMap": true, - "noImplicitAny": true, - "noImplicitThis": true, - "noImplicitReturns": true, - "noImplicitOverride": true, - "noUnusedLocals": true, - "strictNullChecks": true, - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "esModuleInterop": true, - "jsx": "react" - } -} \ No newline at end of file diff --git a/examples/tsconfig.json b/examples/tsconfig.json index 341b858d..588d0c6a 100644 --- a/examples/tsconfig.json +++ b/examples/tsconfig.json @@ -1,8 +1,9 @@ { - "extends": "../configs/base.tsconfig.json", + "extends": "../tsconfig.json", "compilerOptions": { "types": [ - "reflect-metadata", "webpack-env" + "reflect-metadata", + "webpack-env" ], "declaration": false, "declarationMap": false @@ -11,6 +12,7 @@ "./server/**/*.ts" ], "exclude": [ - "**/*.spec.ts", "**/*.spec.tsx" + "**/*.spec.ts", + "**/*.spec.tsx" ] } \ No newline at end of file diff --git a/package.json b/package.json index 105c93cf..cbf10118 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "clean": "lerna run clean", "build": "lerna run build", "lint": "eslint {**/src/**/*.ts,**/src/**/*.tsx}", - "lint:fix": "eslint {**/src/**/*.ts,\"**/src/**/!(*.spec.ts*|test-helper.ts)\",**/src/**/*.tsx} --fix", + "lint:fix": "eslint {**/src/**/*.ts,**/src/**/*.tsx} --fix", "test": "vitest run", "coverage": "vitest run --coverage", "publish:prepare": "lerna version --ignore-scripts --yes --no-push", diff --git a/packages/generator-sprotty/tsconfig.json b/packages/generator-sprotty/tsconfig.json index fcd1b7d2..817b3857 100644 --- a/packages/generator-sprotty/tsconfig.json +++ b/packages/generator-sprotty/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../configs/base.tsconfig.json", + "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "app" }, diff --git a/packages/sprotty-elk/tsconfig.json b/packages/sprotty-elk/tsconfig.json index 6f2e210b..c045697f 100644 --- a/packages/sprotty-elk/tsconfig.json +++ b/packages/sprotty-elk/tsconfig.json @@ -1,15 +1,16 @@ { - "extends": "../../configs/base.tsconfig.json", - "compilerOptions": { - "outDir": "lib", - "types": [ - "node" - ] - }, - "include": [ - "src" - ], - "exclude": [ - "**/*.spec.ts", "**/*.spec.tsx" + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "lib", + "types": [ + "node" ] - } \ No newline at end of file + }, + "include": [ + "src" + ], + "exclude": [ + "**/*.spec.ts", + "**/*.spec.tsx" + ] +} \ No newline at end of file diff --git a/packages/sprotty-protocol/tsconfig.json b/packages/sprotty-protocol/tsconfig.json index 4c5de45f..9f98a077 100644 --- a/packages/sprotty-protocol/tsconfig.json +++ b/packages/sprotty-protocol/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../configs/base.tsconfig.json", + "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "lib" }, @@ -7,6 +7,7 @@ "src" ], "exclude": [ - "**/*.spec.ts", "**/*.spec.tsx" + "**/*.spec.ts", + "**/*.spec.tsx" ] } \ No newline at end of file diff --git a/packages/sprotty/tsconfig.json b/packages/sprotty/tsconfig.json index 36b256ae..5d640e7c 100644 --- a/packages/sprotty/tsconfig.json +++ b/packages/sprotty/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../../configs/base.tsconfig.json", + "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "lib" }, @@ -7,6 +7,8 @@ "src" ], "exclude": [ - "**/*.spec.ts", "**/*.spec.tsx", "src/utils/test-helper.ts" + "**/*.spec.ts", + "**/*.spec.tsx", + "src/utils/test-helper.ts" ] } \ No newline at end of file diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json deleted file mode 100644 index 8c1de817..00000000 --- a/tsconfig.eslint.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "extends": "./configs/base.tsconfig.json", - "include": [ - "**/src/**/*.ts", - "**/src/**/*.tsx", - "**/packages/*/*/*.ts", - "**/packages/*/*/*.js", - "*.js", - "*.ts" - ], - "exclude": [ - "lib/**/*", - "node_modules/**/*" - ] -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index e3d00cf1..da1b25e5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,39 @@ { - "extends": "./configs/base.tsconfig.json", + "$schema": "https://json.schemastore.org/tsconfig", + "compilerOptions": { + "target": "ES2017", + "module": "commonjs", + "lib": [ + "ES2017", + "DOM" + ], + "types": [ + "reflect-metadata" + ], + "sourceMap": true, + "declaration": true, + "declarationMap": true, + "noImplicitAny": true, + "noImplicitThis": true, + "noImplicitReturns": true, + "noImplicitOverride": true, + "noUnusedLocals": true, + "strictNullChecks": true, + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "esModuleInterop": true, + "jsx": "react" + }, "include": [ - "packages/*/src/**/*.ts", + "**/src/**/*.ts", + "**/src/**/*.tsx", + "**/packages/*/*/*.ts", + "**/packages/*/*/*.js", + "*.js", + "*.ts" ], + "exclude": [ + "lib/**/*", + "node_modules/**/*" + ] } \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index e42e55b1..1be5b829 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1146,7 +1146,7 @@ "@types/yeoman-environment" "*" "@types/yeoman-generator" "*" -"@typescript-eslint/eslint-plugin@~6.10.0": +"@typescript-eslint/eslint-plugin@^6.10.0": version "6.10.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.10.0.tgz#cfe2bd34e26d2289212946b96ab19dcad64b661a" integrity sha512-uoLj4g2OTL8rfUQVx2AFO1hp/zja1wABJq77P6IclQs6I/m9GLrm7jCdgzZkvWdDCQf1uEvoa8s8CupsgWQgVg== @@ -1163,7 +1163,7 @@ semver "^7.5.4" ts-api-utils "^1.0.1" -"@typescript-eslint/parser@~6.10.0": +"@typescript-eslint/parser@^6.10.0": version "6.10.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-6.10.0.tgz#578af79ae7273193b0b6b61a742a2bc8e02f875a" integrity sha512-+sZwIj+s+io9ozSxIWbNB5873OSdfeBEH/FR0re14WLI6BaKuSOnnwCJ2foUiu8uXf4dRp1UqHP0vrZ1zXGrog== @@ -2615,7 +2615,7 @@ eslint-visitor-keys@^3.3.0, eslint-visitor-keys@^3.4.1, eslint-visitor-keys@^3.4 resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz#0cd72fe8550e3c2eae156a96a4dddcd1c8ac5800" integrity sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag== -eslint@~8.53.0: +eslint@^8.53.0: version "8.53.0" resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.53.0.tgz#14f2c8244298fcae1f46945459577413ba2697ce" integrity sha512-N4VuiPjXDUa4xVeV/GC/RV3hQW9Nw+Y463lkWaKKXKYMvmRiRDAtfpuPFLN+E1/6ZhyR8J2ig+eVREnYgUsiag==