Skip to content

Commit

Permalink
create base and base-legacy configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Hotell committed Mar 17, 2022
1 parent 3a5eceb commit 1e3d42c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 24 deletions.
18 changes: 18 additions & 0 deletions packages/eslint-plugin/src/configs/base-legacy.js
Original file line number Diff line number Diff line change
@@ -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: [],
};
26 changes: 26 additions & 0 deletions packages/eslint-plugin/src/configs/base.js
Original file line number Diff line number Diff line change
@@ -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' }],
},
},
],
};
2 changes: 0 additions & 2 deletions packages/eslint-plugin/src/configs/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 2 additions & 5 deletions packages/eslint-plugin/src/configs/node-legacy.js
Original file line number Diff line number Diff line change
@@ -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: {},
};
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/configs/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
4 changes: 1 addition & 3 deletions packages/eslint-plugin/src/configs/react-legacy.js
Original file line number Diff line number Diff line change
@@ -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',
},
};
11 changes: 1 addition & 10 deletions packages/eslint-plugin/src/configs/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }],
},
},
],
};
6 changes: 3 additions & 3 deletions packages/eslint-plugin/src/utils/configHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -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',
Expand Down

0 comments on commit 1e3d42c

Please sign in to comment.