diff --git a/src/rules/__snapshots__/react.spec.ts.snap b/src/rules/__snapshots__/react.spec.ts.snap index a50453a..2c4fb33 100644 --- a/src/rules/__snapshots__/react.spec.ts.snap +++ b/src/rules/__snapshots__/react.spec.ts.snap @@ -194,7 +194,7 @@ exports[`reactRules > should create react rules 1`] = ` "react-refresh/only-export-components": [ "warn", { - "allowConstantExport": true, + "allowConstantExport": undefined, "allowExportNames": [], }, ], diff --git a/src/rules/react.spec.ts b/src/rules/react.spec.ts index 01093a8..453ab7d 100644 --- a/src/rules/react.spec.ts +++ b/src/rules/react.spec.ts @@ -37,4 +37,17 @@ describe("reactRules", () => { ] `); }); + + it("should only enable allowConstantExport for vite", async () => { + vi.mocked(isPackageExists).mockImplementation((name) => { + return name === "vite"; + }); + + const rules = await reactRules(); + + const allowConstantExport = + rules["react-refresh/only-export-components"][1].allowConstantExport; + + expect(allowConstantExport).toBeTruthy(); + }); }); diff --git a/src/rules/react.ts b/src/rules/react.ts index 301ef0b..41bea53 100644 --- a/src/rules/react.ts +++ b/src/rules/react.ts @@ -1,6 +1,6 @@ import type { Rules } from "../types"; -import { hasNext } from "../utils/has-dependency"; +import { hasNext, hasVite } from "../utils/has-dependency"; import { interopDefault } from "../utils/interop-default"; import { normalizeRuleEntries } from "../utils/normalize-rule-entries"; @@ -26,6 +26,7 @@ export const reactRules = async () => { interopDefault(import("eslint-plugin-jsx-a11y")), ]); const isUsingNext = hasNext(); + const isUsingVite = hasVite(); return { ...jsxA11yPlugin.configs.recommended.rules, @@ -37,7 +38,7 @@ export const reactRules = async () => { "react-refresh/only-export-components": [ "warn", { - allowConstantExport: true, + allowConstantExport: isUsingVite, allowExportNames: isUsingNext ? nextAllowedExportNames : [], }, ], diff --git a/src/utils/has-dependency.ts b/src/utils/has-dependency.ts index 3943a5d..172dc91 100644 --- a/src/utils/has-dependency.ts +++ b/src/utils/has-dependency.ts @@ -47,3 +47,7 @@ export const hasStorybook = () => { export const hasNext = () => { return isPackageExists("next"); }; + +export const hasVite = () => { + return isPackageExists("vite"); +};