From 825d6ba7b5c5732c0de21f945d37c1db0b7f855e Mon Sep 17 00:00:00 2001 From: Jimmy Guzman <30631540+jimmy-guzman@users.noreply.github.com> Date: Mon, 2 Dec 2024 20:27:51 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20add=20recommended=20Next.js?= =?UTF-8?q?=20rules=20(#114)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/rules/__snapshots__/nextjs.spec.ts.snap | 19 +++++++++++++ src/rules/nextjs.ts | 7 +++-- src/utils/warning-as-errors.spec.ts | 31 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/utils/warning-as-errors.spec.ts diff --git a/src/rules/__snapshots__/nextjs.spec.ts.snap b/src/rules/__snapshots__/nextjs.spec.ts.snap index 641d99e..6327679 100644 --- a/src/rules/__snapshots__/nextjs.spec.ts.snap +++ b/src/rules/__snapshots__/nextjs.spec.ts.snap @@ -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", } `; diff --git a/src/rules/nextjs.ts b/src/rules/nextjs.ts index d979436..8cdc151 100644 --- a/src/rules/nextjs.ts +++ b/src/rules/nextjs.ts @@ -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; }; diff --git a/src/utils/warning-as-errors.spec.ts b/src/utils/warning-as-errors.spec.ts new file mode 100644 index 0000000..14ce121 --- /dev/null +++ b/src/utils/warning-as-errors.spec.ts @@ -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", + } + `); + }); +});