From a51b4e94cda04a0b7b03ed6231b6bf046d2fd5eb Mon Sep 17 00:00:00 2001 From: Lukasz Ostafin Date: Fri, 18 Oct 2024 14:03:05 +0200 Subject: [PATCH 1/4] IBX-9109: Added support for TypeScript --- index.js | 121 +++++++++++++++++++++++++++++---------------------- package.json | 3 ++ 2 files changed, 73 insertions(+), 51 deletions(-) diff --git a/index.js b/index.js index ab94326..dc8b143 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,55 @@ +const baseRules = { + "array-callback-return": "error", + "eol-last": "error", + "no-console": ["error", { allow: ["warn", "error"] }], + "no-duplicate-imports": "error", + "no-else-return": "error", + "no-extra-boolean-cast": "off", + "no-multi-spaces": "error", + "no-multiple-empty-lines": ["error", { "max": 1, "maxBOF": 0, "maxEOF": 0 }], + "no-nested-ternary": "error", + "no-shadow": "error", + "no-template-curly-in-string": "error", + "no-trailing-spaces": "error", + "no-unreachable-loop": "error", + "no-unsafe-optional-chaining": "error", + "no-useless-concat": "error", + "no-var": "error", + "object-curly-spacing": ["error", "always"], + "prefer-const": "error", + "prefer-destructuring": ["error", { + "VariableDeclarator": { + "array": false, + "object": true + }, + "AssignmentExpression": { + "array": false, + "object": false + } + }, { enforceForRenamedProperties: false }], + "prefer-object-spread": "error", + "prefer-template": "error", + "quotes": ["error", "single", { allowTemplateLiterals: true }], + "radix": "error", + "semi-spacing": "error", + "react/button-has-type": "error", + "react/default-props-match-prop-types": "error", + "react/jsx-boolean-value": ["error", "always"], + "react/jsx-closing-bracket-location": "error", + "react/jsx-closing-tag-location": "error", + "react/jsx-curly-spacing": "error", + "react/jsx-equals-spacing": "error", + "react/jsx-first-prop-new-line": "error", + "react/jsx-key": "error", + "react/jsx-no-duplicate-props": "error", + "react/no-array-index-key": "error", + "react/no-typos": "error", + "react/require-default-props": "error", + "react/self-closing-comp": "error", + "react/style-prop-object": "error", +}; + module.exports = { - plugins: ["react"], - extends: ["eslint:recommended", "plugin:react/recommended"], settings: { react: { version: "16.x" @@ -22,54 +71,24 @@ module.exports = { sourceType: "module", ecmaVersion: 12 }, - rules: { - "array-callback-return": "error", - "eol-last": "error", - "no-console": ["error", { allow: ["warn", "error"] }], - "no-duplicate-imports": "error", - "no-else-return": "error", - "no-extra-boolean-cast": "off", - "no-multi-spaces": "error", - "no-multiple-empty-lines": ["error", { "max": 1, "maxBOF": 0, "maxEOF": 0 }], - "no-nested-ternary": "error", - "no-shadow": "error", - "no-template-curly-in-string": "error", - "no-trailing-spaces": "error", - "no-unreachable-loop": "error", - "no-unsafe-optional-chaining": "error", - "no-useless-concat": "error", - "no-var": "error", - "object-curly-spacing": ["error", "always"], - "prefer-const": "error", - "prefer-destructuring": ["error", { - "VariableDeclarator": { - "array": false, - "object": true - }, - "AssignmentExpression": { - "array": false, - "object": false + overrides: [ + { + files: ["*.js"], + plugins: ["react"], + extends: ["eslint:recommended", "plugin:react/recommended"], + rules: baseRules + }, + { + files: ["*.ts", "*.tsx"], + plugins: ["react", "@typescript-eslint"], + extends: ["plugin:@typescript-eslint/recommended"], + rules: { + ...baseRules, + ...{ + "react/style-prop-object": "error", + "react/require-default-props": "off" + } } - }, { enforceForRenamedProperties: false }], - "prefer-object-spread": "error", - "prefer-template": "error", - "quotes": ["error", "single", { allowTemplateLiterals: true }], - "radix": "error", - "semi-spacing": "error", - "react/button-has-type": "error", - "react/default-props-match-prop-types": "error", - "react/jsx-boolean-value": ["error", "always"], - "react/jsx-closing-bracket-location": "error", - "react/jsx-closing-tag-location": "error", - "react/jsx-curly-spacing": "error", - "react/jsx-equals-spacing": "error", - "react/jsx-first-prop-new-line": "error", - "react/jsx-key": "error", - "react/jsx-no-duplicate-props": "error", - "react/no-array-index-key": "error", - "react/no-typos": "error", - "react/require-default-props": "error", - "react/self-closing-comp": "error", - "react/style-prop-object": "error" - } + } + ] }; diff --git a/package.json b/package.json index 4f87b08..e0dee49 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,9 @@ "repository": "git@github.com:ibexa/eslint-config-ibexa.git", "private": true, "dependencies": { + "@typescript-eslint/eslint-plugin": "^8.10.0", + "@typescript-eslint/parser": "^8.10.0", + "typescript": "^5.6.3", "eslint": "8.55", "eslint-plugin-react": "7.33.2", "prettier": "3.1" From deab0597cabe1300e6ee214768e14f1020d0f195 Mon Sep 17 00:00:00 2001 From: Lukasz Ostafin Date: Thu, 21 Nov 2024 09:08:19 +0100 Subject: [PATCH 2/4] After CR --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e0dee49..aefb522 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "repository": "git@github.com:ibexa/eslint-config-ibexa.git", "private": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "^8.10.0", - "@typescript-eslint/parser": "^8.10.0", + "@typescript-eslint/eslint-plugin": "8.10.0", + "@typescript-eslint/parser": "8.10.0", "typescript": "^5.6.3", "eslint": "8.55", "eslint-plugin-react": "7.33.2", From 11926242049cc5094e519f619c33955b79f6a6aa Mon Sep 17 00:00:00 2001 From: Lukasz Ostafin Date: Fri, 29 Nov 2024 16:09:54 +0100 Subject: [PATCH 3/4] After tests --- index.js | 5 ++++- package.json | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index dc8b143..81f0dc1 100644 --- a/index.js +++ b/index.js @@ -80,8 +80,11 @@ module.exports = { }, { files: ["*.ts", "*.tsx"], + parserOptions: { + project: "./tseslint.json", + }, plugins: ["react", "@typescript-eslint"], - extends: ["plugin:@typescript-eslint/recommended"], + extends: ["plugin:@typescript-eslint/recommended-type-checked"], rules: { ...baseRules, ...{ diff --git a/package.json b/package.json index aefb522..1102e92 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "@typescript-eslint/eslint-plugin": "8.10.0", "@typescript-eslint/parser": "8.10.0", - "typescript": "^5.6.3", + "typescript": "5.6.3", "eslint": "8.55", "eslint-plugin-react": "7.33.2", "prettier": "3.1" From 120b7f91d10bd8e7be10c11e1ceafd62e7bd5227 Mon Sep 17 00:00:00 2001 From: Lukasz Ostafin Date: Fri, 29 Nov 2024 21:40:40 +0100 Subject: [PATCH 4/4] Update @typescript-eslint/eslint-plugin version --- index.js | 24 +++++++++++++++++++++--- package.json | 4 ++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 81f0dc1..54ec9bd 100644 --- a/index.js +++ b/index.js @@ -81,13 +81,31 @@ module.exports = { { files: ["*.ts", "*.tsx"], parserOptions: { - project: "./tseslint.json", + project: './tsconfig.eslint.json', }, - plugins: ["react", "@typescript-eslint"], - extends: ["plugin:@typescript-eslint/recommended-type-checked"], + extends: [ + "eslint:recommended", + "plugin:@typescript-eslint/strict-type-checked", + "plugin:@typescript-eslint/stylistic-type-checked" + ], rules: { ...baseRules, ...{ + "@typescript-eslint/no-unsafe-type-assertion": "error", + "@typescript-eslint/no-redundant-type-constituents": "off", + "@typescript-eslint/typedef": [ + "error", + { + "arrayDestructuring": true, + "arrowParameter": true, + "memberVariableDeclaration": true, + "objectDestructuring": true, + "parameter": true, + "propertyDeclaration": true, + "variableDeclaration": false, + "variableDeclarationIgnoreFunction": false, + }, + ], "react/style-prop-object": "error", "react/require-default-props": "off" } diff --git a/package.json b/package.json index 1102e92..86594a0 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,8 @@ "repository": "git@github.com:ibexa/eslint-config-ibexa.git", "private": true, "dependencies": { - "@typescript-eslint/eslint-plugin": "8.10.0", - "@typescript-eslint/parser": "8.10.0", + "@typescript-eslint/eslint-plugin": "8.16.0", + "@typescript-eslint/parser": "8.16.0", "typescript": "5.6.3", "eslint": "8.55", "eslint-plugin-react": "7.33.2",