Skip to content

Commit

Permalink
feat!: Add a ruleset powered by unicorn plugin into essentials co…
Browse files Browse the repository at this point in the history
…nfig (#335)

* install packages

* implement rules: unicorn

* apply unicorn ruleset

* update readme

* disable `prefer-global-this` rule
  • Loading branch information
wakamsha authored Oct 25, 2024
1 parent 8179efa commit c5a1544
Show file tree
Hide file tree
Showing 14 changed files with 3,735 additions and 92 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ We also provide various other rule sets that you can configure to suit your proj
}
```

| Rule set | Summary | Dependencies |
| -----------: | :---------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `essentials` | Contains basic, import, and promise recommended rules | [`eslint`](https://eslint.org/) <br> [`eslint-plugin-promise`](https://github.com/eslint-community/eslint-plugin-promise) <br> [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) |
| `jsdoc` | Contains JSDoc recommended rules | [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc) |
| `next` | Contains Next.js recommended rules | [`@next/eslint-plugin-next`](https://github.com/vercel/next.js/tree/canary/packages/eslint-plugin-next) |
| `node` | Contains Node.js recommended rules | [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n) |
| `react` | Contains React recommended rules | [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y) <br> [`eslint-plugin-react-hooks`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks) <br> [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react) |
| `storybook` | Contains Storybook recommended rules | [`eslint-plugin-storybook`](https://github.com/storybookjs/eslint-plugin-storybook) |
| `test/react` | Contains Jest and React Testing Library rules | [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest) <br> [`eslint-plugin-jest-dom`](https://github.com/testing-library/eslint-plugin-jest-dom) <br> [`eslint-plugin-testing-library`](https://github.com/testing-library/eslint-plugin-testing-library) |
| `typescript` | Contains TypeScript recommended rules | [`@eslint-typescript/eslint-plugin`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin) <br> [`@eslint-typescript/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser) |
| Rule set | Summary | Dependencies |
| -----------: | :---------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `essentials` | Contains basic, import, and promise recommended rules | [`eslint`](https://eslint.org/) <br> [`eslint-plugin-promise`](https://github.com/eslint-community/eslint-plugin-promise) <br> [`eslint-plugin-import`](https://github.com/import-js/eslint-plugin-import) <br> [`eslint-plugin-unicorn`](https://github.com/sindresorhus/eslint-plugin-unicorn) |
| `jsdoc` | Contains JSDoc recommended rules | [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc) |
| `next` | Contains Next.js recommended rules | [`@next/eslint-plugin-next`](https://github.com/vercel/next.js/tree/canary/packages/eslint-plugin-next) |
| `node` | Contains Node.js recommended rules | [`eslint-plugin-n`](https://github.com/eslint-community/eslint-plugin-n) |
| `react` | Contains React recommended rules | [`eslint-plugin-jsx-a11y`](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y) <br> [`eslint-plugin-react-hooks`](https://github.com/facebook/react/tree/main/packages/eslint-plugin-react-hooks) <br> [`eslint-plugin-react`](https://github.com/jsx-eslint/eslint-plugin-react) |
| `storybook` | Contains Storybook recommended rules | [`eslint-plugin-storybook`](https://github.com/storybookjs/eslint-plugin-storybook) |
| `test/react` | Contains Jest and React Testing Library rules | [`eslint-plugin-jest`](https://github.com/jest-community/eslint-plugin-jest) <br> [`eslint-plugin-jest-dom`](https://github.com/testing-library/eslint-plugin-jest-dom) <br> [`eslint-plugin-testing-library`](https://github.com/testing-library/eslint-plugin-testing-library) |
| `typescript` | Contains TypeScript recommended rules | [`@eslint-typescript/eslint-plugin`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/eslint-plugin) <br> [`@eslint-typescript/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/parser) |

## Using Prettier

Expand Down Expand Up @@ -162,7 +162,7 @@ By adding the `prettier` configuration to `extends` in the ESLint configuration,
eslint-config-moneyforward contains various plugins related to different rule sets. Therefore, users don't need to install them separately. If you have installed them in your existing configuration, we recommend uninstalling them.

```bash
npm uninstall eslint-plugin-promise eslint-plugin-import \
npm uninstall eslint-plugin-promise eslint-plugin-import eslint-plugin-unicorn \
eslint-plugin-jsdoc \
@next/eslint-plugin-next \
eslint-plugin-n \
Expand Down
1 change: 1 addition & 0 deletions configs/eslintrc/essentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
'../../rules/imports',
'../../rules/promise',
'../../rules/style',
'../../rules/unicorn',
'../../rules/variables',
],
parserOptions: {
Expand Down
27 changes: 27 additions & 0 deletions configs/flat/essentials.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import globals from 'globals';
// @ts-ignore
import importPlugin from 'eslint-plugin-import';
import promisePlugin from 'eslint-plugin-promise';
import unicornPlugin from 'eslint-plugin-unicorn';
import bestPracticesRuleSet from '../../rules/best-practices.js';
import errorsRuleSet from '../../rules/errors.js';
import es6RuleSet from '../../rules/es6.js';
import importRuleSetBase from '../../rules/imports.js';
import promiseRuleSetBase from '../../rules/promise.js';
import styleRuleSet from '../../rules/style.js';
import unicornRuleSetBase from '../../rules/unicorn.js';
import variablesRuleSet from '../../rules/variables.js';

const importRuleSet = {
Expand All @@ -33,6 +35,25 @@ const promiseRuleSet = {
},
};

const unicornRuleSet = {
plugins: {
unicorn: unicornPlugin,
},
rules: {
...unicornPlugin.configs['flat/recommended'].rules,
...unicornRuleSetBase.rules,
},
};

const unicornRuleSetForReact = {
plugins: {
unicorn: unicornPlugin,
},
rules: {
...unicornRuleSetBase.overrides[0].rules,
},
};

export default [
{
languageOptions: {
Expand All @@ -51,4 +72,10 @@ export default [
promiseRuleSet,
styleRuleSet,
variablesRuleSet,

unicornRuleSet,
{
files: ['*.@(jsx|tsx)'],
...unicornRuleSetForReact,
},
];
Loading

0 comments on commit c5a1544

Please sign in to comment.