From 407432aa02de692c2d5b9f5ed20f771b3a3da948 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Thu, 12 Aug 2021 18:01:54 -0400 Subject: [PATCH] adds eslint-config-helpers (#3912) --- .eslintrc.js | 144 ++++++++++++---------- package-lock.json | 6 + package.json | 1 + packages/insomnia-app/.eslintrc.js | 14 ++- packages/insomnia-components/.eslintrc.js | 4 +- packages/insomnia-importers/.eslintrc.js | 6 +- packages/insomnia-inso/.eslintrc.js | 4 +- packages/insomnia-prettify/.eslintrc.js | 4 +- packages/insomnia-smoke-test/.eslintrc.js | 4 +- packages/insomnia-testing/.eslintrc.js | 4 +- packages/insomnia-url/.eslintrc.js | 4 +- packages/openapi-2-kong/.eslintrc.js | 8 +- 12 files changed, 119 insertions(+), 84 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f34904c78..cf8285406 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,3 +1,13 @@ +const { + ERROR, + OFF, + SUCCESSOR, + TYPESCRIPT_CONVERSION, + TYPESCRIPT_EXTENSION, + UNKNOWN, + WARN, +} = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { parser: '@typescript-eslint/parser', @@ -50,44 +60,44 @@ module.exports = { { files: ['*.js'], rules: { - '@typescript-eslint/no-var-requires': 'off', + '@typescript-eslint/no-var-requires': OFF(UNKNOWN), }, }, ], rules: { - 'array-bracket-spacing': 'error', - 'brace-style': 'off', // successor('@typescript-eslint/brace-style') - 'camelcase': ['error', { allow: ['__export_format', '__export_date', '__export_source'] }], - 'comma-dangle': ['error', 'always-multiline'], - 'comma-spacing': 'error', - 'consistent-return': 'warn', - 'default-case': 'error', - 'default-case-last': 'error', - 'filenames/match-exported': ['error', 'kebab'], - 'indent': ['error', 2, { SwitchCase: 1 }], - 'eol-last': ['error', 'always'], - 'eqeqeq': ['error', 'smart'], - 'arrow-parens': ['error', 'as-needed'], - 'arrow-spacing': 'error', - 'keyword-spacing': 'off', // successor('@typescript-eslint/keyword-spacing') - 'no-async-promise-executor': 'off', - 'no-case-declarations': 'off', - 'no-duplicate-imports': 'off', - 'no-prototype-builtins': 'off', - 'no-redeclare': 'off', - 'no-unused-vars': 'off', - 'no-use-before-define': 'off', - 'no-var': 'error', - 'no-trailing-spaces': 'error', - 'no-multiple-empty-lines': ['error', { 'max': 1, 'maxEOF': 0 }], - 'object-curly-spacing': ['error', 'always'], - 'quotes': 'off', - 'semi': ['error', 'always'], - 'space-before-function-paren': ['error', { anonymous: 'never', named: 'never', asyncArrow: 'always' }], - 'space-infix-ops': 'off', // successor('@typescript-eslint/space-infix-ops') - 'space-unary-ops': 'error', - 'space-in-parens': 'error', - 'spaced-comment': ['error', 'always', { + 'array-bracket-spacing': ERROR, + 'brace-style': SUCCESSOR(TYPESCRIPT_EXTENSION), + 'camelcase': [ERROR, { allow: ['__export_format', '__export_date', '__export_source'] }], + 'comma-dangle': [ERROR, 'always-multiline'], + 'comma-spacing': ERROR, + 'consistent-return': WARN(UNKNOWN), + 'default-case': ERROR, + 'default-case-last': ERROR, + 'filenames/match-exported': [ERROR, 'kebab'], + 'indent': [ERROR, 2, { SwitchCase: 1 }], + 'eol-last': [ERROR, 'always'], + 'eqeqeq': [ERROR, 'smart'], + 'arrow-parens': [ERROR, 'as-needed'], + 'arrow-spacing': ERROR, + 'keyword-spacing': SUCCESSOR(TYPESCRIPT_EXTENSION), + 'no-async-promise-executor': OFF(UNKNOWN), + 'no-case-declarations': OFF(UNKNOWN), + 'no-duplicate-imports': OFF(UNKNOWN), + 'no-prototype-builtins': OFF(UNKNOWN), + 'no-redeclare': OFF(UNKNOWN), + 'no-unused-vars': OFF(UNKNOWN), + 'no-use-before-define': OFF(UNKNOWN), + 'no-var': ERROR, + 'no-trailing-spaces': ERROR, + 'no-multiple-empty-lines': [ERROR, { 'max': 1, 'maxEOF': 0 }], + 'object-curly-spacing': [ERROR, 'always'], + 'quotes': OFF(UNKNOWN), + 'semi': [ERROR, 'always'], + 'space-before-function-paren': [ERROR, { anonymous: 'never', named: 'never', asyncArrow: 'always' }], + 'space-infix-ops': SUCCESSOR(TYPESCRIPT_EXTENSION), + 'space-unary-ops': ERROR, + 'space-in-parens': ERROR, + 'spaced-comment': [ERROR, 'always', { exceptions: ['/', '*', '-', '* '], // for ASCII art :) markers: [ '/', // for TypeScript directives, doxygen, vsdoc, etc. (which use `///`) @@ -95,48 +105,48 @@ module.exports = { ], }], - 'filenames/match-exported': ['error', 'kebab'], + 'filenames/match-exported': [ERROR, 'kebab'], - 'react/no-find-dom-node': 'off', - 'react/no-unescaped-entities': 'off', // TSCONVERSION - 'react/jsx-first-prop-new-line': ['error', 'multiline'], - 'react/jsx-max-props-per-line': ['error', { maximum: 1, when: 'multiline' }], - 'react/jsx-uses-react': 'error', - 'react/jsx-uses-vars': 'error', - 'react/jsx-indent': ['error', 2], - 'react/jsx-indent-props': ['error', 2], - 'react/prop-types': 'off', - 'react/function-component-definition': ['error', { + 'react/no-find-dom-node': OFF(UNKNOWN), + 'react/no-unescaped-entities': OFF(TYPESCRIPT_CONVERSION), + 'react/jsx-first-prop-new-line': [ERROR, 'multiline'], + 'react/jsx-max-props-per-line': [ERROR, { maximum: 1, when: 'multiline' }], + 'react/jsx-uses-react': ERROR, + 'react/jsx-uses-vars': ERROR, + 'react/jsx-indent': [ERROR, 2], + 'react/jsx-indent-props': [ERROR, 2], + 'react/prop-types': OFF(UNKNOWN), + 'react/function-component-definition': [ERROR, { 'namedComponents': 'arrow-function', 'unnamedComponents': 'arrow-function', }], - 'react/jsx-max-props-per-line': ['error', { 'maximum': 1, 'when': 'multiline' }], - 'react/jsx-closing-bracket-location': ['error', 'line-aligned'], - 'react/prefer-stateless-function': 'warn', // TODO: fix this and change to error - 'react/jsx-key': ['error', { 'checkFragmentShorthand': true }], - 'react/no-array-index-key': 'warn', - 'react/self-closing-comp': 'error', + 'react/jsx-max-props-per-line': [ERROR, { 'maximum': 1, 'when': 'multiline' }], + 'react/jsx-closing-bracket-location': [ERROR, 'line-aligned'], + 'react/prefer-stateless-function': WARN(UNKNOWN), // TODO: fix this and change to error + 'react/jsx-key': [ERROR, { 'checkFragmentShorthand': true }], + 'react/no-array-index-key': WARN(UNKNOWN), + 'react/self-closing-comp': ERROR, - 'react-hooks/exhaustive-deps': ['error', { + 'react-hooks/exhaustive-deps': [ERROR, { // From react-use https://github.com/streamich/react-use/issues/1703#issuecomment-770972824 'additionalHooks': '^use(Async|AsyncFn|AsyncRetry|Debounce|UpdateEffect|IsomorphicLayoutEffect|DeepCompareEffect|ShallowCompareEffect)$', }], - 'react-hooks/rules-of-hooks': 'error', + 'react-hooks/rules-of-hooks': ERROR, - '@typescript-eslint/array-type': ['error', { default: 'array', readonly: 'array' }], - '@typescript-eslint/ban-types': 'off', - '@typescript-eslint/brace-style': ['error', '1tbs', { 'allowSingleLine': true }], - '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], - '@typescript-eslint/explicit-module-boundary-types': 'off', - '@typescript-eslint/keyword-spacing': 'error', - '@typescript-eslint/no-empty-function': 'off', - '@typescript-eslint/no-namespace': ['error', { allowDeclarations: true }], - '@typescript-eslint/no-redeclare': 'error', - '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }], - '@typescript-eslint/no-use-before-define': 'error', - '@typescript-eslint/space-infix-ops': 'error', - '@typescript-eslint/quotes': ['error', 'single', { avoidEscape: true }], + '@typescript-eslint/array-type': [ERROR, { default: 'array', readonly: 'array' }], + '@typescript-eslint/ban-types': OFF(UNKNOWN), + '@typescript-eslint/brace-style': [ERROR, '1tbs', { 'allowSingleLine': true }], + '@typescript-eslint/consistent-type-definitions': [ERROR, 'interface'], + '@typescript-eslint/explicit-module-boundary-types': OFF(UNKNOWN), + '@typescript-eslint/keyword-spacing': ERROR, + '@typescript-eslint/no-empty-function': OFF(UNKNOWN), + '@typescript-eslint/no-namespace': [ERROR, { allowDeclarations: true }], + '@typescript-eslint/no-redeclare': ERROR, + '@typescript-eslint/no-unused-vars': [ERROR, { ignoreRestSiblings: true }], + '@typescript-eslint/no-use-before-define': ERROR, + '@typescript-eslint/space-infix-ops': ERROR, + '@typescript-eslint/quotes': [ERROR, 'single', { avoidEscape: true }], - 'simple-import-sort/imports': 'error', + 'simple-import-sort/imports': ERROR, }, }; diff --git a/package-lock.json b/package-lock.json index f9bf9507a..1560e28ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7614,6 +7614,12 @@ } } }, + "eslint-config-helpers": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-helpers/-/eslint-config-helpers-1.1.0.tgz", + "integrity": "sha512-CquyZ9thHewhoEsGP9Ty3szu/Jx2Dg+U7yOY2Se6fuu0GwGtdP4jpZnwcSekeGcz6C3Iknk9QnROGoCCDABJwg==", + "dev": true + }, "eslint-import-resolver-node": { "version": "0.3.4", "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.4.tgz", diff --git a/package.json b/package.json index ba53ef8eb..4252443a7 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "babel-plugin-styled-components": "^1.12.0", "cross-env": "^7.0.2", "eslint": "^7.29.0", + "eslint-config-helpers": "^1.1.0", "eslint-plugin-filenames": "^1.3.2", "eslint-plugin-html": "^6.1.2", "eslint-plugin-import": "^2.23.4", diff --git a/packages/insomnia-app/.eslintrc.js b/packages/insomnia-app/.eslintrc.js index ccb92ad29..1ddc30388 100644 --- a/packages/insomnia-app/.eslintrc.js +++ b/packages/insomnia-app/.eslintrc.js @@ -1,3 +1,5 @@ +const { ERROR, OFF, UNKNOWN, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', @@ -7,12 +9,12 @@ module.exports = { }, }, rules: { - 'filenames/match-exported': 'off', - camelcase: 'off', - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION - '@typescript-eslint/no-explicit-any': 'off', // TSCONVERSION - 'react/no-find-dom-node': 'off', - 'no-restricted-properties': ['error', { + 'filenames/match-exported': OFF(UNKNOWN), + camelcase: OFF(UNKNOWN), + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), + '@typescript-eslint/no-explicit-any': OFF(TYPESCRIPT_CONVERSION), + 'react/no-find-dom-node': OFF(UNKNOWN), + 'no-restricted-properties': [ERROR, { property: 'openExternal', message: 'use the `clickLink` function in `electron-helpers.ts` instead. see https://security.stackexchange.com/questions/225799/dangers-of-electrons-shell-openexternal-on-untrusted-content for more information.', }], diff --git a/packages/insomnia-components/.eslintrc.js b/packages/insomnia-components/.eslintrc.js index 7c1232643..766a57587 100644 --- a/packages/insomnia-components/.eslintrc.js +++ b/packages/insomnia-components/.eslintrc.js @@ -1,3 +1,5 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', @@ -7,6 +9,6 @@ module.exports = { }, }, rules: { - '@typescript-eslint/no-explicit-any': 'off', // TSCONVERSION + '@typescript-eslint/no-explicit-any': OFF(TYPESCRIPT_CONVERSION), }, }; diff --git a/packages/insomnia-importers/.eslintrc.js b/packages/insomnia-importers/.eslintrc.js index c5d1c094f..d4874c808 100644 --- a/packages/insomnia-importers/.eslintrc.js +++ b/packages/insomnia-importers/.eslintrc.js @@ -1,8 +1,10 @@ +const { ERROR, OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION - camelcase: ['error', { allow: ['__export_format', '__export_date', '__export_source', '_postman_variable_scope'] }], + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), + camelcase: [ERROR, { allow: ['__export_format', '__export_date', '__export_source', '_postman_variable_scope'] }], }, }; diff --git a/packages/insomnia-inso/.eslintrc.js b/packages/insomnia-inso/.eslintrc.js index 17427cb1b..fb49abcdc 100644 --- a/packages/insomnia-inso/.eslintrc.js +++ b/packages/insomnia-inso/.eslintrc.js @@ -1,7 +1,9 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), }, }; diff --git a/packages/insomnia-prettify/.eslintrc.js b/packages/insomnia-prettify/.eslintrc.js index 17427cb1b..fb49abcdc 100644 --- a/packages/insomnia-prettify/.eslintrc.js +++ b/packages/insomnia-prettify/.eslintrc.js @@ -1,7 +1,9 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), }, }; diff --git a/packages/insomnia-smoke-test/.eslintrc.js b/packages/insomnia-smoke-test/.eslintrc.js index 17427cb1b..fb49abcdc 100644 --- a/packages/insomnia-smoke-test/.eslintrc.js +++ b/packages/insomnia-smoke-test/.eslintrc.js @@ -1,7 +1,9 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), }, }; diff --git a/packages/insomnia-testing/.eslintrc.js b/packages/insomnia-testing/.eslintrc.js index 17427cb1b..fb49abcdc 100644 --- a/packages/insomnia-testing/.eslintrc.js +++ b/packages/insomnia-testing/.eslintrc.js @@ -1,7 +1,9 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), }, }; diff --git a/packages/insomnia-url/.eslintrc.js b/packages/insomnia-url/.eslintrc.js index 17427cb1b..fb49abcdc 100644 --- a/packages/insomnia-url/.eslintrc.js +++ b/packages/insomnia-url/.eslintrc.js @@ -1,7 +1,9 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), }, }; diff --git a/packages/openapi-2-kong/.eslintrc.js b/packages/openapi-2-kong/.eslintrc.js index aec693fc8..090dd4e5a 100644 --- a/packages/openapi-2-kong/.eslintrc.js +++ b/packages/openapi-2-kong/.eslintrc.js @@ -1,10 +1,12 @@ +const { OFF, TYPESCRIPT_CONVERSION } = require('eslint-config-helpers'); + /** @type { import('eslint').Linter.Config } */ module.exports = { extends: '../../.eslintrc.js', rules: { camelcase: 'off', - '@typescript-eslint/no-explicit-any': 'off', // TSCONVERSION - '@typescript-eslint/no-empty-interface': 'off', // TSCONVERSION - '@typescript-eslint/no-use-before-define': 'off', // TSCONVERSION + '@typescript-eslint/no-explicit-any': OFF(TYPESCRIPT_CONVERSION), + '@typescript-eslint/no-empty-interface': OFF(TYPESCRIPT_CONVERSION), + '@typescript-eslint/no-use-before-define': OFF(TYPESCRIPT_CONVERSION), }, };