Skip to content

Commit

Permalink
feat: ✨ add recommended Next.js rules (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman authored Dec 3, 2024
1 parent 8649133 commit 825d6ba
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/rules/__snapshots__/nextjs.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@

exports[`should create nextjs rules 1`] = `
{
"@next/next/google-font-display": "error",
"@next/next/google-font-preconnect": "error",
"@next/next/inline-script-id": "error",
"@next/next/next-script-for-ga": "error",
"@next/next/no-assign-module-variable": "error",
"@next/next/no-async-client-component": "error",
"@next/next/no-before-interactive-script-outside-document": "error",
"@next/next/no-css-tags": "error",
"@next/next/no-document-import-in-page": "error",
"@next/next/no-duplicate-head": "error",
"@next/next/no-head-element": "error",
"@next/next/no-head-import-in-document": "error",
"@next/next/no-html-link-for-pages": "error",
"@next/next/no-img-element": "error",
"@next/next/no-page-custom-font": "error",
"@next/next/no-script-component-in-head": "error",
"@next/next/no-styled-jsx-in-document": "error",
"@next/next/no-sync-scripts": "error",
"@next/next/no-title-in-document-head": "error",
"@next/next/no-typos": "error",
"@next/next/no-unwanted-polyfillio": "error",
}
`;
7 changes: 4 additions & 3 deletions src/rules/nextjs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { Rules } from "../types";

import { interopDefault } from "../utils/interop-default";
import { warningAsErrors } from "../utils/warnings-as-errors";

export const nextjsRules = async () => {
const nextjsPlugin = await interopDefault(import("@next/eslint-plugin-next"));

return {
...nextjsPlugin.configs["core-web-vitals"].rules,
} satisfies Rules;
return warningAsErrors(
nextjsPlugin.configs.recommended.rules,
) satisfies Rules;
};
31 changes: 31 additions & 0 deletions src/utils/warning-as-errors.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { warningAsErrors } from "./warnings-as-errors";

describe("warningAsErrors", () => {
it("should return empty object when no rules", () => {
const ruleEntries = warningAsErrors();

expect(ruleEntries).toMatchInlineSnapshot(`{}`);
});

it("should return empty object when empty rules", () => {
const ruleEntries = warningAsErrors({});

expect(ruleEntries).toMatchInlineSnapshot(`{}`);
});

it("should change warnings to errors", () => {
const ruleEntries = warningAsErrors({
"react/forbid-prop-types": "warn",
"react/jsx-uses-react": "error",
"react/react-in-jsx-scope": "warn",
});

expect(ruleEntries).toMatchInlineSnapshot(`
{
"react/forbid-prop-types": "error",
"react/jsx-uses-react": "error",
"react/react-in-jsx-scope": "error",
}
`);
});
});

0 comments on commit 825d6ba

Please sign in to comment.