-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: expose used plugins and automatic inference used plugins
this allows users to easier customize based on our presets BREAKING CHANGE: renamed `utils.config()` to `utils.defineConfig()`
- Loading branch information
1 parent
20df425
commit 42d16db
Showing
13 changed files
with
145 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
change/@rightcapital-eslint-config-6c337893-976b-4e96-b2b9-ec4077713318.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"comment": "feat!: expose used plugins and automatic inference used plugins", | ||
"type": "major", | ||
"packageName": "@rightcapital/eslint-config", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,12 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import eslintPluginLodash from 'eslint-plugin-lodash'; | ||
import eslintPluginUnicorn from 'eslint-plugin-unicorn'; | ||
|
||
import { pickPlugins } from '../../utils.js'; | ||
|
||
// extracted from [email protected] | ||
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-base-v15.0.0/packages/eslint-config-airbnb-base/rules/best-practices.js | ||
const config: TSESLint.FlatConfig.ConfigArray = [ | ||
{ | ||
plugins: { | ||
lodash: eslintPluginLodash, | ||
unicorn: eslintPluginUnicorn, | ||
}, | ||
plugins: pickPlugins(['lodash', 'unicorn']), | ||
rules: { | ||
// enforces return statements in callbacks of array's methods | ||
// https://eslint.org/docs/rules/array-callback-return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'; | ||
|
||
import eslintPluginImportX from '../../plugins/eslint-plugin-import-x.js'; | ||
import { pickPlugins } from '../../utils.js'; | ||
|
||
// extracted from [email protected] | ||
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-base-v15.0.0/packages/eslint-config-airbnb-base/rules/imports.js | ||
const config: TSESLint.FlatConfig.ConfigArray = [ | ||
{ | ||
plugins: { | ||
'import-x': eslintPluginImportX, | ||
'simple-import-sort': eslintPluginSimpleImportSort, | ||
}, | ||
plugins: pickPlugins(['import-x', 'simple-import-sort']), | ||
|
||
rules: { | ||
// Static analysis: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import eslintPluginStylistic from '@stylistic/eslint-plugin'; | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
|
||
import { pickPlugins } from '../../utils.js'; | ||
|
||
// extracted from [email protected] | ||
// https://github.com/airbnb/javascript/blob/eslint-config-airbnb-base-v15.0.0/packages/eslint-config-airbnb-base/rules/style.js | ||
const config: TSESLint.FlatConfig.ConfigArray = [ | ||
{ | ||
plugins: { | ||
'@stylistic': eslintPluginStylistic as TSESLint.FlatConfig.Plugin, | ||
}, | ||
plugins: pickPlugins(['@stylistic']), | ||
|
||
rules: { | ||
// require camel case names | ||
camelcase: ['error', { properties: 'never', ignoreDestructuring: false }], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import eslintPluginReact from '@eslint-react/eslint-plugin'; | ||
import eslintPluginRightcapital from '@rightcapital/eslint-plugin'; | ||
import eslintPluginStylistic from '@stylistic/eslint-plugin'; | ||
import type { TSESLint } from '@typescript-eslint/utils'; | ||
import eslintPluginA11y from 'eslint-plugin-jsx-a11y'; | ||
import eslintPluginLodash from 'eslint-plugin-lodash'; | ||
import n from 'eslint-plugin-n'; | ||
import eslintPluginSimpleImportSort from 'eslint-plugin-simple-import-sort'; | ||
import eslintPluginUnicorn from 'eslint-plugin-unicorn'; | ||
import * as typescriptEslint from 'typescript-eslint'; | ||
|
||
import eslintPluginImportX from './eslint-plugin-import-x.js'; | ||
import eslintPluginReactHooks from './eslint-plugin-react-hooks.js'; | ||
|
||
/** | ||
* All plugins used in `@rightcapital/eslint-config`. | ||
*/ | ||
export const plugins = { | ||
'@typescript-eslint': typescriptEslint.plugin, | ||
'@rightcapital': eslintPluginRightcapital, | ||
'import-x': eslintPluginImportX, | ||
'simple-import-sort': eslintPluginSimpleImportSort, | ||
n, | ||
...eslintPluginReact.configs.all.plugins, | ||
'@stylistic': eslintPluginStylistic as TSESLint.FlatConfig.Plugin, | ||
'react-hooks': eslintPluginReactHooks, | ||
'jsx-a11y': eslintPluginA11y, | ||
lodash: eslintPluginLodash, | ||
unicorn: eslintPluginUnicorn, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import globals from 'globals'; | ||
import tseslint from 'typescript-eslint'; | ||
|
||
import { plugins } from './plugins/index.js'; | ||
|
||
/** | ||
* Generate a plugins object from a list of ESLint plugin names | ||
* (Only plugins that are known to `@rightcapital/eslint-config`). | ||
* | ||
* @see {@link plugins} for the list of plugins. | ||
*/ | ||
export function pickPlugins(pluginNames?: Array<keyof typeof plugins>) { | ||
if (!pluginNames) { | ||
return plugins; | ||
} | ||
|
||
return Object.fromEntries( | ||
pluginNames.map((pluginName) => [pluginName, plugins[pluginName]]), | ||
); | ||
} | ||
|
||
const defineConfig: typeof tseslint.config = (...configs) => | ||
tseslint.config(...configs).map((config) => { | ||
const knownPluginNames = Object.keys(plugins).filter((pluginName) => | ||
Object.keys(config.rules ?? {}).some((rule) => | ||
rule.startsWith(`${pluginName}/`), | ||
), | ||
) as Array<keyof typeof plugins>; | ||
const resolvedPlugins = { | ||
...pickPlugins(knownPluginNames), | ||
...config.plugins, | ||
}; | ||
return { | ||
...(Object.keys(resolvedPlugins).length > 0 | ||
? { plugins: resolvedPlugins } | ||
: null), | ||
...config, | ||
}; | ||
}); | ||
|
||
const utils = { | ||
/** | ||
* Utility function for easily composing configs. | ||
* | ||
* This is a wrapper around `typescript-eslint`'s `config` function. | ||
* | ||
* With automatic plugin inference(if the plugin is known to `@rightcapital/eslint-config`). | ||
* | ||
* @see https://typescript-eslint.io/packages/typescript-eslint#config | ||
*/ | ||
defineConfig, | ||
globals, | ||
plugins, | ||
pickPlugins, | ||
} as const; | ||
|
||
export default utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters