diff --git a/dist/index.d.ts b/dist/index.d.ts index 21cf707..a316661 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -32,16 +32,16 @@ export type RuleEntry = RuleLevel | [ ]; export interface LocalRuleOptions { /** Bans import from the specifier '.' and '..' and replaces it with '.+/index' */ - "rules/no-import-dot": RuleEntry; + "custom/no-import-dot": RuleEntry; /** * Enforce template literal expressions to be of `string` type * @see [restrict-template-expressions](https://typescript-eslint.io/rules/restrict-template-expressions) */ - "rules/restrict-template-expressions": RuleEntry<{ + "custom/restrict-template-expressions": RuleEntry<{ allow: string[]; }>; /** Ban assignment of empty object literals `{}` and replace them with `Object.create(null)` */ - "rules/no-empty-object-literal": RuleEntry; + "custom/no-empty-object-literal": RuleEntry; } export type RuleOptions = Rules & Partial; export interface CustomRule { diff --git a/dist/package.json b/dist/package.json index 975a4e0..ac8f269 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "@aet/eslint-rules", - "version": "1.0.1-beta.20", + "version": "1.0.1-beta.22", "license": "UNLICENSED", "bin": { "eslint-install": "install.js", @@ -17,10 +17,10 @@ "@eslint-community/eslint-utils": "^4.4.0", "@tanstack/eslint-plugin-query": "^5.51.15", "@types/eslint": "^9.6.0", - "@typescript-eslint/eslint-plugin": "^8.0.0", - "@typescript-eslint/parser": "^8.0.0", - "@typescript-eslint/type-utils": "^8.0.0", - "@typescript-eslint/utils": "^8.0.0", + "@typescript-eslint/eslint-plugin": "^8.0.1", + "@typescript-eslint/parser": "^8.0.1", + "@typescript-eslint/type-utils": "^8.0.1", + "@typescript-eslint/utils": "^8.0.1", "@eslint-react/eslint-plugin": "1.7.1", "aria-query": "^5.3.0", "axe-core": "^4.10.0", @@ -35,7 +35,7 @@ "eslint-module-utils": "^2.8.1", "eslint-plugin-es-x": "^8.0.0", "eslint-plugin-import-x": "^3.1.0", - "eslint-plugin-jsdoc": "^48.11.0", + "eslint-plugin-jsdoc": "^50.0.0", "eslint-plugin-react-refresh": "^0.4.9", "eslint-plugin-unicorn": "^55.0.0", "esprima": "^4.0.1", @@ -65,4 +65,4 @@ "**/is-core-module": "file:./overrides/is-core-module", "**/supports-preserve-symlinks-flag": "file:./overrides/supports-preserve-symlinks-flag" } -} +} \ No newline at end of file diff --git a/packages/eslint-import-resolver-typescript b/packages/eslint-import-resolver-typescript index c9b5626..3dfad60 160000 --- a/packages/eslint-import-resolver-typescript +++ b/packages/eslint-import-resolver-typescript @@ -1 +1 @@ -Subproject commit c9b5626ee69bd529c7e391e40928a4fb28dce179 +Subproject commit 3dfad602a05b4b3812a4d3fc681051932f86e838 diff --git a/packages/eslint-plugin-n b/packages/eslint-plugin-n index 5aad5f1..6744257 160000 --- a/packages/eslint-plugin-n +++ b/packages/eslint-plugin-n @@ -1 +1 @@ -Subproject commit 5aad5f1c419b3143ffb9356bd299fc50dc576ee5 +Subproject commit 6744257b43560181412a76eadeb7de564b886ad4 diff --git a/src/env.ts b/src/env.ts index 5af29f3..cb24d56 100644 --- a/src/env.ts +++ b/src/env.ts @@ -1,10 +1,9 @@ import * as fs from 'node:fs'; import { resolve } from 'node:path'; -import { storybook } from './index'; import { react, reactRefresh } from './presets/react'; import { tailwind } from './presets/tailwind'; import { jsdoc } from './presets/jsdoc'; -import { reactQuery } from './presets/misc'; +import { storybook, reactQuery } from './presets/misc'; import { testingLibrary } from './presets/testing-library'; import type { Middleware } from './middleware'; diff --git a/src/index.ts b/src/index.ts index 548bf4a..b64819e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import type { Middleware, MiddlewareConfig, MiddlewareFunctions } from './middle import { importTypeScript } from './presets/typescript'; import { unicorn } from './presets/unicorn'; import { eslintRules } from './presets/eslint'; -import { local } from './presets/local'; +import { custom } from './presets/custom'; import { error, warn, off } from './constants'; import { checkEnv } from './env'; @@ -41,14 +41,14 @@ type RuleEntry = RuleLevel | [RuleLevel, Partial]; export interface LocalRuleOptions { /** Bans import from the specifier '.' and '..' and replaces it with '.+/index' */ - 'rules/no-import-dot': RuleEntry; + 'custom/no-import-dot': RuleEntry; /** * Enforce template literal expressions to be of `string` type * @see [restrict-template-expressions](https://typescript-eslint.io/rules/restrict-template-expressions) */ - 'rules/restrict-template-expressions': RuleEntry<{ allow: string[] }>; + 'custom/restrict-template-expressions': RuleEntry<{ allow: string[] }>; /** Ban assignment of empty object literals `{}` and replace them with `Object.create(null)` */ - 'rules/no-empty-object-literal': RuleEntry; + 'custom/no-empty-object-literal': RuleEntry; } export type RuleOptions = Rules & Partial; @@ -121,25 +121,27 @@ export function extendConfig( customRuleFiles, parserOptions, middlewares: _middlewares = [], - // @ts-expect-error - localRules: _, ...rest } = of; let plugins: Plugin[] = [..._plugins]; let extend: Extends[] = ensureArray(_extends); + if (customRuleFiles != null) { + plugins.push('local'); + } + const middlewares: Middleware[] = uniq([ importTypeScript, unicorn, - local, + custom, ...(auto ? checkEnv() : []), ..._middlewares, ]); const result: MiddlewareConfig = { root: true, - plugins: unique('rules', plugins), + plugins: unique('custom', plugins), env: { node: true, browser: true, es2023: true }, reportUnusedDisableDirectives: true, parserOptions: { diff --git a/src/local/index.ts b/src/local/index.ts index 1d3739e..ae624a3 100644 --- a/src/local/index.ts +++ b/src/local/index.ts @@ -1,6 +1,6 @@ import type { ESLint } from 'eslint'; import * as fs from 'node:fs'; -import { basename, extname, resolve } from 'node:path'; +import { basename, extname, isAbsolute, resolve } from 'node:path'; import { glob } from 'fast-glob'; import { parseModule } from 'esprima'; import query from 'esquery'; @@ -9,6 +9,7 @@ import type { Node, Property } from 'estree'; // https://github.com/gulpjs/interpret const transpilers = [ 'esbuild-register', + 'tsx', 'ts-node/register/transpile-only', '@swc/register', 'sucrase/register', @@ -64,7 +65,10 @@ function main() { if (!customRuleFiles?.length) return; tryRequire(); - for (const file of glob.sync(customRuleFiles)) { + for (let file of glob.sync(customRuleFiles)) { + if (!isAbsolute(file)) { + file = resolve(rootDir, file); + } const module = unwrapDefault(require(file)); const name = module.name ?? basename(file, extname(file)); plugin.rules![name] = module; diff --git a/src/presets/custom.ts b/src/presets/custom.ts new file mode 100644 index 0000000..8d528f9 --- /dev/null +++ b/src/presets/custom.ts @@ -0,0 +1,12 @@ +import type { LocalRuleOptions } from '../index'; +import { error } from '../constants'; +import { defineMiddleware } from '../middleware'; + +const customRules: Partial = { + 'custom/no-import-dot': error, + 'custom/restrict-template-expressions': error, +}; + +export const custom = defineMiddleware((_, { addRules }) => { + addRules(customRules); +}); diff --git a/src/presets/local.ts b/src/presets/local.ts deleted file mode 100644 index 2728d24..0000000 --- a/src/presets/local.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { LocalRuleOptions } from '../index'; -import { error } from '../constants'; -import { defineMiddleware } from '../middleware'; - -const localRules: Partial = { - 'rules/no-import-dot': error, - 'rules/restrict-template-expressions': error, -}; - -export const local = defineMiddleware((_, { addRules }) => { - addRules(localRules); -});