diff --git a/next.js b/next.js index 9fd529a..84d451e 100644 --- a/next.js +++ b/next.js @@ -1,3 +1,6 @@ module.exports = { - extends: ["next/core-web-vitals", "next/typescript", "./react.js"], + extends: ["next/core-web-vitals", "next/typescript", "./ts.js"], + rules: { + ...require("./shared-react.js"), + }, } diff --git a/package.json b/package.json index bd6fd06..a05dc68 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "eslint-config-gev", - "version": "4.6.0", + "version": "4.6.1", "description": "Curated ESLint configs for TS, JS, Next, React, and React Native projects", "author": "SrBrahma", "main": "index.js", "bin": "bin.js", "scripts": { - "format": "biome check --apply-unsafe . && eslint --fix . package.json", - "format:check": "biome check . && eslint . package.json", + "format": "biome check --unsafe --fix . && eslint --fix . package.json", + "format:check": "biome check --unsafe . && eslint . package.json", "pre-commit": "bun format && bun start && git add -A", "prepare": "bunx husky", "start": "bun scripts/makeTsExtensions.ts", @@ -38,14 +38,16 @@ "citty": "0.1.6", "eslint": "8.56.0", "eslint-config-biome": "^1.9.3", + "eslint-config-next": "^15.0.3", "eslint-plugin-jsdoc": "48.2.6", "eslint-plugin-json-files": "^4.4.2", "eslint-plugin-no-autofix": "2.1.0", "eslint-plugin-no-relative-import-paths": "1.5.5", "eslint-plugin-prefer-arrow-functions": "3.4.1", "eslint-plugin-react": "7.37.2", - "eslint-plugin-react-hooks": "4.6.2", + "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-native": "4.1.0", + "eslint-plugin-react-refresh": "^0.4.14", "eslint-plugin-require-extensions": "0.1.3", "eslint-plugin-unused-imports": "3.2.0" }, @@ -53,8 +55,6 @@ "@biomejs/biome": "^1.9.4", "@sindresorhus/tsconfig": "7.0.0", "@types/bun": "^1.1.14", - "eslint-config-next": "^15.0.3", - "eslint-plugin-react-refresh": "^0.4.14", "husky": "9.1.7" } } diff --git a/react.js b/react.js index 3fa96af..9070a44 100644 --- a/react.js +++ b/react.js @@ -12,57 +12,6 @@ module.exports = { "./ts.js", ], rules: { - "react/prop-types": "off", - "react/display-name": "off", - - /** - * Allow to use . Sometimes it's useful to simplify the code and to do some nice hacks, - * like conditional wrapping component. - * https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md - */ - "react/no-children-prop": "off", - - /** - * Enable deps autofix. I've only had infinite loops once, and the autofix was off, - * I just accept the suggestions and don't spend time analysing it. Rare to happen, easy to notice. - * - * https://github.com/facebook/react/issues/18235#issuecomment-898636301 - */ - "react-hooks/exhaustive-deps": [ - "warn", - { - enableDangerousAutofixThisMayCauseInfiniteLoops: true, - }, - ], - /** https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md */ - // Dropped it as it won't allow <> to fit JSX.Element return. - // "react/jsx-no-useless-fragment": ["warn", {"allowExpressions": true}], - - /** - * From d to {'d'} - * - * Note that it always converts to double-quotes when changing, - * so we use `jsx-quotes` rule for props and `quotes` rule for children. - * - * https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md - */ - "react/jsx-curly-brace-presence": [ - "warn", - { props: "never", children: "always" }, - ], - - /** - * Prefer <> over if not using key=''. - * - * https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md - */ - "react/jsx-fragments": "warn", - - /** https://www.npmjs.com/package/eslint-plugin-react-refresh */ - "react-refresh/only-export-components": [ - "warn", - // Only Vite supports this. - { allowConstantExport: true }, - ], + ...require("./shared-react.js"), }, } diff --git a/shared-react.js b/shared-react.js new file mode 100644 index 0000000..c47b4c2 --- /dev/null +++ b/shared-react.js @@ -0,0 +1,46 @@ +module.exports = { + "react/prop-types": "off", + "react/display-name": "off", + /** + * Enable deps autofix. I've only had infinite loops once, and the autofix was off, + * I just accept the suggestions and don't spend time analysing it. Rare to happen, easy to notice. + * + * https://github.com/facebook/react/issues/18235#issuecomment-898636301 + */ + "react-hooks/exhaustive-deps": [ + "warn", + { + enableDangerousAutofixThisMayCauseInfiniteLoops: true, + }, + ], + /** https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-no-useless-fragment.md */ + // Dropped it as it won't allow <> to fit JSX.Element return. + // "react/jsx-no-useless-fragment": ["warn", {"allowExpressions": true}], + + /** + * From d to {'d'} + * + * Note that it always converts to double-quotes when changing, + * so we use `jsx-quotes` rule for props and `quotes` rule for children. + * + * https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/jsx-curly-brace-presence.md + */ + "react/jsx-curly-brace-presence": [ + "warn", + { props: "never", children: "always" }, + ], + + /** + * Prefer <> over if not using key=''. + * + * https://github.com/jsx-eslint/eslint-plugin-react/blob/master/docs/rules/jsx-fragments.md + */ + "react/jsx-fragments": "warn", + + /** https://www.npmjs.com/package/eslint-plugin-react-refresh */ + "react-refresh/only-export-components": [ + "warn", + // Only Vite supports this. + { allowConstantExport: true }, + ], +} diff --git a/tests/test.test.ts b/tests/test.test.ts new file mode 100644 index 0000000..8b1f9a0 --- /dev/null +++ b/tests/test.test.ts @@ -0,0 +1,19 @@ +import { test } from "bun:test" +import path from "node:path" +import { $ } from "bun" + +const flavors = ["index", "ts", "js", "react", "react-native"] + +$.cwd(path.resolve(__dirname)) + +test("can run eslint", async () => { + const execs = flavors.map((flavor) => + $`bunx eslint --config ../${flavor}.js test.test.ts`.catch( + (err: unknown) => { + throw new Error(`error on flavor ${flavor}: ${err}`) + }, + ), + ) + + await Promise.all(execs) +}) diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 0000000..55d6d8c --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@sindresorhus/tsconfig" +}