Skip to content

Commit

Permalink
refactor(eslint.config.js): simplify eslintConfig export for clarity
Browse files Browse the repository at this point in the history
feat(package.json): bump version to 1.3.6 and add eslint-plugin-react-hooks
refactor(nextjs/config.ts, react/config.ts): extract rule renaming logic to improve maintainability
refactor(gen.d.ts): remove deprecated react-hooks rules to align with updated hooks best practices
style(type.ts): disable no-explicit-any rule to allow any types where necessary

feat(utils/extension.ts): add eslint-plugin-react-hooks to extensions
refactor(utils/factory.ts): include nextjs plugin in eslintConfig mapping for consistency
refactor(utils/naming.ts): correct return type annotation in renameRules function
style: disable ts/no-explicit-any rule to allow any type usage where needed
  • Loading branch information
Bluzzi committed Dec 25, 2024
1 parent f80fa61 commit 3433c5d
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 30 deletions.
11 changes: 3 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { eslintConfig } from "./dist/index.js";

export default eslintConfig(
{
typescript: { tsconfigPath: "./tsconfig.json" },
},
{
rules: { "ts/no-explicit-any": "off" },
},
);
export default eslintConfig({
typescript: { tsconfigPath: "./tsconfig.json" },
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@bluzzi/eslint-config",
"description": "ESLint configuration preset for linting and formatting all your files",
"version": "1.3.5",
"version": "1.3.6",
"license": "MIT",
"author": "Bluzzi",
"type": "module",
Expand Down Expand Up @@ -39,6 +39,7 @@
"eslint-flat-config-utils": "^0.4.0",
"eslint-plugin-antfu": "^2.7.0",
"eslint-plugin-n": "^17.15.1",
"eslint-plugin-react-hooks": "^5.1.0",
"globals": "^15.14.0",
"local-pkg": "^0.5.1"
},
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

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

16 changes: 13 additions & 3 deletions src/configs/nextjs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@

import type { TypedFlatConfigItem } from "#/types/type";
import { nextjsPlugin } from "#/utils/extension";
import { configName } from "#/utils/naming";
import { configName, renameRules } from "#/utils/naming";

export const nextjs = (): TypedFlatConfigItem[] => {
const recommendedRules = renameRules(
nextjsPlugin.configs.recommended.rules as Record<string, string>,
{ "@next/next": "nextjs" },
);

const recommendedCoreRules = renameRules(
nextjsPlugin.configs["core-web-vitals"].rules as Record<string, string>,
{ "@next/next": "nextjs" },
);

return [
{
name: configName("nextjs", "rules"),
Expand All @@ -15,8 +25,8 @@ export const nextjs = (): TypedFlatConfigItem[] => {
},
rules: {
// https://github.com/vercel/next.js/blob/7a47ed5123b8dac03e9483cb823e224370da2667/packages/eslint-plugin-next/src/index.ts#L26
...nextjsPlugin.configs.recommended.rules,
...nextjsPlugin.configs["core-web-vitals"].rules,
...recommendedRules,
...recommendedCoreRules,
},
},
];
Expand Down
14 changes: 12 additions & 2 deletions src/configs/react/config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import type { TypedFlatConfigItem } from "#/types/type";
import { reactPlugin } from "#/utils/extension";
import { configName } from "#/utils/naming";
import { configName, renameRules } from "#/utils/naming";

export const react = (): TypedFlatConfigItem[] => {
const recommendedRules = renameRules(
reactPlugin.configs.recommended,
{
"@eslint-react": "react",
"@eslint-react/dom": "react-dom",
"@eslint-react/hooks-extra": "react-hooks-extra",
"@eslint-react/naming-convention": "react-naming-convention",
},
);

return [
{
name: configName("react", "rules"),
Expand All @@ -22,7 +32,7 @@ export const react = (): TypedFlatConfigItem[] => {
sourceType: "module",
},
rules: {
...reactPlugin.configs.recommended.rules,
...recommendedRules,
},
},
];
Expand Down
15 changes: 0 additions & 15 deletions src/types/gen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1856,16 +1856,6 @@ export interface RuleOptions {
* @see https://eslint-react.xyz/docs/rules/hooks-extra-prefer-use-state-lazy-initialization
*/
'react-hooks-extra/prefer-use-state-lazy-initialization'?: Linter.RuleEntry<[]>
/**
* verifies the list of dependencies for Hooks like useEffect and similar
* @see https://github.com/facebook/react/issues/14920
*/
'react-hooks/exhaustive-deps'?: Linter.RuleEntry<ReactHooksExhaustiveDeps>
/**
* enforces the Rules of Hooks
* @see https://reactjs.org/docs/hooks-rules.html
*/
'react-hooks/rules-of-hooks'?: Linter.RuleEntry<[]>
/**
* enforce component naming convention to 'PascalCase' or 'CONSTANT_CASE'
* @see https://eslint-react.xyz/docs/rules/naming-convention-component-name
Expand Down Expand Up @@ -5094,11 +5084,6 @@ type ReactDomNoUnknownProperty = []|[{
ignore?: string[]
requireDataLowercase?: boolean
}]
// ----- react-hooks/exhaustive-deps -----
type ReactHooksExhaustiveDeps = []|[{
additionalHooks?: string
enableDangerousAutofixThisMayCauseInfiniteLoops?: boolean
}]
// ----- react-naming-convention/component-name -----
type ReactNamingConventionComponentName = []|[(("PascalCase" | "CONSTANT_CASE") | {
allowAllCaps?: boolean
Expand Down
2 changes: 2 additions & 0 deletions src/types/type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable ts/no-explicit-any */

import type { Linter } from "eslint";
import type { ConfigNames, RuleOptions } from "./gen";
import type { ParamsTS } from "#/configs/typescript";
Expand Down
1 change: 1 addition & 0 deletions src/utils/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export { default as stylisticPlugin } from "@stylistic/eslint-plugin";
export { default as typescriptPlugin } from "@typescript-eslint/eslint-plugin";
export { default as nextjsPlugin } from "@next/eslint-plugin-next";
export { default as reactPlugin } from "@eslint-react/eslint-plugin";
export { default as reactHooksPlugin } from "eslint-plugin-react-hooks";

export { default as typescriptParser } from "@typescript-eslint/parser";
6 changes: 6 additions & 0 deletions src/utils/factory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable ts/no-explicit-any */

import type { Awaitable, ConfigNames, OptionsConfig, TypedFlatConfigItem } from "#/types/type";
import type { Linter } from "eslint";
import { isPackageExists } from "local-pkg";
Expand Down Expand Up @@ -67,10 +69,14 @@ export const eslintConfig = async (
"@typescript-eslint": "ts",
"n": "node",

"@next/next": "next",

"@eslint-react": "react",
"@eslint-react/dom": "react-dom",
"@eslint-react/hooks-extra": "react-hooks-extra",
"@eslint-react/naming-convention": "react-naming-convention",

"react-hooks": "react-hooks", // maybe good for consistency
});

return composer;
Expand Down
4 changes: 3 additions & 1 deletion src/utils/naming.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable ts/no-explicit-any */

export const configName = (name: string, category: "rules" | "parsers" | "plugins"): string => `bluzzi/${name}/${category}`;

/**
Expand All @@ -18,7 +20,7 @@ export const configName = (name: string, category: "rules" | "parsers" | "plugin
* }]
* ```
*/
export const renameRules = (rules: Record<string, any>, map: Record<string, string>): Record<string, string> => {
export const renameRules = (rules: Record<string, any>, map: Record<string, string>): Record<string, any> => {
return Object.fromEntries(
Object.entries(rules)
.map(([key, value]) => {
Expand Down

0 comments on commit 3433c5d

Please sign in to comment.