From 1e3d42c651b7accf2bd6ec42b0728b147313daa7 Mon Sep 17 00:00:00 2001 From: Martin Hochel Date: Thu, 17 Mar 2022 11:08:16 +0100 Subject: [PATCH] create base and base-legacy configs --- .../eslint-plugin/src/configs/base-legacy.js | 18 +++++++++++++ packages/eslint-plugin/src/configs/base.js | 26 +++++++++++++++++++ packages/eslint-plugin/src/configs/core.js | 2 -- .../eslint-plugin/src/configs/node-legacy.js | 7 ++--- packages/eslint-plugin/src/configs/node.js | 2 +- .../eslint-plugin/src/configs/react-legacy.js | 4 +-- packages/eslint-plugin/src/configs/react.js | 11 +------- .../eslint-plugin/src/utils/configHelpers.js | 6 ++--- 8 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 packages/eslint-plugin/src/configs/base-legacy.js create mode 100644 packages/eslint-plugin/src/configs/base.js diff --git a/packages/eslint-plugin/src/configs/base-legacy.js b/packages/eslint-plugin/src/configs/base-legacy.js new file mode 100644 index 00000000000000..5a13ee06174a26 --- /dev/null +++ b/packages/eslint-plugin/src/configs/base-legacy.js @@ -0,0 +1,18 @@ +// @ts-check + +const path = require('path'); + +const { configHelpers } = require('..'); + +/** @type {import("eslint").Linter.Config} */ +module.exports = { + extends: [path.join(__dirname, 'core')], + rules: { + /** + * `@typescript-eslint`plugin eslint rules + * @see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin + */ + ...configHelpers.getNamingConventionRule({ prefixInterface: true }), + }, + overrides: [], +}; diff --git a/packages/eslint-plugin/src/configs/base.js b/packages/eslint-plugin/src/configs/base.js new file mode 100644 index 00000000000000..6cc412483f2565 --- /dev/null +++ b/packages/eslint-plugin/src/configs/base.js @@ -0,0 +1,26 @@ +// @ts-check + +const path = require('path'); + +const { configHelpers } = require('..'); + +/** @type {import("eslint").Linter.Config} */ +module.exports = { + extends: [path.join(__dirname, 'core')], + rules: { + /** + * `@typescript-eslint`plugin eslint rules + * @see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin + */ + ...configHelpers.getNamingConventionRule(), + }, + overrides: [ + { + files: '**/src/index.{ts,tsx,js}', + rules: { + // TODO: propagate to `error` once all packages barrel files have been fixed + '@rnx-kit/no-export-all': ['warn', { expand: 'all' }], + }, + }, + ], +}; diff --git a/packages/eslint-plugin/src/configs/core.js b/packages/eslint-plugin/src/configs/core.js index 6132de446024f8..b6a69150c2b9b3 100644 --- a/packages/eslint-plugin/src/configs/core.js +++ b/packages/eslint-plugin/src/configs/core.js @@ -153,8 +153,6 @@ const config = { * `@typescript-eslint`plugin eslint rules * @see https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin */ - // tslint: function-name, variable-name - ...configHelpers.getNamingConventionRule(false), '@typescript-eslint/no-empty-function': 'error', '@typescript-eslint/no-explicit-any': 'error', '@typescript-eslint/prefer-namespace-keyword': 'error', diff --git a/packages/eslint-plugin/src/configs/node-legacy.js b/packages/eslint-plugin/src/configs/node-legacy.js index 4647efb495880b..8e36520c72c332 100644 --- a/packages/eslint-plugin/src/configs/node-legacy.js +++ b/packages/eslint-plugin/src/configs/node-legacy.js @@ -1,12 +1,9 @@ // @ts-check const path = require('path'); -const configHelpers = require('../utils/configHelpers'); /** @type {import("eslint").Linter.Config} */ module.exports = { - extends: [path.join(__dirname, 'core')], - rules: { - ...configHelpers.getNamingConventionRule(true), - }, + extends: [path.join(__dirname, 'base-legacy')], + rules: {}, }; diff --git a/packages/eslint-plugin/src/configs/node.js b/packages/eslint-plugin/src/configs/node.js index d6e2a305fb4e74..91146bd8764dd4 100644 --- a/packages/eslint-plugin/src/configs/node.js +++ b/packages/eslint-plugin/src/configs/node.js @@ -4,7 +4,7 @@ const path = require('path'); /** @type {import("eslint").Linter.Config} */ module.exports = { - extends: [path.join(__dirname, 'core')], + extends: [path.join(__dirname, 'base')], rules: { 'no-console': 'off', }, diff --git a/packages/eslint-plugin/src/configs/react-legacy.js b/packages/eslint-plugin/src/configs/react-legacy.js index 81bd72331c91cb..a57ab3338e7bf1 100644 --- a/packages/eslint-plugin/src/configs/react-legacy.js +++ b/packages/eslint-plugin/src/configs/react-legacy.js @@ -1,14 +1,12 @@ // @ts-check const path = require('path'); -const configHelpers = require('../utils/configHelpers'); /** @type {import("eslint").Linter.Config} */ module.exports = { - extends: [path.join(__dirname, 'core'), path.join(__dirname, 'react-config')], + extends: [path.join(__dirname, 'base-legacy'), path.join(__dirname, 'react-config')], rules: { - ...configHelpers.getNamingConventionRule(true), 'jsdoc/check-tag-names': 'off', }, }; diff --git a/packages/eslint-plugin/src/configs/react.js b/packages/eslint-plugin/src/configs/react.js index b288515dfdcf56..a50553f8390020 100644 --- a/packages/eslint-plugin/src/configs/react.js +++ b/packages/eslint-plugin/src/configs/react.js @@ -4,15 +4,6 @@ const path = require('path'); /** @type {import("eslint").Linter.Config} */ module.exports = { - extends: [path.join(__dirname, 'core'), path.join(__dirname, 'react-config')], + extends: [path.join(__dirname, 'base'), path.join(__dirname, 'react-config')], rules: {}, - overrides: [ - { - files: '**/src/index.{ts,tsx,js}', - rules: { - // TODO: propagate to `error` once all packages barrel files have been fixed - '@rnx-kit/no-export-all': ['warn', { expand: 'all' }], - }, - }, - ], }; diff --git a/packages/eslint-plugin/src/utils/configHelpers.js b/packages/eslint-plugin/src/utils/configHelpers.js index 95f7ca39cdd874..b287bc7ab95e0e 100644 --- a/packages/eslint-plugin/src/utils/configHelpers.js +++ b/packages/eslint-plugin/src/utils/configHelpers.js @@ -69,10 +69,10 @@ module.exports = { * Returns a rule configuration for [`@typescript-eslint/naming-convention`](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md). * This provides the ability to override *only* the interface rule without having to repeat or * lose the rest of the (very complicated) config. - * @param {boolean} prefixWithI - Whether to prefix interfaces with I + * @param {{prefixInterface: boolean}} config - Whether to prefix interfaces with I * @returns {import("eslint").Linter.RulesRecord} */ - getNamingConventionRule: prefixWithI => ({ + getNamingConventionRule: (config = { prefixInterface: false }) => ({ '@typescript-eslint/naming-convention': [ 'error', { selector: 'function', format: ['camelCase'], leadingUnderscore: 'allow' }, @@ -98,7 +98,7 @@ module.exports = { { selector: 'interface', format: ['PascalCase'], - ...(prefixWithI ? { prefix: ['I'] } : { custom: { regex: '^I[A-Z]', match: false } }), + ...(config.prefixInterface ? { prefix: ['I'] } : { custom: { regex: '^I[A-Z]', match: false } }), }, { selector: 'default',