Skip to content

Commit

Permalink
feat: ✨ add eslint-plugin-react-compiler rules (#108)
Browse files Browse the repository at this point in the history
🏁 Closes: #107
  • Loading branch information
jimmy-guzman authored Nov 27, 2024
1 parent 161aa60 commit 15ce7c5
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"eslint-plugin-perfectionist": "^4.1.2",
"eslint-plugin-playwright": "^2.1.0",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-compiler": "19.0.0-beta-df7b47d-20241124",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "0.4.14",
"eslint-plugin-regexp": "^2.7.0",
Expand Down
121 changes: 121 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions src/configs/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import { reactRules } from "../rules/react";
import { interopDefault } from "../utils/interop-default";

export const reactConfig = async () => {
const [reactPlugin, jsxA11yPlugin, reactHooksPlugin, reactRefreshPlugin] =
await Promise.all([
interopDefault(import("eslint-plugin-react")),
interopDefault(import("eslint-plugin-jsx-a11y")),
import("eslint-plugin-react-hooks"),
import("eslint-plugin-react-refresh"),
]);
const [
reactPlugin,
jsxA11yPlugin,
reactHooksPlugin,
reactRefreshPlugin,
reactCompilerPlugin,
] = await Promise.all([
interopDefault(import("eslint-plugin-react")),
interopDefault(import("eslint-plugin-jsx-a11y")),
import("eslint-plugin-react-hooks"),
import("eslint-plugin-react-refresh"),
interopDefault(import("eslint-plugin-react-compiler")),
]);

return [
{
Expand All @@ -33,6 +39,7 @@ export const reactConfig = async () => {
plugins: {
"jsx-a11y": jsxA11yPlugin,
"react": reactPlugin,
"react-compiler": reactCompilerPlugin,
"react-hooks": reactHooksPlugin,
"react-refresh": reactRefreshPlugin,
},
Expand Down
8 changes: 8 additions & 0 deletions src/rules.gen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3702,6 +3702,10 @@ export interface RuleOptions {
* @see https://eslint.org/docs/latest/rules/radix
*/
'radix'?: Linter.RuleEntry<Radix>
/**
* Surfaces diagnostics from React Forget
*/
'react-compiler/react-compiler'?: Linter.RuleEntry<ReactCompilerReactCompiler>
/**
* verifies the list of dependencies for Hooks like useEffect and similar
* @see https://github.com/facebook/react/issues/14920
Expand Down Expand Up @@ -9787,6 +9791,10 @@ type Quotes = []|[("single" | "double" | "backtick")]|[("single" | "double" | "b
})]
// ----- radix -----
type Radix = []|[("always" | "as-needed")]
// ----- react-compiler/react-compiler -----
type ReactCompilerReactCompiler = []|[{
[k: string]: unknown | undefined
}]
// ----- react-hooks/exhaustive-deps -----
type ReactHooksExhaustiveDeps = []|[{
additionalHooks?: string
Expand Down
1 change: 1 addition & 0 deletions src/rules/__snapshots__/react.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ exports[`should create react rules 1`] = `
"jsx-a11y/role-supports-aria-props": "error",
"jsx-a11y/scope": "error",
"jsx-a11y/tabindex-no-positive": "error",
"react-compiler/react-compiler": "error",
"react-hooks/exhaustive-deps": "error",
"react-hooks/rules-of-hooks": "error",
"react-refresh/only-export-components": [
Expand Down
1 change: 1 addition & 0 deletions src/rules/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const reactRules = async () => {
...jsxA11yPlugin.configs.recommended.rules,
...normalizeRuleEntries(reactPlugin.configs.flat?.recommended?.rules),
...normalizeRuleEntries(reactPlugin.configs.flat?.["jsx-runtime"]?.rules),
"react-compiler/react-compiler": "error",
"react-hooks/exhaustive-deps": "error",
"react-hooks/rules-of-hooks": "error",
"react-refresh/only-export-components": [
Expand Down
8 changes: 8 additions & 0 deletions src/stubs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ declare module "@eslint-community/eslint-plugin-eslint-comments/configs" {

export = { recommended };
}

declare module "eslint-plugin-react-compiler" {
import type { ESLint } from "eslint";

const plugin: ESLint.Plugin;

export default plugin;
}

0 comments on commit 15ce7c5

Please sign in to comment.