From db5b3ef050e5f48411801743d365b93d301c8f7d Mon Sep 17 00:00:00 2001 From: strawberry-choco Date: Fri, 11 Oct 2024 13:05:09 +0200 Subject: [PATCH] adjust rules (#241) Signed-off-by: Kangrui Johann Ye --- eslint.config.mjs | 2 + package.json | 2 +- packages/eslint-plugin-angular/package.json | 2 +- packages/eslint-plugin-node/package.json | 2 +- .../src/configs/security.ts | 2 +- packages/eslint-plugin-react/package.json | 2 +- .../eslint-plugin-typescript/package.json | 6 +-- .../eslint-plugin-typescript/src/index.ts | 1 + packages/eslint-plugin-vue/package.json | 2 +- packages/eslint-plugin-vue/src/configs/vue.ts | 41 ++++++++++++++++++- yarn.lock | 19 ++------- 11 files changed, 52 insertions(+), 29 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index a952357..99f1ff1 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -24,7 +24,9 @@ export default tseslint.config( 'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/format.ts', 'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/import.ts', 'packages/eslint-plugin-typescript/src/configs/recommended-typescript/rules/rxjs.ts', + 'packages/eslint-plugin-typescript/src/rules/package/*', 'packages/eslint-plugin-typescript/src/rules/ts-config/*', + 'packages/eslint-plugin-typescript/src/rules/typescript/*.spec.ts', 'scripts/*', '.eslintrc.format.js', 'eslint.config.mjs', diff --git a/package.json b/package.json index f202830..f4c5959 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "private": true, "volta": { "node": "20.12.2", diff --git a/packages/eslint-plugin-angular/package.json b/packages/eslint-plugin-angular/package.json index 83bd6e9..eaf5441 100644 --- a/packages/eslint-plugin-angular/package.json +++ b/packages/eslint-plugin-angular/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin-angular", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "description": "Cloudflight eslint-plugin & eslint-config for angular", "volta": { "extends": "../../package.json" diff --git a/packages/eslint-plugin-node/package.json b/packages/eslint-plugin-node/package.json index 47550cf..97218a8 100644 --- a/packages/eslint-plugin-node/package.json +++ b/packages/eslint-plugin-node/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin-node", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "description": "Cloudflight eslint-plugin & eslint-config for node", "volta": { "extends": "../../package.json" diff --git a/packages/eslint-plugin-node/src/configs/security.ts b/packages/eslint-plugin-node/src/configs/security.ts index a078087..042b04f 100644 --- a/packages/eslint-plugin-node/src/configs/security.ts +++ b/packages/eslint-plugin-node/src/configs/security.ts @@ -13,7 +13,7 @@ function warningEntryToError(value: TSESLint.Linter.RuleEntry): TSESLint.Linter. const level = Array.isArray(value) ? value[0] : value; const updatedLevel = warningLevelToError(level); - return Array.isArray(value) ? [updatedLevel, value.slice(1)] : updatedLevel; + return Array.isArray(value) ? [updatedLevel, ...value.slice(1)] : updatedLevel; } function warningLevelToError(level: TSESLint.Linter.RuleLevel): TSESLint.Linter.RuleLevel { diff --git a/packages/eslint-plugin-react/package.json b/packages/eslint-plugin-react/package.json index 4ecc5f3..193e0aa 100644 --- a/packages/eslint-plugin-react/package.json +++ b/packages/eslint-plugin-react/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin-react", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "description": "Cloudflight eslint-plugin & eslint-config for React", "volta": { "extends": "../../package.json" diff --git a/packages/eslint-plugin-typescript/package.json b/packages/eslint-plugin-typescript/package.json index abfdb77..ea21e06 100644 --- a/packages/eslint-plugin-typescript/package.json +++ b/packages/eslint-plugin-typescript/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin-typescript", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "description": "Cloudflight eslint-plugin & eslint-config for typescript", "volta": { "extends": "../../package.json" @@ -30,10 +30,6 @@ "@eslint/js": "^9.11.1", "@typescript-eslint/eslint-plugin": "^8.8.0", "@typescript-eslint/parser": "^8.8.0", - "eslint-plugin-import": "^2.29.1", - "eslint-plugin-json-es": "^1.6.0", - "eslint-plugin-rxjs": "^5.0.3", - "eslint-plugin-simple-import-sort": "^12.1.0", "typescript-eslint": "^8.8.0" }, "peerDependencies": { diff --git a/packages/eslint-plugin-typescript/src/index.ts b/packages/eslint-plugin-typescript/src/index.ts index ed84838..222b89c 100644 --- a/packages/eslint-plugin-typescript/src/index.ts +++ b/packages/eslint-plugin-typescript/src/index.ts @@ -14,6 +14,7 @@ export const cloudflightTypescriptConfig = tseslint.config( extends: [ pluginJs.configs.recommended, ...tseslint.configs.recommendedTypeChecked, + ...tseslint.configs.strictTypeChecked, ], rules: { ...eslintRules, diff --git a/packages/eslint-plugin-vue/package.json b/packages/eslint-plugin-vue/package.json index 05f43b7..f54320f 100644 --- a/packages/eslint-plugin-vue/package.json +++ b/packages/eslint-plugin-vue/package.json @@ -1,6 +1,6 @@ { "name": "@cloudflight/eslint-plugin-vue", - "version": "1.0.0-rc3", + "version": "1.0.0-rc4", "description": "Cloudflight eslint-plugin & eslint-config for vue", "volta": { "extends": "../../package.json" diff --git a/packages/eslint-plugin-vue/src/configs/vue.ts b/packages/eslint-plugin-vue/src/configs/vue.ts index 135b769..4759d24 100644 --- a/packages/eslint-plugin-vue/src/configs/vue.ts +++ b/packages/eslint-plugin-vue/src/configs/vue.ts @@ -1,8 +1,22 @@ import {TSESLint} from '@typescript-eslint/utils'; +// @ts-expect-error .d.ts file for eslint-plugin-vue has been implemented but not released yet +// if the following line fails to build after updating the version, simply remove this comment +import pluginVue from 'eslint-plugin-vue'; -const htmlIndent = 4; +// .d.ts file for eslint-plugin-vue has been implemented but not released yet, if the +// following line fails to build after updating the version, simply remove this comment +// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/consistent-type-assertions +const recommendedConfigArray = pluginVue.configs['flat/recommended'] as TSESLint.FlatConfig.ConfigArray; +const recommendedRules = recommendedConfigArray + .reduce>((acc, config) => ({...acc, ...config.rules}), {}); +const updatedRules = Object.entries(recommendedRules) + .filter((entry): entry is [string, TSESLint.Linter.RuleEntry] => entry[1] != null) + .map(([key, value]) => [key, warningEntryToError(value)]); export const vueRules: TSESLint.Linter.RulesRecord = { + // yes, we know this works correctly + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions + ...Object.fromEntries(updatedRules) as TSESLint.Linter.RulesRecord, 'vue/block-lang': [ 'error', { @@ -24,7 +38,30 @@ export const vueRules: TSESLint.Linter.RulesRecord = { }, ], 'vue/html-button-has-type': 'error', - 'vue/html-indent': ['error', htmlIndent], 'vue/no-ref-object-destructure': 'error', 'vue/no-undef-properties': 'error', + // disable stylistic rules + 'vue/html-indent': 'off', + 'vue/max-attributes-per-line': 'off', + 'vue/html-self-closing': 'off', + 'vue/singleline-html-element-content-newline': 'off', + 'vue/multiline-html-element-content-newline': 'off', + 'vue/html-closing-bracket-newline': 'off', }; + +function warningEntryToError(value: TSESLint.Linter.RuleEntry): TSESLint.Linter.RuleEntry { + const level = Array.isArray(value) ? value[0] : value; + const updatedLevel = warningLevelToError(level); + + return Array.isArray(value) ? [updatedLevel, ...value.slice(1)] : updatedLevel; +} + +function warningLevelToError(level: TSESLint.Linter.RuleLevel): TSESLint.Linter.RuleLevel { + if (level === 'warn') { + return 'error'; + } else if (level === 1) { + return 'error'; + } + + return level; +} diff --git a/yarn.lock b/yarn.lock index 5a05443..37ede83 100644 --- a/yarn.lock +++ b/yarn.lock @@ -564,10 +564,6 @@ __metadata: "@eslint/js": "npm:^9.11.1" "@typescript-eslint/eslint-plugin": "npm:^8.8.0" "@typescript-eslint/parser": "npm:^8.8.0" - eslint-plugin-import: "npm:^2.29.1" - eslint-plugin-json-es: "npm:^1.6.0" - eslint-plugin-rxjs: "npm:^5.0.3" - eslint-plugin-simple-import-sort: "npm:^12.1.0" typescript: "npm:5.5.4" typescript-eslint: "npm:^8.8.0" peerDependencies: @@ -2914,7 +2910,7 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-import@npm:2.29.1, eslint-plugin-import@npm:^2.29.1": +"eslint-plugin-import@npm:2.29.1": version: 2.29.1 resolution: "eslint-plugin-import@npm:2.29.1" dependencies: @@ -2941,7 +2937,7 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-json-es@npm:1.6.0, eslint-plugin-json-es@npm:^1.6.0": +"eslint-plugin-json-es@npm:1.6.0": version: 1.6.0 resolution: "eslint-plugin-json-es@npm:1.6.0" dependencies: @@ -3043,7 +3039,7 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-rxjs@npm:5.0.3, eslint-plugin-rxjs@npm:^5.0.3": +"eslint-plugin-rxjs@npm:5.0.3": version: 5.0.3 resolution: "eslint-plugin-rxjs@npm:5.0.3" dependencies: @@ -3072,15 +3068,6 @@ __metadata: languageName: node linkType: hard -"eslint-plugin-simple-import-sort@npm:^12.1.0": - version: 12.1.0 - resolution: "eslint-plugin-simple-import-sort@npm:12.1.0" - peerDependencies: - eslint: ">=5.0.0" - checksum: 10c0/11e963683216e190b09bb6834b6978ca71d438d9413c52495e92493b0a68fc10268d7fd5815814496ab02fe7c018e4d5fd82866bf3ed5f95cff69628ca741102 - languageName: node - linkType: hard - "eslint-plugin-vue@npm:9.28.0, eslint-plugin-vue@npm:^9.28.0": version: 9.28.0 resolution: "eslint-plugin-vue@npm:9.28.0"