-
Couldn't load subscription status.
- Fork 1
Proposals for ESLint rules regarding React app #1208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jinmayamashita
wants to merge
7
commits into
main
Choose a base branch
from
proposal-react-lint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99d544a
add lint rules
jinmayamashita bcdb969
use only the necessary parts of the unicorn rules.
jinmayamashita 78aae0b
establishing rules for React components
jinmayamashita 935513c
Merge branch 'main' into proposal-react-lint
jinmayamashita ea971a3
approve a proposal
jinmayamashita 0b9056d
Merge branch 'main' into proposal-react-lint
jinmayamashita 5c2db40
feat: use eslint 9
jinmayamashita File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,190 @@ | ||
| import js from "@eslint/js"; | ||
| import ts from "typescript-eslint"; | ||
| import globals from "globals"; | ||
| import unicorn from "eslint-plugin-unicorn"; | ||
| import reactRecommended from "eslint-plugin-react/configs/recommended.js"; | ||
| import reactJsxRuntime from "eslint-plugin-react/configs/jsx-runtime.js"; | ||
| import tailwindcss from "eslint-plugin-tailwindcss"; | ||
| import storybook from "eslint-plugin-storybook"; | ||
|
|
||
| /** @type {import('typescript-eslint').Config} */ | ||
| export default [ | ||
| // JS | ||
| { languageOptions: { globals: { ...globals.browser, ...globals.node } } }, | ||
| { ...js.configs.recommended }, | ||
| { | ||
| files: ["**/*.@(ts|tsx|js|jsx|mjs|cjs)"], | ||
| plugins: { unicorn }, | ||
| rules: { | ||
| // https://typescript-eslint.io/rules/naming-convention/ | ||
| "@typescript-eslint/naming-convention": [ | ||
| "error", | ||
| { | ||
| selector: "function", | ||
| format: ["camelCase", "PascalCase"], | ||
| }, | ||
| { | ||
| selector: "variable", | ||
| modifiers: ["const"], | ||
| format: ["camelCase", "UPPER_CASE", "PascalCase"], | ||
| }, | ||
| { | ||
| selector: "interface", | ||
| format: ["PascalCase"], | ||
| }, | ||
| ], | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/filename-case.md | ||
| "unicorn/filename-case": ["error", { case: "kebabCase" }], | ||
| // https://eslint.org/docs/latest/rules/no-console | ||
| "no-console": "error", | ||
| // https://eslint.org/docs/latest/rules/eqeqeq | ||
| eqeqeq: "error", | ||
| // https://eslint.org/docs/latest/rules/no-magic-numbers | ||
| "no-magic-numbers": ["error", { ignore: [0, 1, 2] }], | ||
| // https://eslint.org/docs/latest/rules/no-negated-condition | ||
| "no-negated-condition": "error", | ||
| // https://eslint.org/docs/latest/rules/no-useless-rename | ||
| "no-useless-rename": "error", | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/better-regex.md | ||
| "unicorn/better-regex": "error", | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-nested-ternary.md | ||
| "unicorn/no-nested-ternary": "error", | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prevent-abbreviations.md | ||
| "unicorn/prevent-abbreviations": [ | ||
| "error", | ||
| { | ||
| allowList: { | ||
| Args: true, | ||
| args: true, | ||
| Arg: true, | ||
| arg: true, | ||
| Props: true, | ||
| props: true, | ||
| Prop: true, | ||
| prop: true, | ||
| Refs: true, | ||
| refs: true, | ||
| Ref: true, | ||
| ref: true, | ||
| env: true, | ||
| }, | ||
| }, | ||
| ], | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-for-each.md | ||
| "unicorn/no-array-for-each": "error", | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-push-push.md | ||
| "unicorn/no-array-push-push": "error", | ||
| // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md | ||
| "unicorn/no-array-reduce": "error", | ||
| // https://eslint.org/docs/latest/rules/no-eval | ||
| "no-eval": "error", | ||
| }, | ||
| }, | ||
|
|
||
| // TS | ||
| { files: ["**/*.@(ts|tsx)"] }, | ||
| ...ts.configs.strict, | ||
| ...ts.configs.stylistic, | ||
| { languageOptions: { parserOptions: { project: true } } }, | ||
|
|
||
| // React | ||
| { | ||
| files: ["src/**/*.{ts,tsx}"], | ||
| ...reactRecommended, | ||
| }, | ||
| { | ||
| settings: { react: { version: "detect" } }, | ||
| files: ["src/**/*.{ts,tsx}"], | ||
| rules: { | ||
| ...reactJsxRuntime.rules, | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/hook-use-state.md | ||
| "react/hook-use-state": "error", | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/jsx-boolean-value.md | ||
| "react/jsx-boolean-value": "error", | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md | ||
| "react/jsx-curly-brace-presence": "error", | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/destructuring-assignment.md | ||
| "react/destructuring-assignment": "error", | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md | ||
| "react/jsx-no-useless-fragment": ["error", { allowExpressions: true }], | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/function-component-definition.md | ||
| "react/function-component-definition": [ | ||
| "error", | ||
| { unnamedComponents: "function-expression" }, | ||
| ], | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/jsx-filename-extension.md | ||
| "react/jsx-filename-extension": ["error", { extensions: [".tsx"] }], | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/no-danger.md | ||
| "react/no-danger": "error", | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/no-unstable-nested-components.md | ||
| "react/no-unstable-nested-components": ["error", { allowAsProps: true }], | ||
| // https://github.com/jsx-eslint/eslint-plugin-react/tree/master/docs/rules/no-array-index-key.md | ||
| "react/no-array-index-key": "error", | ||
| "react/prop-types": "off", | ||
| }, | ||
| }, | ||
|
|
||
| // Tailwind CSS | ||
| { | ||
| files: ["src/**/*.tsx"], | ||
| plugins: { tailwindcss }, | ||
| rules: { | ||
| ...tailwindcss.configs.recommended.rules, | ||
| // https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/enforces-negative-arbitrary-values.md | ||
| "tailwindcss/enforces-negative-arbitrary-values": "error", | ||
| // https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/enforces-shorthand.md | ||
| "tailwindcss/enforces-shorthand": "error", | ||
| // https://github.com/francoismassart/eslint-plugin-tailwindcss/tree/master/docs/rules/no-unnecessary-arbitrary-value.md | ||
| "tailwindcss/no-unnecessary-arbitrary-value": "error", | ||
| }, | ||
| settings: { | ||
| tailwindcss: { | ||
| callees: ["clsx", "cn", "tv"], | ||
| }, | ||
| }, | ||
| }, | ||
|
|
||
| // Storybook | ||
| { | ||
| files: ["**/*.stories.@(ts|tsx)"], | ||
| // TODO: Support flat config | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/pull/156 | ||
| plugins: { storybook }, | ||
| rules: { | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/csf-component.md | ||
| "storybook/csf-component": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/default-exports.md | ||
| "storybook/default-exports": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/no-redundant-story-name.md | ||
| "storybook/no-redundant-story-name": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/hierarchy-separator.md | ||
| "storybook/hierarchy-separator": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/story-exports.md | ||
| "storybook/story-exports": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/no-title-property-in-meta.md | ||
| "storybook/no-title-property-in-meta": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/prefer-pascal-case.md | ||
| "storybook/prefer-pascal-case": "error", | ||
| // https://github.com/storybookjs/eslint-plugin-storybook/blob/main/docs/rules/meta-inline-properties.md | ||
| "storybook/meta-inline-properties": "error", | ||
| "@typescript-eslint/naming-convention": [ | ||
| "error", | ||
| { | ||
| selector: "variable", | ||
| modifiers: ["const"], | ||
| format: ["camelCase", "UPPER_CASE", "PascalCase"], | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| ignores: [ | ||
| "node_modules", | ||
| ".next", | ||
| "eslint.config.js", | ||
| ".storybook", | ||
| "storybook-static", | ||
| "dist", | ||
| ], | ||
| }, | ||
| ]; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest the following rules to be added
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seiya0914
Thank you for the proposal! I've reviewed rules and it looks good, so I've added it.
ea971a3
It would be helpful if you could discuss with @mvn-luanvu-hn whether to approve the PR after reviewing the final rules.