eslint-config-setup 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/0b23ff88.js +48 -339
- package/dist/configs/12c62446.js +6 -266
- package/dist/configs/196d687e.js +52 -383
- package/dist/configs/1c3f743c.js +7 -267
- package/dist/configs/2f6f3a82.js +9 -313
- package/dist/configs/4eb62e57.js +49 -340
- package/dist/configs/52762a42.js +41 -4
- package/dist/configs/532f50a4.js +0 -1
- package/dist/configs/5a302873.js +8 -312
- package/dist/configs/6bc0d588.js +43 -4
- package/dist/configs/91e82988.js +0 -1
- package/dist/configs/c2fecd3d.js +41 -4
- package/dist/configs/cde010b4.js +0 -1
- package/dist/configs/d537b683.js +43 -4
- package/dist/configs/db69ebb6.js +53 -384
- package/dist/configs/e4b137fa.js +0 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js.map +1 -1
- package/dist/modules.d.ts +4 -2
- package/dist/modules.js +47 -37
- package/dist/modules.js.map +1 -1
- package/dist/{types-D227zLeg.d.ts → types-CAUUIuJR.d.ts} +13 -1
- package/package.json +1 -1
package/dist/configs/e4b137fa.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as ConfigOptions, F as FlatConfigArray, O as OxlintConfigOptions, R as RuleSeverity,
|
|
2
|
-
export {
|
|
1
|
+
import { C as ConfigOptions, F as FlatConfigArray, O as OxlintConfigOptions, a as OxlintConfigResult, R as RuleSeverity, b as RuleOptions } from './types-CAUUIuJR.js';
|
|
2
|
+
export { c as RuleScope } from './types-CAUUIuJR.js';
|
|
3
3
|
import 'eslint';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -11,7 +11,7 @@ declare function getEslintConfig(opts?: ConfigOptions): Promise<FlatConfigArray>
|
|
|
11
11
|
* Loads a pre-generated OxLint config from the hashed JSON file.
|
|
12
12
|
* Only `react`, `node`, and `ai` flags are relevant — `oxlint` is ignored.
|
|
13
13
|
*/
|
|
14
|
-
declare function getOxlintConfig(opts?: OxlintConfigOptions):
|
|
14
|
+
declare function getOxlintConfig(opts?: OxlintConfigOptions): OxlintConfigResult;
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Change the severity of a rule across all config blocks, preserving options.
|
|
@@ -49,4 +49,4 @@ declare function bitmaskToHash(mask: number): string;
|
|
|
49
49
|
/** Convenience: options → filename (without path prefix). */
|
|
50
50
|
declare function optionsToFilename(opts: ConfigOptions): string;
|
|
51
51
|
|
|
52
|
-
export { ConfigOptions, FlatConfigArray, OxlintConfigOptions, RuleOptions, RuleSeverity, addRule, bitmaskToHash, configureRule, disableAllRulesBut, disableRule, getEslintConfig, getOxlintConfig, optionsToBitmask, optionsToFilename, setRuleSeverity };
|
|
52
|
+
export { ConfigOptions, FlatConfigArray, OxlintConfigOptions, OxlintConfigResult, RuleOptions, RuleSeverity, addRule, bitmaskToHash, configureRule, disableAllRulesBut, disableRule, getEslintConfig, getOxlintConfig, optionsToBitmask, optionsToFilename, setRuleSeverity };
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loader.ts","../src/hash.ts","../src/api/rule-helpers.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename -- Paths are computed from deterministic hashes in dist/, not from user input. */\nimport { readFileSync } from \"node:fs\"\nimport path from \"node:path\"\n\nimport type { ConfigOptions, FlatConfigArray, OxlintConfigOptions } from \"./types\"\n\nimport { optionsToFilename, oxlintOptionsToFilename } from \"./hash\"\n\n/**\n * Loads a pre-generated ESLint config by dynamically importing the hashed file.\n * The hash is computed from the options using the same algorithm as the build.\n */\nexport async function getEslintConfig(\n opts: ConfigOptions = {},\n): Promise<FlatConfigArray> {\n const filename = optionsToFilename(opts)\n const dirname = import.meta.dirname\n const configPath = path.join(dirname, \"configs\", filename)\n\n try {\n const module = (await import(\n /* webpackIgnore: true */\n `${configPath}?${Date.now()}`\n )) as { default: FlatConfigArray }\n return module.default\n } catch {\n throw new Error(\n `eslint-config-setup: No pre-generated config found for options ${JSON.stringify(opts)}. ` +\n `Expected file: configs/${filename}. Run \"npm run generate\" in the package to build configs.`,\n )\n }\n}\n\n/**\n * Loads a pre-generated OxLint config from the hashed JSON file.\n * Only `react`, `node`, and `ai` flags are relevant — `oxlint` is ignored.\n */\nexport function getOxlintConfig(\n opts: OxlintConfigOptions = {},\n): unknown {\n const filename = oxlintOptionsToFilename(opts)\n const dirname = import.meta.dirname\n const configPath = path.join(dirname, \"oxlint-configs\", filename)\n\n try {\n const content = readFileSync(configPath, \"utf8\")\n return JSON.parse(content) as unknown\n } catch {\n throw new Error(\n `eslint-config-setup: No pre-generated OxLint config found for options ${JSON.stringify(opts)}. ` +\n `Expected file: oxlint-configs/${filename}. Run \"npm run generate\" in the package to build configs.`,\n )\n }\n}\n","import { createHash } from \"node:crypto\"\n\nimport type { ConfigOptions, OxlintConfigOptions } from \"./types\"\n\n/**\n * Converts config options to a deterministic bitmask.\n * Bit order is fixed and must never change (would break published configs).\n */\nexport function optionsToBitmask(opts: ConfigOptions): number {\n let mask = 0\n if (opts.react) mask |= 1 << 0\n if (opts.node) mask |= 1 << 1\n if (opts.ai) mask |= 1 << 2\n if (opts.oxlint) mask |= 1 << 3\n return mask\n}\n\n/**\n * Converts a bitmask to a short deterministic hash (8 hex chars).\n * The same hash is produced at build-time (generate) and run-time (getConfig).\n */\nexport function bitmaskToHash(mask: number): string {\n const input = `effective-eslint-config:${mask}`\n return createHash(\"sha1\").update(input).digest(\"hex\").slice(0, 8)\n}\n\n/** Convenience: options → filename (without path prefix). */\nexport function optionsToFilename(opts: ConfigOptions): string {\n return `${bitmaskToHash(optionsToBitmask(opts))}.js`\n}\n\n/** Total number of permutations (2^4 = 16). */\nexport const TOTAL_PERMUTATIONS = 16\n\n/** Iterate all possible option combinations. */\nexport function* allPermutations(): Generator<ConfigOptions> {\n for (let mask = 0; mask < TOTAL_PERMUTATIONS; mask++) {\n yield {\n react: Boolean(mask & (1 << 0)),\n node: Boolean(mask & (1 << 1)),\n ai: Boolean(mask & (1 << 2)),\n oxlint: Boolean(mask & (1 << 3)),\n }\n }\n}\n\n// --- OxLint config permutations (3 flags → 8 combos) ---\n\n/** Converts OxLint-relevant options to a 3-bit bitmask (react, node, ai). */\nexport function oxlintOptionsToBitmask(opts: OxlintConfigOptions): number {\n let mask = 0\n if (opts.react) mask |= 1 << 0\n if (opts.node) mask |= 1 << 1\n if (opts.ai) mask |= 1 << 2\n return mask\n}\n\n/** Deterministic hash for OxLint configs (different salt to avoid collisions). */\nexport function oxlintBitmaskToHash(mask: number): string {\n const input = `eslint-config-setup-oxlint:${mask}`\n return createHash(\"sha1\").update(input).digest(\"hex\").slice(0, 8)\n}\n\n/** OxLint options → filename (without path prefix). */\nexport function oxlintOptionsToFilename(opts: OxlintConfigOptions): string {\n return `${oxlintBitmaskToHash(oxlintOptionsToBitmask(opts))}.json`\n}\n\n/** Total number of OxLint permutations (2^3 = 8). */\nexport const TOTAL_OXLINT_PERMUTATIONS = 8\n\n/** Iterate all OxLint option combinations. */\nexport function* allOxlintPermutations(): Generator<OxlintConfigOptions> {\n for (let mask = 0; mask < TOTAL_OXLINT_PERMUTATIONS; mask++) {\n yield {\n react: Boolean(mask & (1 << 0)),\n node: Boolean(mask & (1 << 1)),\n ai: Boolean(mask & (1 << 2)),\n }\n }\n}\n","/* eslint-disable max-params, complexity -- Public API: config + ruleName + severity + options is the natural signature. Options objects would hurt ergonomics for one-liner calls. */\nimport type { Linter } from \"eslint\"\n\nimport type {\n FlatConfigArray,\n RuleOptions,\n RuleSeverity,\n} from \"../types\"\n\nconst CONFIG_PREFIX = \"eslint-config-setup/\"\n\n/** Maps user-facing scope names to config block name segments. */\nconst SCOPE_TO_BLOCK: Record<string, string> = {\n configs: \"config-files\",\n}\n\n/**\n * Check if a config block matches a given scope.\n * A block matches if its name is `eslint-config-setup/{segment}` or starts with `eslint-config-setup/{segment}-`.\n */\nfunction blockMatchesScope(\n block: Linter.Config,\n scope: string,\n): boolean {\n const name = block.name\n if (name == null) return false\n const segment = SCOPE_TO_BLOCK[scope] ?? scope\n const target = `${CONFIG_PREFIX}${segment}`\n return name === target || name.startsWith(`${target}-`)\n}\n\n/**\n * Change the severity of a rule across all config blocks, preserving options.\n */\nexport function setRuleSeverity(\n config: FlatConfigArray,\n ruleName: string,\n severity: RuleSeverity,\n options?: RuleOptions,\n): void {\n for (const block of config) {\n if (options?.scope !== undefined && !blockMatchesScope(block, options.scope)) continue\n if (block.rules?.[ruleName] == null) continue\n\n const current = block.rules[ruleName]\n if (Array.isArray(current)) {\n block.rules[ruleName] = [severity, ...current.slice(1)] as Linter.RuleEntry\n } else {\n block.rules[ruleName] = severity\n }\n }\n}\n\n/**\n * Update the options of a rule across all config blocks, preserving severity.\n */\nexport function configureRule(\n config: FlatConfigArray,\n ruleName: string,\n options: unknown[],\n ruleOptions?: RuleOptions,\n): void {\n for (const block of config) {\n if (ruleOptions?.scope !== undefined && !blockMatchesScope(block, ruleOptions.scope))\n continue\n if (block.rules?.[ruleName] == null) continue\n\n const current = block.rules[ruleName]\n const severity = Array.isArray(current) ? current[0] : current\n block.rules[ruleName] = [severity, ...options] as Linter.RuleEntry\n }\n}\n\n/**\n * Completely disable a rule across all config blocks.\n * With scope: disables in the first matching block (creates entry if needed).\n */\nexport function disableRule(\n config: FlatConfigArray,\n ruleName: string,\n options?: RuleOptions,\n): void {\n if (options?.scope != null) {\n const { scope } = options\n const block = config.find((b) => blockMatchesScope(b, scope))\n if (!block) return\n block.rules ??= {}\n block.rules[ruleName] = \"off\"\n return\n }\n\n for (const block of config) {\n if (block.rules?.[ruleName] == null) continue\n block.rules[ruleName] = \"off\"\n }\n}\n\n/**\n * Add a new rule to the first (base) config block.\n * With scope: adds to the first matching block instead.\n */\nexport function addRule(\n config: FlatConfigArray,\n ruleName: string,\n severity: RuleSeverity,\n options?: RuleOptions | unknown[],\n ruleOptions?: RuleOptions,\n): void {\n // Handle overloaded signatures: addRule(config, rule, severity, options?, ruleOptions?)\n // When options is a plain object with scope, it's actually ruleOptions\n let ruleOpts: undefined | unknown[]\n let scopeOpts: RuleOptions | undefined\n\n if (Array.isArray(options)) {\n ruleOpts = options\n scopeOpts = ruleOptions\n } else if (options && typeof options === \"object\" && \"scope\" in options) {\n scopeOpts = options\n } else if (options === undefined) {\n scopeOpts = ruleOptions\n }\n\n let target: Linter.Config | undefined\n if (scopeOpts?.scope != null) {\n const { scope } = scopeOpts\n target = config.find((b) => blockMatchesScope(b, scope))\n } else {\n target = config[0]\n }\n\n if (!target) return\n\n target.rules ??= {}\n target.rules[ruleName] = ruleOpts\n ? ([severity, ...ruleOpts] as Linter.RuleEntry)\n : severity\n}\n\n/**\n * Disable all rules except the specified one — useful for debugging.\n */\nexport function disableAllRulesBut(\n config: FlatConfigArray,\n keepRuleName: string,\n): void {\n for (const block of config) {\n if (!block.rules) continue\n for (const ruleName of Object.keys(block.rules)) {\n if (ruleName !== keepRuleName) {\n block.rules[ruleName] = \"off\"\n }\n }\n }\n}\n"],"mappings":";AACA,SAAS,oBAAoB;AAC7B,OAAO,UAAU;;;ACFjB,SAAS,kBAAkB;AAQpB,SAAS,iBAAiB,MAA6B;AAC5D,MAAI,OAAO;AACX,MAAI,KAAK,MAAO,SAAQ,KAAK;AAC7B,MAAI,KAAK,KAAM,SAAQ,KAAK;AAC5B,MAAI,KAAK,GAAI,SAAQ,KAAK;AAC1B,MAAI,KAAK,OAAQ,SAAQ,KAAK;AAC9B,SAAO;AACT;AAMO,SAAS,cAAc,MAAsB;AAClD,QAAM,QAAQ,2BAA2B,IAAI;AAC7C,SAAO,WAAW,MAAM,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK,EAAE,MAAM,GAAG,CAAC;AAClE;AAGO,SAAS,kBAAkB,MAA6B;AAC7D,SAAO,GAAG,cAAc,iBAAiB,IAAI,CAAC,CAAC;AACjD;AAoBO,SAAS,uBAAuB,MAAmC;AACxE,M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AM,QAAQ,QAAQ,KAAK,KAAM;AACrC,UAAM,MAAM,QAAQ,IAAI;AAAA,EAC1B;AACF;AAMO,SAAS,QACd,QACA,UACA,UACA,SACA,aACM;AAGN,MAAI;AACJ,MAAI;AAEJ,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,eAAW;AACX,gBAAY;AAAA,EACd,WAAW,WAAW,OAAO,YAAY,YAAY,WAAW,SAAS;AACvE,gBAAY;AAAA,EACd,WAAW,YAAY,QAAW;AAChC,gBAAY;AAAA,EACd;AAEA,MAAI;AACJ,MAAI,WAAW,SAAS,MAAM;AAC5B,UAAM,EAAE,MAAM,IAAI;AAClB,aAAS,OAAO,KAAK,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAAA,EACzD,OAAO;AACL,aAAS,OAAO,CAAC;AAAA,EACnB;AAEA,MAAI,CAAC,OAAQ;AAEb,SAAO,UAAU,CAAC;AAClB,SAAO,MAAM,QAAQ,IAAI,WACpB,CAAC,UAAU,GAAG,QAAQ,IACvB;AACN;AAKO,SAAS,mBACd,QACA,cACM;AACN,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC,MAAM,MAAO;AAClB,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAC/C,UAAI,aAAa,cAAc;AAC7B,cAAM,MAAM,QAAQ,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/loader.ts","../src/hash.ts","../src/api/rule-helpers.ts"],"sourcesContent":["/* eslint-disable security/detect-non-literal-fs-filename -- Paths are computed from deterministic hashes in dist/, not from user input. */\nimport { readFileSync } from \"node:fs\"\nimport path from \"node:path\"\n\nimport type { ConfigOptions, FlatConfigArray, OxlintConfigOptions, OxlintConfigResult } from \"./types\"\n\nimport { optionsToFilename, oxlintOptionsToFilename } from \"./hash\"\n\n/**\n * Loads a pre-generated ESLint config by dynamically importing the hashed file.\n * The hash is computed from the options using the same algorithm as the build.\n */\nexport async function getEslintConfig(\n opts: ConfigOptions = {},\n): Promise<FlatConfigArray> {\n const filename = optionsToFilename(opts)\n const dirname = import.meta.dirname\n const configPath = path.join(dirname, \"configs\", filename)\n\n try {\n const module = (await import(\n /* webpackIgnore: true */\n `${configPath}?${Date.now()}`\n )) as { default: FlatConfigArray }\n return module.default\n } catch {\n throw new Error(\n `eslint-config-setup: No pre-generated config found for options ${JSON.stringify(opts)}. ` +\n `Expected file: configs/${filename}. Run \"npm run generate\" in the package to build configs.`,\n )\n }\n}\n\n/**\n * Loads a pre-generated OxLint config from the hashed JSON file.\n * Only `react`, `node`, and `ai` flags are relevant — `oxlint` is ignored.\n */\nexport function getOxlintConfig(\n opts: OxlintConfigOptions = {},\n): OxlintConfigResult {\n const filename = oxlintOptionsToFilename(opts)\n const dirname = import.meta.dirname\n const configPath = path.join(dirname, \"oxlint-configs\", filename)\n\n try {\n const content = readFileSync(configPath, \"utf8\")\n return JSON.parse(content) as OxlintConfigResult\n } catch {\n throw new Error(\n `eslint-config-setup: No pre-generated OxLint config found for options ${JSON.stringify(opts)}. ` +\n `Expected file: oxlint-configs/${filename}. Run \"npm run generate\" in the package to build configs.`,\n )\n }\n}\n","import { createHash } from \"node:crypto\"\n\nimport type { ConfigOptions, OxlintConfigOptions } from \"./types\"\n\n/**\n * Converts config options to a deterministic bitmask.\n * Bit order is fixed and must never change (would break published configs).\n */\nexport function optionsToBitmask(opts: ConfigOptions): number {\n let mask = 0\n if (opts.react) mask |= 1 << 0\n if (opts.node) mask |= 1 << 1\n if (opts.ai) mask |= 1 << 2\n if (opts.oxlint) mask |= 1 << 3\n return mask\n}\n\n/**\n * Converts a bitmask to a short deterministic hash (8 hex chars).\n * The same hash is produced at build-time (generate) and run-time (getConfig).\n */\nexport function bitmaskToHash(mask: number): string {\n const input = `effective-eslint-config:${mask}`\n return createHash(\"sha1\").update(input).digest(\"hex\").slice(0, 8)\n}\n\n/** Convenience: options → filename (without path prefix). */\nexport function optionsToFilename(opts: ConfigOptions): string {\n return `${bitmaskToHash(optionsToBitmask(opts))}.js`\n}\n\n/** Total number of permutations (2^4 = 16). */\nexport const TOTAL_PERMUTATIONS = 16\n\n/** Iterate all possible option combinations. */\nexport function* allPermutations(): Generator<ConfigOptions> {\n for (let mask = 0; mask < TOTAL_PERMUTATIONS; mask++) {\n yield {\n react: Boolean(mask & (1 << 0)),\n node: Boolean(mask & (1 << 1)),\n ai: Boolean(mask & (1 << 2)),\n oxlint: Boolean(mask & (1 << 3)),\n }\n }\n}\n\n// --- OxLint config permutations (3 flags → 8 combos) ---\n\n/** Converts OxLint-relevant options to a 3-bit bitmask (react, node, ai). */\nexport function oxlintOptionsToBitmask(opts: OxlintConfigOptions): number {\n let mask = 0\n if (opts.react) mask |= 1 << 0\n if (opts.node) mask |= 1 << 1\n if (opts.ai) mask |= 1 << 2\n return mask\n}\n\n/** Deterministic hash for OxLint configs (different salt to avoid collisions). */\nexport function oxlintBitmaskToHash(mask: number): string {\n const input = `eslint-config-setup-oxlint:${mask}`\n return createHash(\"sha1\").update(input).digest(\"hex\").slice(0, 8)\n}\n\n/** OxLint options → filename (without path prefix). */\nexport function oxlintOptionsToFilename(opts: OxlintConfigOptions): string {\n return `${oxlintBitmaskToHash(oxlintOptionsToBitmask(opts))}.json`\n}\n\n/** Total number of OxLint permutations (2^3 = 8). */\nexport const TOTAL_OXLINT_PERMUTATIONS = 8\n\n/** Iterate all OxLint option combinations. */\nexport function* allOxlintPermutations(): Generator<OxlintConfigOptions> {\n for (let mask = 0; mask < TOTAL_OXLINT_PERMUTATIONS; mask++) {\n yield {\n react: Boolean(mask & (1 << 0)),\n node: Boolean(mask & (1 << 1)),\n ai: Boolean(mask & (1 << 2)),\n }\n }\n}\n","/* eslint-disable max-params, complexity -- Public API: config + ruleName + severity + options is the natural signature. Options objects would hurt ergonomics for one-liner calls. */\nimport type { Linter } from \"eslint\"\n\nimport type {\n FlatConfigArray,\n RuleOptions,\n RuleSeverity,\n} from \"../types\"\n\nconst CONFIG_PREFIX = \"eslint-config-setup/\"\n\n/** Maps user-facing scope names to config block name segments. */\nconst SCOPE_TO_BLOCK: Record<string, string> = {\n configs: \"config-files\",\n}\n\n/**\n * Check if a config block matches a given scope.\n * A block matches if its name is `eslint-config-setup/{segment}` or starts with `eslint-config-setup/{segment}-`.\n */\nfunction blockMatchesScope(\n block: Linter.Config,\n scope: string,\n): boolean {\n const name = block.name\n if (name == null) return false\n const segment = SCOPE_TO_BLOCK[scope] ?? scope\n const target = `${CONFIG_PREFIX}${segment}`\n return name === target || name.startsWith(`${target}-`)\n}\n\n/**\n * Change the severity of a rule across all config blocks, preserving options.\n */\nexport function setRuleSeverity(\n config: FlatConfigArray,\n ruleName: string,\n severity: RuleSeverity,\n options?: RuleOptions,\n): void {\n for (const block of config) {\n if (options?.scope !== undefined && !blockMatchesScope(block, options.scope)) continue\n if (block.rules?.[ruleName] == null) continue\n\n const current = block.rules[ruleName]\n if (Array.isArray(current)) {\n block.rules[ruleName] = [severity, ...current.slice(1)] as Linter.RuleEntry\n } else {\n block.rules[ruleName] = severity\n }\n }\n}\n\n/**\n * Update the options of a rule across all config blocks, preserving severity.\n */\nexport function configureRule(\n config: FlatConfigArray,\n ruleName: string,\n options: unknown[],\n ruleOptions?: RuleOptions,\n): void {\n for (const block of config) {\n if (ruleOptions?.scope !== undefined && !blockMatchesScope(block, ruleOptions.scope))\n continue\n if (block.rules?.[ruleName] == null) continue\n\n const current = block.rules[ruleName]\n const severity = Array.isArray(current) ? current[0] : current\n block.rules[ruleName] = [severity, ...options] as Linter.RuleEntry\n }\n}\n\n/**\n * Completely disable a rule across all config blocks.\n * With scope: disables in the first matching block (creates entry if needed).\n */\nexport function disableRule(\n config: FlatConfigArray,\n ruleName: string,\n options?: RuleOptions,\n): void {\n if (options?.scope != null) {\n const { scope } = options\n const block = config.find((b) => blockMatchesScope(b, scope))\n if (!block) return\n block.rules ??= {}\n block.rules[ruleName] = \"off\"\n return\n }\n\n for (const block of config) {\n if (block.rules?.[ruleName] == null) continue\n block.rules[ruleName] = \"off\"\n }\n}\n\n/**\n * Add a new rule to the first (base) config block.\n * With scope: adds to the first matching block instead.\n */\nexport function addRule(\n config: FlatConfigArray,\n ruleName: string,\n severity: RuleSeverity,\n options?: RuleOptions | unknown[],\n ruleOptions?: RuleOptions,\n): void {\n // Handle overloaded signatures: addRule(config, rule, severity, options?, ruleOptions?)\n // When options is a plain object with scope, it's actually ruleOptions\n let ruleOpts: undefined | unknown[]\n let scopeOpts: RuleOptions | undefined\n\n if (Array.isArray(options)) {\n ruleOpts = options\n scopeOpts = ruleOptions\n } else if (options && typeof options === \"object\" && \"scope\" in options) {\n scopeOpts = options\n } else if (options === undefined) {\n scopeOpts = ruleOptions\n }\n\n let target: Linter.Config | undefined\n if (scopeOpts?.scope != null) {\n const { scope } = scopeOpts\n target = config.find((b) => blockMatchesScope(b, scope))\n } else {\n target = config[0]\n }\n\n if (!target) return\n\n target.rules ??= {}\n target.rules[ruleName] = ruleOpts\n ? ([severity, ...ruleOpts] as Linter.RuleEntry)\n : severity\n}\n\n/**\n * Disable all rules except the specified one — useful for debugging.\n */\nexport function disableAllRulesBut(\n config: FlatConfigArray,\n keepRuleName: string,\n): void {\n for (const block of config) {\n if (!block.rules) continue\n for (const ruleName of Object.keys(block.rules)) {\n if (ruleName !== keepRuleName) {\n block.rules[ruleName] = \"off\"\n }\n }\n }\n}\n"],"mappings":";AACA,SAAS,oBAAoB;AAC7B,OAAO,UAAU;;;ACFjB,SAAS,kBAAkB;AAQpB,SAAS,iBAAiB,MAA6B;AAC5D,MAAI,OAAO;AACX,MAAI,KAAK,MAAO,SAAQ,KAAK;AAC7B,MAAI,KAAK,KAAM,SAAQ,KAAK;AAC5B,MAAI,KAAK,GAAI,SAAQ,KAAK;AAC1B,MAAI,KAAK,OAAQ,SAAQ,KAAK;AAC9B,SAAO;AACT;AAMO,SAAS,cAAc,MAAsB;AAClD,QAAM,QAAQ,2BAA2B,IAAI;AAC7C,SAAO,WAAW,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AQ,OAAO,KAAK,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAC5D,QAAI,CAAC,MAAO;AACZ,UAAM,UAAU,CAAC;AACjB,UAAM,MAAM,QAAQ,IAAI;AACxB;AAAA,EACF;AAEA,aAAW,SAAS,QAAQ;AAC1B,QAAI,MAAM,QAAQ,QAAQ,KAAK,KAAM;AACrC,UAAM,MAAM,QAAQ,IAAI;AAAA,EAC1B;AACF;AAMO,SAAS,QACd,QACA,UACA,UACA,SACA,aACM;AAGN,MAAI;AACJ,MAAI;AAEJ,MAAI,MAAM,QAAQ,OAAO,GAAG;AAC1B,eAAW;AACX,gBAAY;AAAA,EACd,WAAW,WAAW,OAAO,YAAY,YAAY,WAAW,SAAS;AACvE,gBAAY;AAAA,EACd,WAAW,YAAY,QAAW;AAChC,gBAAY;AAAA,EACd;AAEA,MAAI;AACJ,MAAI,WAAW,SAAS,MAAM;AAC5B,UAAM,EAAE,MAAM,IAAI;AAClB,aAAS,OAAO,KAAK,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAAA,EACzD,OAAO;AACL,aAAS,OAAO,CAAC;AAAA,EACnB;AAEA,MAAI,CAAC,OAAQ;AAEb,SAAO,UAAU,CAAC;AAClB,SAAO,MAAM,QAAQ,IAAI,WACpB,CAAC,UAAU,GAAG,QAAQ,IACvB;AACN;AAKO,SAAS,mBACd,QACA,cACM;AACN,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC,MAAM,MAAO;AAClB,eAAW,YAAY,OAAO,KAAK,MAAM,KAAK,GAAG;AAC/C,UAAI,aAAa,cAAc;AAC7B,cAAM,MAAM,QAAQ,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/modules.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as FlatConfigArray, C as ConfigOptions } from './types-
|
|
1
|
+
import { F as FlatConfigArray, C as ConfigOptions } from './types-CAUUIuJR.js';
|
|
2
2
|
import 'eslint';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -13,7 +13,9 @@ import 'eslint';
|
|
|
13
13
|
* and tightened beyond their defaults for AI-generated code.
|
|
14
14
|
* @see ADR-0006: docs/adr/0006-ai-mode-as-dedicated-flag.md
|
|
15
15
|
*/
|
|
16
|
-
declare function aiConfig(
|
|
16
|
+
declare function aiConfig(opts?: {
|
|
17
|
+
react?: boolean;
|
|
18
|
+
}): FlatConfigArray;
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Base ESLint config — extends `eslint.configs.recommended` with additional
|
package/dist/modules.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/configs/ai.ts
|
|
2
|
-
function aiConfig() {
|
|
2
|
+
function aiConfig(opts) {
|
|
3
|
+
const isReact = opts?.react ?? false;
|
|
3
4
|
const configs = [
|
|
4
5
|
{
|
|
5
6
|
name: "eslint-config-setup/ai-structural",
|
|
@@ -136,12 +137,29 @@ function aiConfig() {
|
|
|
136
137
|
// https://typescript-eslint.io/rules/naming-convention
|
|
137
138
|
"@typescript-eslint/naming-convention": [
|
|
138
139
|
"error",
|
|
140
|
+
{
|
|
141
|
+
selector: "variable",
|
|
142
|
+
format: isReact ? ["strictCamelCase", "UPPER_CASE", "StrictPascalCase"] : ["strictCamelCase", "UPPER_CASE"],
|
|
143
|
+
leadingUnderscore: "allowSingleOrDouble",
|
|
144
|
+
trailingUnderscore: "allow",
|
|
145
|
+
filter: { regex: "[- ]", match: false }
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
selector: "function",
|
|
149
|
+
format: isReact ? ["strictCamelCase", "StrictPascalCase"] : ["strictCamelCase"]
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
selector: "parameter",
|
|
153
|
+
format: ["strictCamelCase"],
|
|
154
|
+
leadingUnderscore: "allow"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
selector: "import",
|
|
158
|
+
format: ["strictCamelCase", "StrictPascalCase", "UPPER_CASE"]
|
|
159
|
+
},
|
|
139
160
|
{
|
|
140
161
|
selector: [
|
|
141
|
-
"variable",
|
|
142
|
-
"function",
|
|
143
162
|
"classProperty",
|
|
144
|
-
"objectLiteralProperty",
|
|
145
163
|
"parameterProperty",
|
|
146
164
|
"classMethod",
|
|
147
165
|
"objectLiteralMethod",
|
|
@@ -153,6 +171,10 @@ function aiConfig() {
|
|
|
153
171
|
trailingUnderscore: "allow",
|
|
154
172
|
filter: { regex: "[- ]", match: false }
|
|
155
173
|
},
|
|
174
|
+
{
|
|
175
|
+
selector: ["objectLiteralProperty", "typeProperty"],
|
|
176
|
+
format: null
|
|
177
|
+
},
|
|
156
178
|
{
|
|
157
179
|
selector: "typeLike",
|
|
158
180
|
format: ["StrictPascalCase"]
|
|
@@ -1776,9 +1798,11 @@ function unicornConfig() {
|
|
|
1776
1798
|
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-type-error.md
|
|
1777
1799
|
"unicorn/prefer-type-error": "error",
|
|
1778
1800
|
// ── Regex ─────────────────────────────────────────────────────
|
|
1779
|
-
//
|
|
1780
|
-
//
|
|
1781
|
-
|
|
1801
|
+
// Disabled — conflicts with regexp/strict from eslint-plugin-regexp.
|
|
1802
|
+
// Both rules auto-fix regex escaping but disagree on whether characters
|
|
1803
|
+
// like { } ] should be escaped, causing circular fixes.
|
|
1804
|
+
// regexp/strict is the more thorough rule, so we defer to it.
|
|
1805
|
+
"unicorn/better-regex": "off",
|
|
1782
1806
|
// ── Misc ──────────────────────────────────────────────────────
|
|
1783
1807
|
// Enforce `error` name in catch blocks — consistent naming
|
|
1784
1808
|
// https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/catch-error-name.md
|
|
@@ -2264,40 +2288,26 @@ function standardComplexity() {
|
|
|
2264
2288
|
import oxlintPlugin from "eslint-plugin-oxlint";
|
|
2265
2289
|
function oxlintIntegration(opts) {
|
|
2266
2290
|
const typedPlugin = oxlintPlugin;
|
|
2267
|
-
const configs = [
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2291
|
+
const configs = [];
|
|
2292
|
+
const add = (configName, blockName) => {
|
|
2293
|
+
const raw = typedPlugin.configs[configName];
|
|
2294
|
+
const items = Array.isArray(raw) ? raw : [raw];
|
|
2295
|
+
for (const item of items) {
|
|
2296
|
+
configs.push({ name: `eslint-config-setup/${blockName}`, ...item });
|
|
2271
2297
|
}
|
|
2272
|
-
|
|
2298
|
+
};
|
|
2299
|
+
add("flat/recommended", "oxlint");
|
|
2273
2300
|
if (opts.react) {
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
...typedPlugin.configs["flat/react"]
|
|
2277
|
-
}, {
|
|
2278
|
-
name: "eslint-config-setup/oxlint-jsx-a11y",
|
|
2279
|
-
...typedPlugin.configs["flat/jsx-a11y"]
|
|
2280
|
-
});
|
|
2301
|
+
add("flat/react", "oxlint-react");
|
|
2302
|
+
add("flat/jsx-a11y", "oxlint-jsx-a11y");
|
|
2281
2303
|
}
|
|
2282
2304
|
if (opts.node) {
|
|
2283
|
-
|
|
2284
|
-
name: "eslint-config-setup/oxlint-node",
|
|
2285
|
-
...typedPlugin.configs["flat/node"]
|
|
2286
|
-
});
|
|
2305
|
+
add("flat/node", "oxlint-node");
|
|
2287
2306
|
}
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
name: "eslint-config-setup/oxlint-unicorn",
|
|
2293
|
-
...typedPlugin.configs["flat/unicorn"]
|
|
2294
|
-
}, {
|
|
2295
|
-
name: "eslint-config-setup/oxlint-import",
|
|
2296
|
-
...typedPlugin.configs["flat/import"]
|
|
2297
|
-
}, {
|
|
2298
|
-
name: "eslint-config-setup/oxlint-jsdoc",
|
|
2299
|
-
...typedPlugin.configs["flat/jsdoc"]
|
|
2300
|
-
});
|
|
2307
|
+
add("flat/typescript", "oxlint-typescript");
|
|
2308
|
+
add("flat/unicorn", "oxlint-unicorn");
|
|
2309
|
+
add("flat/import", "oxlint-import");
|
|
2310
|
+
add("flat/jsdoc", "oxlint-jsdoc");
|
|
2301
2311
|
return configs;
|
|
2302
2312
|
}
|
|
2303
2313
|
|
|
@@ -2347,7 +2357,7 @@ function composeConfig(opts) {
|
|
|
2347
2357
|
config.push(...reactEffectConfig());
|
|
2348
2358
|
}
|
|
2349
2359
|
if (opts.ai) {
|
|
2350
|
-
config.push(...aiConfig());
|
|
2360
|
+
config.push(...aiConfig({ react: opts.react }));
|
|
2351
2361
|
config.push(...perfectionistAiConfig());
|
|
2352
2362
|
config.push(...packageJsonAiConfig());
|
|
2353
2363
|
}
|