From 91b25491f56a3606ff5c8eef7eae9d1fd77484fb Mon Sep 17 00:00:00 2001 From: Ulf Gerking Date: Wed, 21 Dec 2022 11:40:20 +0100 Subject: [PATCH 1/6] fix: clear maxCallStackSize exceeded error --- configs/react/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/react/index.js b/configs/react/index.js index 8bcee30..689ac92 100644 --- a/configs/react/index.js +++ b/configs/react/index.js @@ -8,7 +8,7 @@ module.exports = { 'plugin:react/recommended', 'plugin:react-hooks/recommended', 'plugin:react/jsx-runtime', - '@singularit', + '@singularit/eslint-config-typescript', ], settings: { react: { From b47c8a872b64e102c991eacbbdb4285e7e0f6950 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Wed, 21 Dec 2022 13:33:46 +0100 Subject: [PATCH 2/6] fix: release workflow --- .github/workflows/release.yml | 10 +++++----- configs/all/package.json | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8c67487..d9b2415 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,7 +28,7 @@ jobs: - uses: EndBug/add-and-commit@v9 with: default_author: github_actions - message: 'chore(deps): bump @singularit/eslint-config-basic' + message: 'feat(deps): bump @singularit/eslint-config-basic' - name: 🚀 Release @singularit/eslint-config-typescript env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -41,7 +41,7 @@ jobs: - uses: EndBug/add-and-commit@v9 with: default_author: github_actions - message: 'chore(deps): bump @singularit/eslint-config-typescript' + message: 'feat(deps): bump @singularit/eslint-config-typescript' - name: 🚀 Release @singularit/eslint-config-vue env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -54,7 +54,7 @@ jobs: - uses: EndBug/add-and-commit@v9 with: default_author: github_actions - message: 'chore(deps): bump @singularit/eslint-config-vue' + message: 'feat(deps): bump @singularit/eslint-config-vue' - name: 🚀 Release @singularit/eslint-config-react env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -67,7 +67,7 @@ jobs: - uses: EndBug/add-and-commit@v9 with: default_author: github_actions - message: 'chore(deps): bump @singularit/eslint-config-react' + message: 'feat(deps): bump @singularit/eslint-config-react' - name: 🚀 Release @singularit/eslint-config env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -80,4 +80,4 @@ jobs: - uses: EndBug/add-and-commit@v9 with: default_author: github_actions - message: 'chore(deps): bump @singularit/eslint-config' + message: 'feat(deps): bump @singularit/eslint-config' diff --git a/configs/all/package.json b/configs/all/package.json index d0cad45..ccb79fc 100644 --- a/configs/all/package.json +++ b/configs/all/package.json @@ -14,7 +14,8 @@ "singularIT", "vue", "typescript", - "react" + "react", + "javascript" ], "main": "index.js", "files": [ From c44fa09be1bdf412e04155b5855cf3d0848c85ef Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Wed, 21 Dec 2022 13:43:28 +0100 Subject: [PATCH 3/6] fix: `object-property-newline.allowMultiplePropertiesPerLine` should be an object --- configs/basic/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/configs/basic/index.js b/configs/basic/index.js index 8da4047..f4ad762 100644 --- a/configs/basic/index.js +++ b/configs/basic/index.js @@ -256,9 +256,9 @@ module.exports = { balanced: true, }, }], - //consistency - 'array-element-newline':["error", "consistent"], - 'object-property-newline': ['error','allowMultiplePropertiesPerLine'], + // consistency + 'array-element-newline': ['error', 'consistent'], + 'object-property-newline': ['error', {allowMultiplePropertiesPerLine: true}], // best-practice 'array-callback-return': 'error', From c10622b85d4765ee4c9b427b109cd446d77579d2 Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Tue, 3 Jan 2023 13:41:04 +0100 Subject: [PATCH 4/6] fix: potentially fix vue and react bug --- configs/react/index.js | 8 ++++++-- configs/vue/index.js | 7 +++++-- package-lock.json | 23 +++++++++++++++++++++-- package.json | 3 +++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/configs/react/index.js b/configs/react/index.js index 689ac92..9e91267 100644 --- a/configs/react/index.js +++ b/configs/react/index.js @@ -1,4 +1,8 @@ -module.exports = { +const { isPackageExists } = require('local-pkg') + +const react = isPackageExists('react') + +module.exports = react ? { plugins: [ 'react', 'react-hooks', @@ -115,5 +119,5 @@ module.exports = { }, ], }, -} +} : {} diff --git a/configs/vue/index.js b/configs/vue/index.js index 6024ef9..3fa0e1c 100644 --- a/configs/vue/index.js +++ b/configs/vue/index.js @@ -1,4 +1,7 @@ -module.exports = { +const {isPackageExists} = require("local-pkg"); +const vue = isPackageExists('vue') + +module.exports = vue ? { overrides: [ { files: ['*.vue'], @@ -13,4 +16,4 @@ module.exports = { '@singularit/eslint-config-typescript', ], rules: {}, -} +} : {} diff --git a/package-lock.json b/package-lock.json index fda3946..feee8a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,9 @@ "workspaces": [ "configs/*" ], + "dependencies": { + "local-pkg": "^0.4.2" + }, "devDependencies": { "eslint": "^8.16.0", "semantic-release-monorepo": "^7.0.5", @@ -22,7 +25,7 @@ "version": "1.1.1", "license": "MIT", "dependencies": { - "@singularit/eslint-config-react": "^0.0.1", + "@singularit/eslint-config-react": "*", "@singularit/eslint-config-vue": "^1.1.3", "@typescript-eslint/eslint-plugin": "^5.26.0", "@typescript-eslint/parser": "^5.26.0", @@ -3486,6 +3489,17 @@ "node": ">=4" } }, + "node_modules/local-pkg": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.2.tgz", + "integrity": "sha512-mlERgSPrbxU3BP4qBqAvvwlgW4MTg78iwJdGGnv7kibKjWcJksrG3t6LB5lXI93wXRDvG4NpUgJFmTG4T6rdrg==", + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, "node_modules/locate-path": { "version": "2.0.0", "license": "MIT", @@ -8753,7 +8767,7 @@ "@singularit/eslint-config": { "version": "file:configs/all", "requires": { - "@singularit/eslint-config-react": "^0.0.1", + "@singularit/eslint-config-react": "*", "@singularit/eslint-config-vue": "^1.1.3", "@typescript-eslint/eslint-plugin": "^5.26.0", "@typescript-eslint/parser": "^5.26.0", @@ -10586,6 +10600,11 @@ } } }, + "local-pkg": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.2.tgz", + "integrity": "sha512-mlERgSPrbxU3BP4qBqAvvwlgW4MTg78iwJdGGnv7kibKjWcJksrG3t6LB5lXI93wXRDvG4NpUgJFmTG4T6rdrg==" + }, "locate-path": { "version": "2.0.0", "requires": { diff --git a/package.json b/package.json index 1e4142e..e266f01 100644 --- a/package.json +++ b/package.json @@ -29,5 +29,8 @@ }, "publishConfig": { "access": "public" + }, + "dependencies": { + "local-pkg": "^0.4.2" } } From 58cc1e332cb74cb60be46792e94c8d3e71d7389b Mon Sep 17 00:00:00 2001 From: Robin Kehl Date: Tue, 3 Jan 2023 13:57:30 +0100 Subject: [PATCH 5/6] fix: update missing packages --- configs/react/package.json | 3 ++- configs/vue/package.json | 3 ++- package.json | 3 --- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/configs/react/package.json b/configs/react/package.json index 3f598a3..2bc4116 100644 --- a/configs/react/package.json +++ b/configs/react/package.json @@ -26,7 +26,8 @@ "@singularit/eslint-config-typescript": "^1.1.3", "eslint-plugin-react": "^7.30.1", "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-prefer-function-component": "^3.0.0" + "eslint-plugin-react-prefer-function-component": "^3.0.0", + "local-pkg": "^0.4.2" }, "devDependencies": { "eslint": "^8.16.0" diff --git a/configs/vue/package.json b/configs/vue/package.json index 244b949..4c11227 100644 --- a/configs/vue/package.json +++ b/configs/vue/package.json @@ -24,7 +24,8 @@ }, "dependencies": { "@singularit/eslint-config-typescript": "^1.1.3", - "eslint-plugin-vue": "^9.0.1" + "eslint-plugin-vue": "^9.0.1", + "local-pkg": "^0.4.2" }, "devDependencies": { "eslint": "^8.16.0" diff --git a/package.json b/package.json index e266f01..1e4142e 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,5 @@ }, "publishConfig": { "access": "public" - }, - "dependencies": { - "local-pkg": "^0.4.2" } } From 404fc98029d32accd9947dd8607037bfe89bb66e Mon Sep 17 00:00:00 2001 From: Ulf Gerking Date: Wed, 4 Jan 2023 16:56:56 +0100 Subject: [PATCH 6/6] fix(react): apply react rules only in tsx and jsx --- configs/react/index.js | 171 +++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 84 deletions(-) diff --git a/configs/react/index.js b/configs/react/index.js index 9e91267..b65c87c 100644 --- a/configs/react/index.js +++ b/configs/react/index.js @@ -34,90 +34,93 @@ module.exports = react ? { }], }, }, - ], - rules: { - // general react rules - 'react-prefer-function-component/react-prefer-function-component': 'error', // Forbid use of class components - 'react/no-array-index-key': 'warn', // Using index as key can lead to unnecessary rerenders - 'react/no-danger': 'error', // Prevent usage of dangerouslySetInnerHTML - 'react/no-invalid-html-attribute': 'error', // Forbid attribute with invalid value - 'react/no-multi-comp': 'warn', // Enforce proper code splitting - 'react/no-namespace': 'error', // Prevent usage of the namespaces - 'react/no-unstable-nested-components': 'error', // Prevent usage of unstable nested components - 'react/no-unused-prop-types': 'error', // Prevent unused prop types - 'react/forbid-component-props': 'warn', // No custom component should use html attributes - 'react/self-closing-comp': 'error', // Prevent extra closing tags for components without children - 'react/void-dom-elements-no-children': 'error', // Prevent passing of children to void DOM elements - // FC specific rules - 'react-hooks/exhaustive-deps': 'warn', // Validate the list of dependencies used by hooks - 'react-hooks/rules-of-hooks': 'error', // Enforces rules of Hooks (see https://reactjs.org/docs/hooks-rules.html) - 'react/hook-use-state': 'error', // Ensure symmetric naming of useState hook value and setter - 'react/function-component-definition': [ // Enforce arrow function components - 'error', - { - namedComponents: ['arrow-function'], - unnamedComponents: ['arrow-function'], - }, - ], - // CC specific rules - 'react/no-access-state-in-setstate': 'warn', // Prevent access to this.state in setState - 'react/no-arrow-function-lifecycle': 'error', // Prevent arrow functions in component lifecycle methods - 'react/no-did-mount-set-state': 'error', // Prevent usage of setState in componentDidMount - 'react/no-did-update-set-state': 'error', // Prevent usage of setState in componentDidUpdate - 'react/no-will-update-set-state': 'error', // Prevent usage of setState in componentWillUpdate - 'react/no-redundant-should-component-update': 'error', // Prevent usage of shouldComponentUpdate when extending React.PureComponent - 'react/no-unsafe': 'error', // Prevent usage of unsafe lifecycle methods - 'react/no-unused-class-component-methods': 'error', // Prevent unused methods in CC - 'react/no-unused-state': 'error', // Prevent unused state variables - 'react/prefer-es6-class': ['error', 'always'], // Prefer ES6 class over React.createClass - 'react/sort-comp': 'error', // Enforce sorted methods in class components - // JSX specific rules - 'jsx-quotes': ['error', 'prefer-double'], - 'react/jsx-boolean-value': 'error', // Enforce boolean attributes notation in JSX - 'react/jsx-closing-bracket-location': 'error', // Validate closing bracket location in JSX - 'react/jsx-closing-tag-location': 'error', // Validate closing tag location for multiline JSX - 'react/jsx-first-prop-new-line': ['error', 'multiline'], // Ensure proper position of the first property in JSX - 'react/jsx-fragments': 'error', // Enforce fragment shorthand syntax - 'react/jsx-indent': ['error', 2], // Enforce consistent 2-space indentation in JSX - 'react/jsx-indent-props': ['error', 2], // Enforce consistent 2-space indentation for props in JSX - 'react/jsx-max-props-per-line': [ // Enforce a maximum of three props per line in JSX - 'error', - { - maximum: 3, - }, - ], - 'react/jsx-no-constructed-context-values': 'error', // Prevents JSX context provider values from taking values that will cause needless rerenders - 'react/jsx-no-leaked-render': [ // Prevent problematic leaked values from being rendered - 'error', - { - validStrategies: [ - 'coerce', - 'ternary', + { + files: ['*.tsx', '*.jsx'], + rules: { + // general react rules + 'react-prefer-function-component/react-prefer-function-component': 'error', // Forbid use of class components + 'react/no-array-index-key': 'warn', // Using index as key can lead to unnecessary rerenders + 'react/no-danger': 'error', // Prevent usage of dangerouslySetInnerHTML + 'react/no-invalid-html-attribute': 'error', // Forbid attribute with invalid value + 'react/no-multi-comp': 'warn', // Enforce proper code splitting + 'react/no-namespace': 'error', // Prevent usage of the namespaces + 'react/no-unstable-nested-components': 'error', // Prevent usage of unstable nested components + 'react/no-unused-prop-types': 'error', // Prevent unused prop types + 'react/forbid-component-props': 'warn', // No custom component should use html attributes + 'react/self-closing-comp': 'error', // Prevent extra closing tags for components without children + 'react/void-dom-elements-no-children': 'error', // Prevent passing of children to void DOM elements + // FC specific rules + 'react-hooks/exhaustive-deps': 'warn', // Validate the list of dependencies used by hooks + 'react-hooks/rules-of-hooks': 'error', // Enforces rules of Hooks (see https://reactjs.org/docs/hooks-rules.html) + 'react/hook-use-state': 'error', // Ensure symmetric naming of useState hook value and setter + 'react/function-component-definition': [ // Enforce arrow function components + 'error', + { + namedComponents: ['arrow-function'], + unnamedComponents: ['arrow-function'], + }, ], - }, - ], - 'react/jsx-no-useless-fragment': 'error', // Prevent unnecessary JSX fragments - 'react/jsx-pascal-case': 'error', // Enforce PascalCase for custom JSX components - 'react/jsx-props-no-multi-spaces': 'error', // Prevent multiple spaces between JSX props - 'react/jsx-tag-spacing': [ // Enforce consistent spacing between tags and their attributes - 'error', - { - beforeClosing: 'never', - beforeSelfClosing: 'always', - }, - ], - 'react/jsx-wrap-multilines': [ // Enforce consistent wrap of multiline JSX - 'error', - { - declaration: 'parens-new-line', - assignment: 'parens-new-line', - return: 'parens-new-line', - arrow: 'parens-new-line', - condition: 'parens-new-line', - logical: 'parens-new-line', - prop: 'parens-new-line', - }, - ], - }, + // CC specific rules + 'react/no-access-state-in-setstate': 'warn', // Prevent access to this.state in setState + 'react/no-arrow-function-lifecycle': 'error', // Prevent arrow functions in component lifecycle methods + 'react/no-did-mount-set-state': 'error', // Prevent usage of setState in componentDidMount + 'react/no-did-update-set-state': 'error', // Prevent usage of setState in componentDidUpdate + 'react/no-will-update-set-state': 'error', // Prevent usage of setState in componentWillUpdate + 'react/no-redundant-should-component-update': 'error', // Prevent usage of shouldComponentUpdate when extending React.PureComponent + 'react/no-unsafe': 'error', // Prevent usage of unsafe lifecycle methods + 'react/no-unused-class-component-methods': 'error', // Prevent unused methods in CC + 'react/no-unused-state': 'error', // Prevent unused state variables + 'react/prefer-es6-class': ['error', 'always'], // Prefer ES6 class over React.createClass + 'react/sort-comp': 'error', // Enforce sorted methods in class components + // JSX specific rules + 'jsx-quotes': ['error', 'prefer-double'], + 'react/jsx-boolean-value': 'error', // Enforce boolean attributes notation in JSX + 'react/jsx-closing-bracket-location': 'error', // Validate closing bracket location in JSX + 'react/jsx-closing-tag-location': 'error', // Validate closing tag location for multiline JSX + 'react/jsx-first-prop-new-line': ['error', 'multiline'], // Ensure proper position of the first property in JSX + 'react/jsx-fragments': 'error', // Enforce fragment shorthand syntax + 'react/jsx-indent': ['error', 2], // Enforce consistent 2-space indentation in JSX + 'react/jsx-indent-props': ['error', 2], // Enforce consistent 2-space indentation for props in JSX + 'react/jsx-max-props-per-line': [ // Enforce a maximum of three props per line in JSX + 'error', + { + maximum: 3, + }, + ], + 'react/jsx-no-constructed-context-values': 'error', // Prevents JSX context provider values from taking values that will cause needless rerenders + 'react/jsx-no-leaked-render': [ // Prevent problematic leaked values from being rendered + 'error', + { + validStrategies: [ + 'coerce', + 'ternary', + ], + }, + ], + 'react/jsx-no-useless-fragment': 'error', // Prevent unnecessary JSX fragments + 'react/jsx-pascal-case': 'error', // Enforce PascalCase for custom JSX components + 'react/jsx-props-no-multi-spaces': 'error', // Prevent multiple spaces between JSX props + 'react/jsx-tag-spacing': [ // Enforce consistent spacing between tags and their attributes + 'error', + { + beforeClosing: 'never', + beforeSelfClosing: 'always', + }, + ], + 'react/jsx-wrap-multilines': [ // Enforce consistent wrap of multiline JSX + 'error', + { + declaration: 'parens-new-line', + assignment: 'parens-new-line', + return: 'parens-new-line', + arrow: 'parens-new-line', + condition: 'parens-new-line', + logical: 'parens-new-line', + prop: 'parens-new-line', + }, + ], + } + } + ], } : {}