Skip to content

Commit

Permalink
fix: πŸ› only enable react refresh allowConstantExport for vite
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Dec 3, 2024
1 parent 957e5af commit 1fb23f7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/rules/__snapshots__/react.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ exports[`reactRules > should create react rules 1`] = `
"react-refresh/only-export-components": [
"warn",
{
"allowConstantExport": true,
"allowConstantExport": undefined,
"allowExportNames": [],
},
],
Expand Down
13 changes: 13 additions & 0 deletions src/rules/react.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
5 changes: 3 additions & 2 deletions src/rules/react.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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,
Expand All @@ -37,7 +38,7 @@ export const reactRules = async () => {
"react-refresh/only-export-components": [
"warn",
{
allowConstantExport: true,
allowConstantExport: isUsingVite,
allowExportNames: isUsingNext ? nextAllowedExportNames : [],
},
],
Expand Down
4 changes: 4 additions & 0 deletions src/utils/has-dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ export const hasStorybook = () => {
export const hasNext = () => {
return isPackageExists("next");
};

export const hasVite = () => {
return isPackageExists("vite");
};

0 comments on commit 1fb23f7

Please sign in to comment.