diff --git a/dist/basic.d.ts b/dist/index.d.ts similarity index 100% rename from dist/basic.d.ts rename to dist/index.d.ts diff --git a/dist/package.json b/dist/package.json index 179058d..75463a4 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,13 +1,13 @@ { "name": "@aet/eslint-rules", - "version": "0.0.1-beta.21", + "version": "0.0.1-beta.22", "license": "UNLICENSED", "peerDependencies": { - "typescript": "^5.1.6" - }, - "bin": { - "eslint-add-alias": "./add-alias.js", - "eslint-remove-alias": "./remove-alias.js" + "typescript": "^5.1.6", + "@typescript-eslint/eslint-plugin": "6.2.0", + "@typescript-eslint/parser": "6.2.0", + "eslint-config-prettier": "8.9.0", + "eslint-import-resolver-typescript": "3.5.5" }, "dependencies": { "@types/eslint": "^8.44.1", @@ -18,7 +18,7 @@ "debug": "^4.3.4", "doctrine": "^3.0.0", "emoji-regex": "^10.2.1", - "eslint-define-config": "^1.21.0", + "eslint-define-config": "^1.22.0", "eslint-import-resolver-node": "^0.3.7", "eslint-module-utils": "^2.8.0", "estraverse": "^5.3.0", diff --git a/src/add-alias.ts b/src/add-alias.ts deleted file mode 100644 index b540966..0000000 --- a/src/add-alias.ts +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env node -import fs from 'node:fs'; -import { resolve } from 'node:path'; -import { name } from '../dist/package.json'; - -const pkgPath = resolve(process.cwd(), 'package.json'); -const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); - -const devDeps = (pkg.devDependencies ??= {}); - -Object.assign(devDeps, { - 'eslint-plugin-import': `file:./node_modules/${name}/import`, - 'eslint-plugin-jsx-a11y': `file:./node_modules/${name}/jsx-a11y`, - 'eslint-plugin-local': `file:./node_modules/${name}/local`, - 'eslint-plugin-rules': `file:./node_modules/${name}/rules`, - 'eslint-plugin-react': `file:./node_modules/${name}/react`, - 'eslint-plugin-react-hooks': `file:./node_modules/${name}/react-hooks`, -}); - -devDeps['@typescript-eslint/eslint-plugin'] ??= '6.2.0'; -devDeps['@typescript-eslint/parser'] ??= '6.2.0'; - -fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2)); - -const eslintrc = resolve(process.cwd(), '.eslintrc.js'); -if (fs.existsSync(eslintrc)) { - fs.writeFileSync( - eslintrc, - `const { extendConfig } = require('@aet/eslint-rules/basic'); - -module.exports = extendConfig({ - extends: [], -});`, - ); -} diff --git a/src/basic.ts b/src/index.ts similarity index 87% rename from src/basic.ts rename to src/index.ts index 4c23cf7..8d37804 100644 --- a/src/basic.ts +++ b/src/index.ts @@ -1,5 +1,7 @@ -// @ts-check +import Module from 'module'; import type { ESLintConfig } from 'eslint-define-config'; +// @ts-expect-error +const { name } = (0, require)('./package.json'); function unique(arr: T[]): T[] { return [...new Set(arr)]; @@ -18,6 +20,7 @@ export function extendConfig({ }: ESLintConfig): ESLintConfig { const hasReact = plugins?.includes('react'); const hasUnicorn = plugins?.includes('unicorn'); + const hasReactRefresh = plugins?.includes('react-refresh'); const result: ESLintConfig = { root: true, @@ -166,6 +169,14 @@ export function extendConfig({ 'unicorn/no-unnecessary-await': off, } : {}), + ...(hasReactRefresh + ? { + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + } + : {}), ...rules, }, ...rest, @@ -173,3 +184,18 @@ export function extendConfig({ return result; } + +const _resolveFilename = (Module as any)._resolveFilename; +(Module as any)._resolveFilename = function (module: string, ...args: any[]) { + switch (module) { + case 'eslint-plugin-import': + case 'eslint-plugin-jsx-a11y': + case 'eslint-plugin-local': + case 'eslint-plugin-react': + case 'eslint-plugin-react-hooks': + case 'eslint-plugin-rules': + module = `${name}/${module.slice(14)}`; + } + + return _resolveFilename(module, ...args); +}; diff --git a/src/remove-alias.ts b/src/remove-alias.ts deleted file mode 100644 index 41676c9..0000000 --- a/src/remove-alias.ts +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env node -import fs from 'node:fs'; -import { resolve } from 'node:path'; -import { name } from '../dist/package.json'; - -const pkgPath = resolve(process.cwd(), 'package.json'); -const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8')); - -const devDeps = (pkg.devDependencies ??= {}); -for (const dep of [ - 'eslint-plugin-import', - 'eslint-plugin-jsx-a11y', - 'eslint-plugin-local', - 'eslint-plugin-rules', - 'eslint-plugin-react', - 'eslint-plugin-react-hooks', -]) { - if (devDeps[dep]?.startsWith(`file:./node_modules/${name}/`)) { - delete devDeps[dep]; - } -} - -fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));