hook-o-gnese 0.0.6 → 0.0.8

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/README.md CHANGED
@@ -62,7 +62,7 @@ No linter setup required. Works in any project. Outputs stylish, JSON, SARIF
62
62
  ```bash
63
63
  npx hook-o-gnese ./src
64
64
  npx hook-o-gnese ./src --format=sarif > report.sarif
65
- npx hook-o-gnese ./src --type-aware # enables custom-hook-depth
65
+ npx hook-o-gnese ./src --type-aware # enables custom-hook-depth (needs `typescript` in your project)
66
66
  ```
67
67
 
68
68
  Add a `.hookogneserc.json` if you want to tune thresholds:
package/dist/cli.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env node
2
- import { n as lintFiles } from "./engine-DJFFKwTZ.mjs";
2
+ import { n as isTypescriptAvailable } from "./registry-YXM4yhf2.mjs";
3
+ import { n as lintFiles } from "./engine-DKI7WYuw.mjs";
3
4
  import { parseArgs } from "node:util";
4
5
  import { readFile } from "node:fs/promises";
5
6
  import { globby } from "globby";
@@ -134,7 +135,8 @@ Usage:
134
135
  Options:
135
136
  --format=<fmt> stylish (default) | json | sarif | github
136
137
  --config=<path> path to .hookogneserc.json
137
- --type-aware enable custom-hook-depth (slower, uses TS Compiler API)
138
+ --type-aware enable custom-hook-depth (slower, uses TS Compiler API).
139
+ Requires 'typescript' installed in your project.
138
140
  --rule=<id>=<sev> override rule severity (off|warn|error). Repeatable.
139
141
  --help, -h show this message
140
142
 
@@ -155,6 +157,10 @@ async function runCli(opts, io) {
155
157
  }
156
158
  const { engine, ignore } = await loadConfig(opts.cwd, opts.config, io.readTextFile);
157
159
  if (opts.typeAware) engine.typeAware = true;
160
+ if (engine.typeAware && !isTypescriptAvailable(opts.cwd)) {
161
+ io.writeStderr("warning: type-aware rules require the 'typescript' package to be installed in your project. Skipping type-aware rules. Install with: npm i -D typescript@>=6\n");
162
+ engine.typeAware = false;
163
+ }
158
164
  const finalEngine = applyCliRuleOverrides(engine, opts.ruleOverrides);
159
165
  const files = await globby(opts.paths, {
160
166
  ignore: [...DEFAULT_IGNORE, ...ignore],
package/dist/cli.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.mjs","names":["jsonFmt"],"sources":["../src/config.ts","../src/formatters/stylish.ts","../src/formatters/json.ts","../src/formatters/sarif.ts","../src/formatters/github.ts","../src/cli-core.ts","../src/cli.node.ts"],"sourcesContent":["import type { EngineConfig, Severity } from \"./engine.ts\";\n\nconst DEFAULT_RULES: Record<string, { severity: Severity; options?: unknown }> =\n {\n \"hook-o-gnese/no-fat-effects\": { severity: \"warn\" },\n \"hook-o-gnese/state-scatter\": { severity: \"warn\" },\n \"hook-o-gnese/hook-coupling\": { severity: \"error\" },\n \"hook-o-gnese/custom-hook-depth\": {\n severity: \"warn\",\n options: { maxDepth: 3 },\n },\n };\n\nexport const DEFAULT_IGNORE = [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/.next/**\",\n \"**/.cache/**\",\n];\n\ninterface FileConfig {\n rules?: Record<string, Severity | [Severity, unknown]>;\n ignore?: string[];\n typeAware?: boolean;\n}\n\nexport type ReadTextFile = (path: string) => Promise<string>;\n\nexport async function loadConfig(\n cwd: string,\n configPath: string | undefined,\n readTextFile: ReadTextFile,\n): Promise<{ engine: EngineConfig; ignore: string[] }> {\n const candidates = configPath\n ? [configPath]\n : [`${cwd.replace(/\\/$/, \"\")}/.hookogneserc.json`];\n\n let fileCfg: FileConfig = {};\n for (const c of candidates) {\n try {\n const text = await readTextFile(c);\n fileCfg = JSON.parse(text);\n break;\n } catch {\n // not found — fine, use defaults\n }\n }\n\n const rules: EngineConfig[\"rules\"] = { ...DEFAULT_RULES };\n if (fileCfg.rules) {\n for (const [id, spec] of Object.entries(fileCfg.rules)) {\n if (Array.isArray(spec)) {\n rules[id] = { severity: spec[0], options: spec[1] };\n } else {\n rules[id] = { severity: spec };\n }\n }\n }\n\n return {\n engine: {\n rules,\n cwd,\n typeAware: fileCfg.typeAware ?? false,\n },\n ignore: fileCfg.ignore ?? DEFAULT_IGNORE,\n };\n}\n\nexport function applyCliRuleOverrides(\n cfg: EngineConfig,\n overrides: Array<{ id: string; severity: Severity }>,\n): EngineConfig {\n const rules = { ...cfg.rules };\n for (const o of overrides) {\n rules[o.id] = {\n ...(rules[o.id] ?? { severity: \"off\" }),\n severity: o.severity,\n };\n }\n return { ...cfg, rules };\n}\n","import type { Formatter } from \"./types.ts\";\n\nexport const stylish: Formatter = (\n { diagnostics, filesScanned, durationMs },\n) => {\n if (diagnostics.length === 0) {\n return `✓ no problems found (${filesScanned} files, ${durationMs}ms)\\n`;\n }\n const byFile = new Map<string, typeof diagnostics>();\n for (const d of diagnostics) {\n if (!byFile.has(d.file)) byFile.set(d.file, []);\n byFile.get(d.file)!.push(d);\n }\n const lines: string[] = [];\n for (const [file, ds] of byFile) {\n lines.push(`\\n${file}`);\n for (const d of ds) {\n const sev = d.severity === \"error\" ? \"error\" : \"warn \";\n const loc = `${d.line}:${d.column}`.padEnd(7);\n lines.push(` ${loc} ${sev} ${d.message} ${d.rule}`);\n }\n }\n const errors = diagnostics.filter((d) => d.severity === \"error\").length;\n const warnings = diagnostics.filter((d) => d.severity === \"warn\").length;\n lines.push(\n `\\n${diagnostics.length} problems (${errors} error${\n errors === 1 ? \"\" : \"s\"\n }, ${warnings} warning${\n warnings === 1 ? \"\" : \"s\"\n }) in ${filesScanned} files, ${durationMs}ms`,\n );\n return lines.join(\"\\n\") + \"\\n\";\n};\n","import type { Formatter } from \"./types.ts\";\n\nexport const json: Formatter = (ctx) => JSON.stringify(ctx, null, 2);\n","import type { Formatter } from \"./types.ts\";\n\nexport const sarif: Formatter = ({ diagnostics }) => {\n const ruleIds = [...new Set(diagnostics.map((d) => d.rule))];\n return JSON.stringify(\n {\n version: \"2.1.0\",\n $schema:\n \"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json\",\n runs: [{\n tool: {\n driver: {\n name: \"hook-o-gnese\",\n informationUri: \"https://github.com/rehoutm/spaghetti-hook-o-gnese\",\n rules: ruleIds.map((id) => ({ id })),\n },\n },\n results: diagnostics.map((d) => ({\n ruleId: d.rule,\n level: d.severity === \"error\" ? \"error\" : \"warning\",\n message: { text: d.message },\n locations: [{\n physicalLocation: {\n artifactLocation: { uri: d.file },\n region: {\n startLine: d.line,\n startColumn: d.column,\n endLine: d.endLine,\n endColumn: d.endColumn,\n },\n },\n }],\n })),\n }],\n },\n null,\n 2,\n );\n};\n","import type { Formatter } from \"./types.ts\";\n\nexport const github: Formatter = ({ diagnostics }) =>\n diagnostics.map((d) => {\n const cmd = d.severity === \"error\" ? \"::error\" : \"::warning\";\n const safe = d.message.replace(/\\r?\\n/g, \" \").replace(/::/g, \":\");\n return `${cmd} file=${d.file},line=${d.line},col=${d.column},title=${d.rule}::${safe}`;\n }).join(\"\\n\") + \"\\n\";\n","import { globby } from \"globby\";\nimport { lintFiles } from \"./engine.ts\";\nimport type { Severity } from \"./engine.ts\";\nimport { applyCliRuleOverrides, DEFAULT_IGNORE, loadConfig } from \"./config.ts\";\nimport { stylish } from \"./formatters/stylish.ts\";\nimport { json as jsonFmt } from \"./formatters/json.ts\";\nimport { sarif } from \"./formatters/sarif.ts\";\nimport { github } from \"./formatters/github.ts\";\nimport type { Formatter } from \"./formatters/types.ts\";\n\nconst FORMATTERS: Record<string, Formatter> = {\n stylish,\n json: jsonFmt,\n sarif,\n github,\n};\n\nexport const HELP = `\nhook-o-gnese — score React hook complexity\n\nUsage:\n hook-o-gnese [options] <paths...>\n\nOptions:\n --format=<fmt> stylish (default) | json | sarif | github\n --config=<path> path to .hookogneserc.json\n --type-aware enable custom-hook-depth (slower, uses TS Compiler API)\n --rule=<id>=<sev> override rule severity (off|warn|error). Repeatable.\n --help, -h show this message\n\nExamples:\n hook-o-gnese ./src\n hook-o-gnese ./src --format=sarif > report.sarif\n hook-o-gnese ./src --type-aware --rule=hook-o-gnese/state-scatter=error\n`.trim();\n\nexport interface CliOptions {\n paths: string[];\n format: string;\n config?: string;\n typeAware: boolean;\n ruleOverrides: Array<{ id: string; severity: Severity }>;\n cwd: string;\n}\n\nexport interface RuntimeIO {\n readTextFile(path: string): Promise<string>;\n writeStdout(s: string): void;\n writeStderr(s: string): void;\n}\n\nexport async function runCli(opts: CliOptions, io: RuntimeIO): Promise<number> {\n if (opts.paths.length === 0) {\n io.writeStderr(\"Error: no paths provided. Use --help for usage.\\n\");\n return 2;\n }\n\n const formatter = FORMATTERS[opts.format];\n if (!formatter) {\n io.writeStderr(`Error: unknown format '${opts.format}'\\n`);\n return 2;\n }\n\n const { engine, ignore } = await loadConfig(\n opts.cwd,\n opts.config,\n io.readTextFile,\n );\n if (opts.typeAware) engine.typeAware = true;\n const finalEngine = applyCliRuleOverrides(engine, opts.ruleOverrides);\n\n const files = await globby(opts.paths, {\n ignore: [...DEFAULT_IGNORE, ...ignore],\n expandDirectories: { extensions: [\"ts\", \"tsx\", \"js\", \"jsx\"] },\n absolute: false,\n });\n\n if (files.length === 0) {\n io.writeStderr(\"Error: no matching files found\\n\");\n return 2;\n }\n\n const start = performance.now();\n const diagnostics = await lintFiles(files, finalEngine, io.readTextFile);\n const durationMs = Math.round(performance.now() - start);\n\n io.writeStdout(formatter({\n diagnostics,\n filesScanned: files.length,\n durationMs,\n }));\n\n if (diagnostics.some((d) => d.severity === \"error\")) return 1;\n return 0;\n}\n","#!/usr/bin/env node\nimport { parseArgs } from \"node:util\";\nimport { readFile } from \"node:fs/promises\";\nimport { HELP, runCli } from \"./cli-core.ts\";\nimport type { Severity } from \"./engine.ts\";\n\nconst { values, positionals } = parseArgs({\n args: process.argv.slice(2),\n options: {\n help: { type: \"boolean\", short: \"h\" },\n \"type-aware\": { type: \"boolean\" },\n format: { type: \"string\", default: \"stylish\" },\n config: { type: \"string\" },\n rule: { type: \"string\", multiple: true },\n },\n allowPositionals: true,\n});\n\nif (values.help) {\n console.log(HELP);\n process.exit(0);\n}\n\nconst overrides = (values.rule ?? []).map((spec) => {\n const [id, sev] = spec.split(\"=\");\n return { id, severity: sev as Severity };\n});\n\nconst code = await runCli(\n {\n paths: positionals,\n format: values.format as string,\n config: values.config,\n typeAware: !!values[\"type-aware\"],\n ruleOverrides: overrides,\n cwd: process.cwd(),\n },\n {\n readTextFile: (p) => readFile(p, \"utf-8\"),\n writeStdout: (s) => {\n process.stdout.write(s);\n },\n writeStderr: (s) => {\n process.stderr.write(s);\n },\n },\n);\nprocess.exit(code);\n"],"mappings":";;;;;;AAEA,MAAM,gBACJ;CACE,+BAA+B,EAAE,UAAU,QAAQ;CACnD,8BAA8B,EAAE,UAAU,QAAQ;CAClD,8BAA8B,EAAE,UAAU,SAAS;CACnD,kCAAkC;EAChC,UAAU;EACV,SAAS,EAAE,UAAU,GAAA;;CAExB;AAEH,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACD;AAUD,eAAsB,WACpB,KACA,YACA,cACqD;CACrD,MAAM,aAAa,aACf,CAAC,WAAW,GACZ,CAAC,GAAG,IAAI,QAAQ,OAAO,GAAG,CAAC,qBAAqB;CAEpD,IAAI,UAAsB,EAAE;AAC5B,MAAK,MAAM,KAAK,WACd,KAAI;EACF,MAAM,OAAO,MAAM,aAAa,EAAE;AAClC,YAAU,KAAK,MAAM,KAAK;AAC1B;SACM;CAKV,MAAM,QAA+B,EAAE,GAAG,eAAe;AACzD,KAAI,QAAQ,MACV,MAAK,MAAM,CAAC,IAAI,SAAS,OAAO,QAAQ,QAAQ,MAAM,CACpD,KAAI,MAAM,QAAQ,KAAK,CACrB,OAAM,MAAM;EAAE,UAAU,KAAK;EAAI,SAAS,KAAK;EAAI;KAEnD,OAAM,MAAM,EAAE,UAAU,MAAM;AAKpC,QAAO;EACL,QAAQ;GACN;GACA;GACA,WAAW,QAAQ,aAAa;GACjC;EACD,QAAQ,QAAQ,UAAU;EAC3B;;AAGH,SAAgB,sBACd,KACA,WACc;CACd,MAAM,QAAQ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M,OACjB;CACE,OAAO;CACP,QAAQ,OAAO;CACf,QAAQ,OAAO;CACf,WAAW,CAAC,CAAC,OAAO;CACpB,eAAe;CACf,KAAK,QAAQ,KAAA;CACd,EACD;CACE,eAAe,MAAM,SAAS,GAAG,QAAQ;CACzC,cAAc,MAAM;AAClB,UAAQ,OAAO,MAAM,EAAE;;CAEzB,cAAc,MAAM;AAClB,UAAQ,OAAO,MAAM,EAAE;;CAE1B,CACF;AACD,QAAQ,KAAK,KAAK"}
1
+ {"version":3,"file":"cli.mjs","names":["jsonFmt"],"sources":["../src/config.ts","../src/formatters/stylish.ts","../src/formatters/json.ts","../src/formatters/sarif.ts","../src/formatters/github.ts","../src/cli-core.ts","../src/cli.node.ts"],"sourcesContent":["import type { EngineConfig, Severity } from \"./engine.ts\";\n\nconst DEFAULT_RULES: Record<string, { severity: Severity; options?: unknown }> =\n {\n \"hook-o-gnese/no-fat-effects\": { severity: \"warn\" },\n \"hook-o-gnese/state-scatter\": { severity: \"warn\" },\n \"hook-o-gnese/hook-coupling\": { severity: \"error\" },\n \"hook-o-gnese/custom-hook-depth\": {\n severity: \"warn\",\n options: { maxDepth: 3 },\n },\n };\n\nexport const DEFAULT_IGNORE = [\n \"**/node_modules/**\",\n \"**/dist/**\",\n \"**/build/**\",\n \"**/.next/**\",\n \"**/.cache/**\",\n];\n\ninterface FileConfig {\n rules?: Record<string, Severity | [Severity, unknown]>;\n ignore?: string[];\n typeAware?: boolean;\n}\n\nexport type ReadTextFile = (path: string) => Promise<string>;\n\nexport async function loadConfig(\n cwd: string,\n configPath: string | undefined,\n readTextFile: ReadTextFile,\n): Promise<{ engine: EngineConfig; ignore: string[] }> {\n const candidates = configPath\n ? [configPath]\n : [`${cwd.replace(/\\/$/, \"\")}/.hookogneserc.json`];\n\n let fileCfg: FileConfig = {};\n for (const c of candidates) {\n try {\n const text = await readTextFile(c);\n fileCfg = JSON.parse(text);\n break;\n } catch {\n // not found — fine, use defaults\n }\n }\n\n const rules: EngineConfig[\"rules\"] = { ...DEFAULT_RULES };\n if (fileCfg.rules) {\n for (const [id, spec] of Object.entries(fileCfg.rules)) {\n if (Array.isArray(spec)) {\n rules[id] = { severity: spec[0], options: spec[1] };\n } else {\n rules[id] = { severity: spec };\n }\n }\n }\n\n return {\n engine: {\n rules,\n cwd,\n typeAware: fileCfg.typeAware ?? false,\n },\n ignore: fileCfg.ignore ?? DEFAULT_IGNORE,\n };\n}\n\nexport function applyCliRuleOverrides(\n cfg: EngineConfig,\n overrides: Array<{ id: string; severity: Severity }>,\n): EngineConfig {\n const rules = { ...cfg.rules };\n for (const o of overrides) {\n rules[o.id] = {\n ...(rules[o.id] ?? { severity: \"off\" }),\n severity: o.severity,\n };\n }\n return { ...cfg, rules };\n}\n","import type { Formatter } from \"./types.ts\";\n\nexport const stylish: Formatter = (\n { diagnostics, filesScanned, durationMs },\n) => {\n if (diagnostics.length === 0) {\n return `✓ no problems found (${filesScanned} files, ${durationMs}ms)\\n`;\n }\n const byFile = new Map<string, typeof diagnostics>();\n for (const d of diagnostics) {\n if (!byFile.has(d.file)) byFile.set(d.file, []);\n byFile.get(d.file)!.push(d);\n }\n const lines: string[] = [];\n for (const [file, ds] of byFile) {\n lines.push(`\\n${file}`);\n for (const d of ds) {\n const sev = d.severity === \"error\" ? \"error\" : \"warn \";\n const loc = `${d.line}:${d.column}`.padEnd(7);\n lines.push(` ${loc} ${sev} ${d.message} ${d.rule}`);\n }\n }\n const errors = diagnostics.filter((d) => d.severity === \"error\").length;\n const warnings = diagnostics.filter((d) => d.severity === \"warn\").length;\n lines.push(\n `\\n${diagnostics.length} problems (${errors} error${\n errors === 1 ? \"\" : \"s\"\n }, ${warnings} warning${\n warnings === 1 ? \"\" : \"s\"\n }) in ${filesScanned} files, ${durationMs}ms`,\n );\n return lines.join(\"\\n\") + \"\\n\";\n};\n","import type { Formatter } from \"./types.ts\";\n\nexport const json: Formatter = (ctx) => JSON.stringify(ctx, null, 2);\n","import type { Formatter } from \"./types.ts\";\n\nexport const sarif: Formatter = ({ diagnostics }) => {\n const ruleIds = [...new Set(diagnostics.map((d) => d.rule))];\n return JSON.stringify(\n {\n version: \"2.1.0\",\n $schema:\n \"https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json\",\n runs: [{\n tool: {\n driver: {\n name: \"hook-o-gnese\",\n informationUri: \"https://github.com/rehoutm/spaghetti-hook-o-gnese\",\n rules: ruleIds.map((id) => ({ id })),\n },\n },\n results: diagnostics.map((d) => ({\n ruleId: d.rule,\n level: d.severity === \"error\" ? \"error\" : \"warning\",\n message: { text: d.message },\n locations: [{\n physicalLocation: {\n artifactLocation: { uri: d.file },\n region: {\n startLine: d.line,\n startColumn: d.column,\n endLine: d.endLine,\n endColumn: d.endColumn,\n },\n },\n }],\n })),\n }],\n },\n null,\n 2,\n );\n};\n","import type { Formatter } from \"./types.ts\";\n\nexport const github: Formatter = ({ diagnostics }) =>\n diagnostics.map((d) => {\n const cmd = d.severity === \"error\" ? \"::error\" : \"::warning\";\n const safe = d.message.replace(/\\r?\\n/g, \" \").replace(/::/g, \":\");\n return `${cmd} file=${d.file},line=${d.line},col=${d.column},title=${d.rule}::${safe}`;\n }).join(\"\\n\") + \"\\n\";\n","import { globby } from \"globby\";\nimport { lintFiles } from \"./engine.ts\";\nimport type { Severity } from \"./engine.ts\";\nimport { applyCliRuleOverrides, DEFAULT_IGNORE, loadConfig } from \"./config.ts\";\nimport { isTypescriptAvailable } from \"./ts-program.ts\";\nimport { stylish } from \"./formatters/stylish.ts\";\nimport { json as jsonFmt } from \"./formatters/json.ts\";\nimport { sarif } from \"./formatters/sarif.ts\";\nimport { github } from \"./formatters/github.ts\";\nimport type { Formatter } from \"./formatters/types.ts\";\n\nconst FORMATTERS: Record<string, Formatter> = {\n stylish,\n json: jsonFmt,\n sarif,\n github,\n};\n\nexport const HELP = `\nhook-o-gnese — score React hook complexity\n\nUsage:\n hook-o-gnese [options] <paths...>\n\nOptions:\n --format=<fmt> stylish (default) | json | sarif | github\n --config=<path> path to .hookogneserc.json\n --type-aware enable custom-hook-depth (slower, uses TS Compiler API).\n Requires 'typescript' installed in your project.\n --rule=<id>=<sev> override rule severity (off|warn|error). Repeatable.\n --help, -h show this message\n\nExamples:\n hook-o-gnese ./src\n hook-o-gnese ./src --format=sarif > report.sarif\n hook-o-gnese ./src --type-aware --rule=hook-o-gnese/state-scatter=error\n`.trim();\n\nexport interface CliOptions {\n paths: string[];\n format: string;\n config?: string;\n typeAware: boolean;\n ruleOverrides: Array<{ id: string; severity: Severity }>;\n cwd: string;\n}\n\nexport interface RuntimeIO {\n readTextFile(path: string): Promise<string>;\n writeStdout(s: string): void;\n writeStderr(s: string): void;\n}\n\nexport async function runCli(opts: CliOptions, io: RuntimeIO): Promise<number> {\n if (opts.paths.length === 0) {\n io.writeStderr(\"Error: no paths provided. Use --help for usage.\\n\");\n return 2;\n }\n\n const formatter = FORMATTERS[opts.format];\n if (!formatter) {\n io.writeStderr(`Error: unknown format '${opts.format}'\\n`);\n return 2;\n }\n\n const { engine, ignore } = await loadConfig(\n opts.cwd,\n opts.config,\n io.readTextFile,\n );\n // CLI flag --type-aware force-enables; config-file `typeAware: true` is\n // honored as-is. Either way, downgrade to false if `typescript` cannot be\n // loaded, so the rule never explodes at create() time.\n if (opts.typeAware) engine.typeAware = true;\n if (engine.typeAware && !isTypescriptAvailable(opts.cwd)) {\n io.writeStderr(\n \"warning: type-aware rules require the 'typescript' package to be \" +\n \"installed in your project. Skipping type-aware rules. \" +\n \"Install with: npm i -D typescript@>=6\\n\",\n );\n engine.typeAware = false;\n }\n const finalEngine = applyCliRuleOverrides(engine, opts.ruleOverrides);\n\n const files = await globby(opts.paths, {\n ignore: [...DEFAULT_IGNORE, ...ignore],\n expandDirectories: { extensions: [\"ts\", \"tsx\", \"js\", \"jsx\"] },\n absolute: false,\n });\n\n if (files.length === 0) {\n io.writeStderr(\"Error: no matching files found\\n\");\n return 2;\n }\n\n const start = performance.now();\n const diagnostics = await lintFiles(files, finalEngine, io.readTextFile);\n const durationMs = Math.round(performance.now() - start);\n\n io.writeStdout(formatter({\n diagnostics,\n filesScanned: files.length,\n durationMs,\n }));\n\n if (diagnostics.some((d) => d.severity === \"error\")) return 1;\n return 0;\n}\n","#!/usr/bin/env node\nimport { parseArgs } from \"node:util\";\nimport { readFile } from \"node:fs/promises\";\nimport { HELP, runCli } from \"./cli-core.ts\";\nimport type { Severity } from \"./engine.ts\";\n\nconst { values, positionals } = parseArgs({\n args: process.argv.slice(2),\n options: {\n help: { type: \"boolean\", short: \"h\" },\n \"type-aware\": { type: \"boolean\" },\n format: { type: \"string\", default: \"stylish\" },\n config: { type: \"string\" },\n rule: { type: \"string\", multiple: true },\n },\n allowPositionals: true,\n});\n\nif (values.help) {\n console.log(HELP);\n process.exit(0);\n}\n\nconst overrides = (values.rule ?? []).map((spec) => {\n const [id, sev] = spec.split(\"=\");\n return { id, severity: sev as Severity };\n});\n\nconst code = await runCli(\n {\n paths: positionals,\n format: values.format as string,\n config: values.config,\n typeAware: !!values[\"type-aware\"],\n ruleOverrides: overrides,\n cwd: process.cwd(),\n },\n {\n readTextFile: (p) => readFile(p, \"utf-8\"),\n writeStdout: (s) => {\n process.stdout.write(s);\n },\n writeStderr: (s) => {\n process.stderr.write(s);\n },\n },\n);\nprocess.exit(code);\n"],"mappings":";;;;;;;AAEA,MAAM,gBACJ;CACE,+BAA+B,EAAE,UAAU,QAAQ;CACnD,8BAA8B,EAAE,UAAU,QAAQ;CAClD,8BAA8B,EAAE,UAAU,SAAS;CACnD,kCAAkC;EAChC,UAAU;EACV,SAAS,EAAE,UAAU,GAAA;;CAExB;AAEH,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACD;AAUD,eAAsB,WACpB,KACA,YACA,cACqD;CACrD,MAAM,aAAa,aACf,CAAC,WAAW,GACZ,CAAC,GAAG,IAAI,QAAQ,OAAO,GAAG,CAAC,qBAAqB;CAEpD,IAAI,UAAsB,EAAE;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M,EAAE,aAAa,QAAQ,CAAE,QAAO;AAC5D,QAAO;;;;ACpGT,MAAM,EAAE,QAAQ,gBAAgB,UAAU;CACxC,MAAM,QAAQ,KAAK,MAAM,EAAE;CAC3B,SAAS;EACP,MAAM;GAAE,MAAM;GAAW,OAAO;GAAK;EACrC,cAAc,EAAE,MAAM,WAAW;EACjC,QAAQ;GAAE,MAAM;GAAU,SAAS;GAAW;EAC9C,QAAQ,EAAE,MAAM,UAAU;EAC1B,MAAM;GAAE,MAAM;GAAU,UAAU;;EACnC;CACD,kBAAkB;CACnB,CAAC;AAEF,IAAI,OAAO,MAAM;AACf,SAAQ,IAAI,KAAK;AACjB,SAAQ,KAAK,EAAE;;AAGjB,MAAM,aAAa,OAAO,QAAQ,EAAE,EAAE,KAAK,SAAS;CAClD,MAAM,CAAC,IAAI,OAAO,KAAK,MAAM,IAAI;AACjC,QAAO;EAAE;EAAI,UAAU;EAAiB;EACxC;AAEF,MAAM,OAAO,MAAM,OACjB;CACE,OAAO;CACP,QAAQ,OAAO;CACf,QAAQ,OAAO;CACf,WAAW,CAAC,CAAC,OAAO;CACpB,eAAe;CACf,KAAK,QAAQ,KAAA;CACd,EACD;CACE,eAAe,MAAM,SAAS,GAAG,QAAQ;CACzC,cAAc,MAAM;AAClB,UAAQ,OAAO,MAAM,EAAE;;CAEzB,cAAc,MAAM;AAClB,UAAQ,OAAO,MAAM,EAAE;;CAE1B,CACF;AACD,QAAQ,KAAK,KAAK"}
@@ -1,6 +1,16 @@
1
- import { t as ALL_RULES } from "./registry-iRG6wil9.mjs";
1
+ import { t as ALL_RULES } from "./registry-YXM4yhf2.mjs";
2
2
  import { parseSync } from "oxc-parser";
3
3
  //#region src/engine.ts
4
+ /**
5
+ * Standalone linting engine for `hook-o-gnese`.
6
+ *
7
+ * Provides a runtime-agnostic pipeline that parses files with `oxc-parser`,
8
+ * runs the package's rules against the resulting AST, and returns
9
+ * {@link Diagnostic} records. Used directly by the CLI and embeddable in any
10
+ * host that can supply a file reader.
11
+ *
12
+ * @module
13
+ */
4
14
  const TYPE_AWARE_RULES = new Set(["hook-o-gnese/custom-hook-depth"]);
5
15
  function ruleNamespace(id) {
6
16
  return id.replace(/^hook-o-gnese\//, "");
@@ -51,6 +61,16 @@ function walkAST(node, handlers) {
51
61
  const exit = handlers[`${node.type}:exit`];
52
62
  if (exit) exit(node);
53
63
  }
64
+ /**
65
+ * Lint a single source file and return any diagnostics produced.
66
+ *
67
+ * Parses `source` with `oxc-parser`, bails out early on non-React files, and
68
+ * dispatches every enabled rule in `config` against the resulting AST.
69
+ *
70
+ * @param filePath Path used for diagnostic reporting and to infer the parser language.
71
+ * @param source The source code to lint.
72
+ * @param config Resolved engine configuration.
73
+ */
54
74
  async function lintFile(filePath, source, config) {
55
75
  const parsed = parseSync(filePath, source, {
56
76
  lang: filePath.endsWith(".tsx") ? "tsx" : filePath.endsWith(".ts") ? "ts" : filePath.endsWith(".jsx") ? "jsx" : "js",
@@ -103,6 +123,13 @@ async function lintFile(filePath, source, config) {
103
123
  }
104
124
  return out;
105
125
  }
126
+ /**
127
+ * Lint a batch of files in parallel and return their combined diagnostics.
128
+ *
129
+ * @param filePaths Paths to lint.
130
+ * @param config Resolved engine configuration shared across files.
131
+ * @param readTextFile File reader supplied by the host (Deno, Node, in-memory).
132
+ */
106
133
  async function lintFiles(filePaths, config, readTextFile) {
107
134
  return (await Promise.all(filePaths.map(async (p) => {
108
135
  return lintFile(p, await readTextFile(p), config);
@@ -111,4 +138,4 @@ async function lintFiles(filePaths, config, readTextFile) {
111
138
  //#endregion
112
139
  export { lintFiles as n, lintFile as t };
113
140
 
114
- //# sourceMappingURL=engine-DJFFKwTZ.mjs.map
141
+ //# sourceMappingURL=engine-DKI7WYuw.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine-DKI7WYuw.mjs","names":[],"sources":["../src/engine.ts"],"sourcesContent":["/**\n * Standalone linting engine for `hook-o-gnese`.\n *\n * Provides a runtime-agnostic pipeline that parses files with `oxc-parser`,\n * runs the package's rules against the resulting AST, and returns\n * {@link Diagnostic} records. Used directly by the CLI and embeddable in any\n * host that can supply a file reader.\n *\n * @module\n */\n\nimport { parseSync } from \"oxc-parser\";\nimport { ALL_RULES } from \"./rules/registry.ts\";\n\n/** Rule severity. `\"off\"` disables a rule entirely. */\nexport type Severity = \"off\" | \"warn\" | \"error\";\n\n/** A single lint finding produced by the engine. */\nexport interface Diagnostic {\n /** Absolute or workspace-relative path of the linted file. */\n file: string;\n /** Fully qualified rule id (e.g. `\"hook-o-gnese/no-fat-effects\"`). */\n rule: string;\n /** Effective severity after rule and config resolution. */\n severity: Exclude<Severity, \"off\">;\n /** Human-readable description of the problem. */\n message: string;\n /** 1-based line where the diagnostic starts. */\n line: number;\n /** 1-based column where the diagnostic starts. */\n column: number;\n /** 1-based line where the diagnostic ends, when known. */\n endLine?: number;\n /** 1-based column where the diagnostic ends, when known. */\n endColumn?: number;\n}\n\n/** Per-rule configuration: severity plus optional rule-specific options. */\nexport interface RuleConfig {\n severity: Severity;\n options?: unknown;\n}\n\n/** Configuration consumed by {@link lintFile} and {@link lintFiles}. */\nexport interface EngineConfig {\n /** Map of rule id to its configuration. */\n rules: Record<string, RuleConfig>;\n /** Working directory used to resolve TypeScript projects and relative paths. */\n cwd: string;\n /** When true, type-aware rules (e.g. `custom-hook-depth`) are run. */\n typeAware: boolean;\n}\n\nconst TYPE_AWARE_RULES = new Set([\"hook-o-gnese/custom-hook-depth\"]);\n\nfunction ruleNamespace(id: string): string {\n return id.replace(/^hook-o-gnese\\//, \"\");\n}\n\nfunction buildLineOffsets(source: string): number[] {\n const offsets = [0];\n for (let i = 0; i < source.length; i++) {\n if (source.charCodeAt(i) === 10) offsets.push(i + 1);\n }\n return offsets;\n}\n\nfunction offsetToLineCol(\n offset: number,\n lineOffsets: number[],\n): { line: number; column: number } {\n let lo = 0;\n let hi = lineOffsets.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >>> 1;\n if (lineOffsets[mid] <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lineOffsets[lo] + 1 };\n}\n\nfunction getLoc(\n node: any,\n lineOffsets: number[],\n): { line: number; column: number; endLine?: number; endColumn?: number } {\n const startOffset = typeof node?.start === \"number\" ? node.start : undefined;\n const endOffset = typeof node?.end === \"number\" ? node.end : undefined;\n if (startOffset === undefined) {\n return { line: 1, column: 1 };\n }\n const start = offsetToLineCol(startOffset, lineOffsets);\n const end = endOffset !== undefined\n ? offsetToLineCol(endOffset, lineOffsets)\n : undefined;\n return {\n line: start.line,\n column: start.column,\n endLine: end?.line,\n endColumn: end?.column,\n };\n}\n\nfunction walkAST(node: any, handlers: Record<string, any>) {\n if (!node || typeof node !== \"object\") return;\n const enter = handlers[node.type];\n if (enter) enter(node);\n for (const key in node) {\n const v = node[key];\n if (Array.isArray(v)) {\n for (const c of v) walkAST(c, handlers);\n } else if (v && typeof v === \"object\") {\n walkAST(v, handlers);\n }\n }\n const exit = handlers[`${node.type}:exit`];\n if (exit) exit(node);\n}\n\n/**\n * Lint a single source file and return any diagnostics produced.\n *\n * Parses `source` with `oxc-parser`, bails out early on non-React files, and\n * dispatches every enabled rule in `config` against the resulting AST.\n *\n * @param filePath Path used for diagnostic reporting and to infer the parser language.\n * @param source The source code to lint.\n * @param config Resolved engine configuration.\n */\nexport async function lintFile(\n filePath: string,\n source: string,\n config: EngineConfig,\n): Promise<Diagnostic[]> {\n const lang = filePath.endsWith(\".tsx\")\n ? \"tsx\"\n : filePath.endsWith(\".ts\")\n ? \"ts\"\n : filePath.endsWith(\".jsx\")\n ? \"jsx\"\n : \"js\";\n\n const parsed = parseSync(filePath, source, {\n lang,\n sourceType: \"module\",\n });\n\n const lineOffsets = buildLineOffsets(source);\n\n if (parsed.errors?.length) {\n return parsed.errors.map((e: any) => {\n const offset = typeof e.labels?.[0]?.start === \"number\"\n ? e.labels[0].start\n : undefined;\n const loc = offset !== undefined\n ? offsetToLineCol(offset, lineOffsets)\n : { line: 1, column: 1 };\n return {\n file: filePath,\n rule: \"parse-error\",\n severity: \"error\" as const,\n message: e.message ?? \"parse error\",\n line: loc.line,\n column: loc.column,\n };\n });\n }\n\n // Bail early on non-React files\n const imports = parsed.module?.staticImports ?? [];\n const hasReact = imports.some((i: any) =>\n (i.moduleRequest?.value ?? i.source?.value) === \"react\"\n );\n if (!hasReact) return [];\n\n const out: Diagnostic[] = [];\n\n for (const [ruleId, ruleCfg] of Object.entries(config.rules)) {\n if (ruleCfg.severity === \"off\") continue;\n if (!config.typeAware && TYPE_AWARE_RULES.has(ruleId)) continue;\n\n const rule = (ALL_RULES as any)[ruleNamespace(ruleId)];\n if (!rule) continue;\n\n const localDiags: Diagnostic[] = [];\n const context = {\n options: ruleCfg.options ? [ruleCfg.options] : [],\n filename: filePath,\n cwd: config.cwd,\n report(d: { message: string; node: any; severity?: \"warn\" | \"error\" }) {\n const loc = getLoc(d.node, lineOffsets);\n const cfgSev = ruleCfg.severity as \"warn\" | \"error\";\n // Rule-emitted severity only escalates (warn → error); never downgrades.\n const severity = d.severity === \"error\" ? \"error\" : cfgSev;\n localDiags.push({\n file: filePath,\n rule: ruleId,\n severity,\n message: d.message,\n ...loc,\n });\n },\n };\n\n const handlers = rule.create(context);\n walkAST(parsed.program, handlers);\n out.push(...localDiags);\n }\n\n return out;\n}\n\n/** Reads a file's contents as text. Injected so the engine stays runtime-agnostic. */\nexport type ReadTextFile = (path: string) => Promise<string>;\n\n/**\n * Lint a batch of files in parallel and return their combined diagnostics.\n *\n * @param filePaths Paths to lint.\n * @param config Resolved engine configuration shared across files.\n * @param readTextFile File reader supplied by the host (Deno, Node, in-memory).\n */\nexport async function lintFiles(\n filePaths: string[],\n config: EngineConfig,\n readTextFile: ReadTextFile,\n): Promise<Diagnostic[]> {\n const results = await Promise.all(\n filePaths.map(async (p) => {\n const src = await readTextFile(p);\n return lintFile(p, src, config);\n }),\n );\n return results.flat();\n}\n"],"mappings":";;;;;;;;;;;;;AAqDA,MAAM,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GACV,KAAK,OAAO;GACZ,OAAO,GAAgE;IACrE,MAAM,MAAM,OAAO,EAAE,MAAM,YAAY;IACvC,MAAM,SAAS,QAAQ;IAEvB,MAAM,WAAW,EAAE,aAAa,UAAU,UAAU;AACpD,eAAW,KAAK;KACd,MAAM;KACN,MAAM;KACN;KACA,SAAS,EAAE;KACX,GAAG;KACJ,CAAC;;GAEL;EAED,MAAM,WAAW,KAAK,OAAO,QAAQ;AACrC,UAAQ,OAAO,SAAS,SAAS;AACjC,MAAI,KAAK,GAAG,WAAW;;AAGzB,QAAO;;;;;;;;;AAaT,eAAsB,UACpB,WACA,QACA,cACuB;AAOvB,SAAO,MANe,QAAQ,IAC5B,UAAU,IAAI,OAAO,MAAM;AAEzB,SAAO,SAAS,GAAG,MADD,aAAa,EAAE,EACT,OAAO;GAC/B,CACH,EACc,MAAM"}
package/dist/engine.d.mts CHANGED
@@ -1,26 +1,69 @@
1
1
  //#region src/engine.d.ts
2
+ /**
3
+ * Standalone linting engine for `hook-o-gnese`.
4
+ *
5
+ * Provides a runtime-agnostic pipeline that parses files with `oxc-parser`,
6
+ * runs the package's rules against the resulting AST, and returns
7
+ * {@link Diagnostic} records. Used directly by the CLI and embeddable in any
8
+ * host that can supply a file reader.
9
+ *
10
+ * @module
11
+ */
12
+ /** Rule severity. `"off"` disables a rule entirely. */
2
13
  type Severity = "off" | "warn" | "error";
14
+ /** A single lint finding produced by the engine. */
3
15
  interface Diagnostic {
16
+ /** Absolute or workspace-relative path of the linted file. */
4
17
  file: string;
18
+ /** Fully qualified rule id (e.g. `"hook-o-gnese/no-fat-effects"`). */
5
19
  rule: string;
20
+ /** Effective severity after rule and config resolution. */
6
21
  severity: Exclude<Severity, "off">;
22
+ /** Human-readable description of the problem. */
7
23
  message: string;
24
+ /** 1-based line where the diagnostic starts. */
8
25
  line: number;
26
+ /** 1-based column where the diagnostic starts. */
9
27
  column: number;
28
+ /** 1-based line where the diagnostic ends, when known. */
10
29
  endLine?: number;
30
+ /** 1-based column where the diagnostic ends, when known. */
11
31
  endColumn?: number;
12
32
  }
33
+ /** Per-rule configuration: severity plus optional rule-specific options. */
13
34
  interface RuleConfig {
14
35
  severity: Severity;
15
36
  options?: unknown;
16
37
  }
38
+ /** Configuration consumed by {@link lintFile} and {@link lintFiles}. */
17
39
  interface EngineConfig {
40
+ /** Map of rule id to its configuration. */
18
41
  rules: Record<string, RuleConfig>;
42
+ /** Working directory used to resolve TypeScript projects and relative paths. */
19
43
  cwd: string;
44
+ /** When true, type-aware rules (e.g. `custom-hook-depth`) are run. */
20
45
  typeAware: boolean;
21
46
  }
47
+ /**
48
+ * Lint a single source file and return any diagnostics produced.
49
+ *
50
+ * Parses `source` with `oxc-parser`, bails out early on non-React files, and
51
+ * dispatches every enabled rule in `config` against the resulting AST.
52
+ *
53
+ * @param filePath Path used for diagnostic reporting and to infer the parser language.
54
+ * @param source The source code to lint.
55
+ * @param config Resolved engine configuration.
56
+ */
22
57
  declare function lintFile(filePath: string, source: string, config: EngineConfig): Promise<Diagnostic[]>;
58
+ /** Reads a file's contents as text. Injected so the engine stays runtime-agnostic. */
23
59
  type ReadTextFile = (path: string) => Promise<string>;
60
+ /**
61
+ * Lint a batch of files in parallel and return their combined diagnostics.
62
+ *
63
+ * @param filePaths Paths to lint.
64
+ * @param config Resolved engine configuration shared across files.
65
+ * @param readTextFile File reader supplied by the host (Deno, Node, in-memory).
66
+ */
24
67
  declare function lintFiles(filePaths: string[], config: EngineConfig, readTextFile: ReadTextFile): Promise<Diagnostic[]>;
25
68
  //#endregion
26
69
  export { Diagnostic, EngineConfig, ReadTextFile, RuleConfig, Severity, lintFile, lintFiles };
package/dist/engine.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { n as lintFiles, t as lintFile } from "./engine-DJFFKwTZ.mjs";
1
+ import { n as lintFiles, t as lintFile } from "./engine-DKI7WYuw.mjs";
2
2
  export { lintFile, lintFiles };
package/dist/index.d.mts CHANGED
@@ -3971,6 +3971,13 @@ interface CreateOnceRule {
3971
3971
  //#endregion
3972
3972
  //#region src/index.d.ts
3973
3973
  declare const plugin: Plugin;
3974
+ /**
3975
+ * Recommended oxlint configuration for `hook-o-gnese`.
3976
+ *
3977
+ * Enables every rule the plugin ships with sensible severities, plus the
3978
+ * tsgolint type-aware rules required for full coverage. Spread into your
3979
+ * oxlint config alongside the default plugin export.
3980
+ */
3974
3981
  declare const recommended: {
3975
3982
  jsPlugins: string[];
3976
3983
  options: {
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as ALL_RULES } from "./registry-iRG6wil9.mjs";
1
+ import { t as ALL_RULES } from "./registry-YXM4yhf2.mjs";
2
2
  //#region node_modules/.deno/@oxlint+plugins@1.63.0/node_modules/@oxlint/plugins/index.js
3
3
  const EMPTY_VISITOR = {};
4
4
  /**
@@ -332,10 +332,33 @@ function createContextAndVisitor(rule, afterHooksState) {
332
332
  }
333
333
  //#endregion
334
334
  //#region src/index.ts
335
+ /**
336
+ * Oxlint plugin entrypoint for `hook-o-gnese`.
337
+ *
338
+ * Exports the plugin as the default export and a `recommended` config that
339
+ * bundles the package's hook-complexity rules together with the type-aware
340
+ * tsgolint built-ins it relies on.
341
+ *
342
+ * @example
343
+ * ```ts
344
+ * // oxlint.config.ts
345
+ * import hookOGnese, { recommended } from "hook-o-gnese";
346
+ * export default { plugins: [hookOGnese], ...recommended };
347
+ * ```
348
+ *
349
+ * @module
350
+ */
335
351
  const plugin = eslintCompatPlugin({
336
352
  meta: { name: "hook-o-gnese" },
337
353
  rules: ALL_RULES
338
354
  });
355
+ /**
356
+ * Recommended oxlint configuration for `hook-o-gnese`.
357
+ *
358
+ * Enables every rule the plugin ships with sensible severities, plus the
359
+ * tsgolint type-aware rules required for full coverage. Spread into your
360
+ * oxlint config alongside the default plugin export.
361
+ */
339
362
  const recommended = {
340
363
  jsPlugins: ["./node_modules/hook-o-gnese/dist/index.mjs"],
341
364
  options: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../node_modules/.deno/@oxlint+plugins@1.63.0/node_modules/@oxlint/plugins/index.js","../src/index.ts"],"sourcesContent":["//#region src-js/package/define.ts\n/**\n* Define a plugin.\n*\n* No-op function, just to provide type safety. Input is passed through unchanged.\n*\n* @param plugin - Plugin to define\n* @returns Same plugin as passed in\n*/\nfunction definePlugin(plugin) {\n\treturn plugin;\n}\n/**\n* Define a rule.\n*\n* No-op function, just to provide type safety. Input is passed through unchanged.\n*\n* @param rule - Rule to define\n* @returns Same rule as passed in\n*/\nfunction defineRule(rule) {\n\treturn rule;\n}\n//#endregion\n//#region src-js/package/compat.ts\nconst EMPTY_VISITOR = {};\n/**\n* Convert a plugin which used Oxlint's `createOnce` API to also work with ESLint.\n*\n* If any of the plugin's rules use the Oxlint alternative `createOnce` API,\n* add ESLint-compatible `create` methods to those rules, which delegate to `createOnce`.\n* This makes the plugin compatible with ESLint.\n*\n* The `plugin` object passed in is mutated in-place.\n*\n* @param plugin - Plugin to convert\n* @returns Plugin with all rules having `create` method\n* @throws {Error} If `plugin` is not an object, or `plugin.rules` is not an object\n*/\nfunction eslintCompatPlugin(plugin) {\n\tif (typeof plugin != \"object\" || !plugin) throw Error(\"Plugin must be an object\");\n\tlet { rules } = plugin;\n\tif (typeof rules != \"object\" || !rules) throw Error(\"Plugin must have an object as `rules` property\");\n\tlet afterHooksState = new AfterHooksState();\n\tfor (let ruleName in rules) Object.hasOwn(rules, ruleName) && convertRule(rules[ruleName], afterHooksState);\n\treturn plugin;\n}\n/**\n* Class containing state for tracking if any `after` hooks for a plugin's rules need to be called.\n*\n* # Aims\n*\n* Aims are:\n* 1. `after` hook of each rule runs after all other AST visit functions, and CFG event handlers.\n* 2. `after` hooks for *all* a plugin's rules run after *all* that plugin's rules have completed visiting AST.\n* 3. `after` hooks for *all* a plugin's rules run before *any* of plugin's rules begin linting another file.\n* 4. In the case of an error during AST traversal, `after` hooks are always still run.\n*\n* The above exactly matches the behavior when running a `createOnce` rule in Oxlint.\n*\n* # Why this is important\n*\n* All the complication comes from ensuring `after` hooks run even after an error during AST traversal.\n*\n* In ESLint CLI, an error will crash the process, so it doesn't particularly matter if `after` hooks run or not,\n* but language servers will typically swallow errors, and keep the process running.\n*\n* Rules using `before` and `after` hooks will often rely on both hooks running in a predictable order,\n* to maintain some internal state. For example, they may use `before` and `after` hooks to maintain a per-file\n* cache of data which is shared between rules. The cache use case is why rule (2) above is important.\n*\n* Below is an example of using `before` and `after` hooks to maintain a per-file cache, shared between rules.\n* It relies on all `before` hooks running before any rule starts visiting the AST,\n* and all `after` hooks running after all rules have finished visiting the AST.\n*\n* ```ts\n* let cache: Data | null = null;\n*\n* let numRunningRules = 0;\n*\n* const setupCache = (context) => {\n* if (cache === null) cache = new Data(context);\n* numRunningRules++;\n* };\n*\n* const teardownCache = () => {\n* numRunningRules--;\n* if (numRunningRules === 0) cache = null;\n* };\n*\n* const rule1 = {\n* createOnce(context) {\n* return {\n* before() {\n* setupCache(context);\n* },\n* Identifier(node) {\n* // Use `cache`\n* },\n* after: teardownCache,\n* };\n* },\n* };\n*\n* const rule2 = {\n* // Same as above\n* };\n*\n* const rule3 = {\n* // Same as above\n* };\n* ```\n*\n* If `after` hooks did not always run, the next lint run could get stale state, and malfunction.\n* If `after` hooks ran in the wrong order (e.g. after some `before` hooks for next file),\n* `numRunningRules` would never get to 0, and cache would never be cleared.\n*\n* Note that because all rules run together in a single AST traversal, if a rule from plugin X throws an error,\n* it can disrupt rules from plugin Y. This would make it hard to debug.\n*\n* # Mechanism\n*\n* ## Initialization\n*\n* Rules with an `after` hook register themselves by:\n*\n* 1. Calling `registerResetFunction` to register a function to run `after` hook and clean up internal state.\n* This call adds the reset fn to `resetFunctions`, and adds `AFTER_HOOK_INACTIVE` to `pendingStates`.\n* 2. Adding an `onCodePathEnd` CFG event handler to the visitor which calls `ruleFinished` at end of AST traversal.\n*\n* ## Per-file setup\n*\n* Before linting a file, `create` will call `setupAfterHook` which is created by `createContextAndVisitor`.\n* This registers that the `after` hook for the rule needs to run, by setting `pendingStates[ruleIndex]`\n* to `AFTER_HOOK_PENDING`, and incrementing `pendingCount`.\n*\n* If a cleanup microtask has not been scheduled yet, one is scheduled now (see reason below).\n*\n* ## Normal operation\n*\n* AST traversal for each rule ends with `ruleFinished` hook being called from `onCodePathEnd` CFG event handler.\n* It increments `lintFinishedCount`. If `lintFinishedCount` equals `pendingCount`, all rules have finished linting\n* the file, and `reset` is called, which calls all the pending `after` hooks.\n*\n* ## Error handling\n*\n* If an error is thrown during AST traversal, we ensure that `after` hooks are still run by 2 mechanisms:\n*\n* ### 1. Next microtick\n*\n* Before any rules began linting files, a microtask was scheduled, which runs on next micro-tick.\n* All language servers we're aware of run each lint task in a separate tick, so this microtask will run in next tick\n* after a linting run, before the next lint task starts.\n*\n* If the linting run completed successfully, the microtask does nothing.\n*\n* But if an error was thrown during AST traversal, this will be visible from the state of `pendingCount`.\n* The microtask will run any `after` hooks which need to be run, and reset state to reflect that there are\n* no more pending `after` hooks.\n*\n* ### 2. Fallback: Next lint run\n*\n* Before linting any file, the state of `pendingCount` is checked.\n* If any `after` hooks are still pending, they are run immediately.\n* They're run before the `context` objects in `createOnce` closures are updated to the next file,\n* so they run with access to the old `context` object from the last file.\n*\n* This fallback should not be required, but it's included as \"belt and braces\", to handle if any language server\n* or other environment running ESLint programmatically, does not pause a tick between linting runs.\n*/\nvar AfterHooksState = class {\n\tresetFunctions = [];\n\tpendingStates = [];\n\tpendingCount = 0;\n\tlintFinishedCount = 0;\n\tresetIsScheduled = !1;\n\tsourceCode = null;\n\tresetMicrotask = this.resetMicrotaskImpl.bind(this);\n\t/**\n\t* Register a function to run `after` hook for a rule, and reset state.\n\t* @param reset - Function to run `after` hook and reset state\n\t* @returns Index of rule\n\t*/\n\tregisterResetFunction(reset) {\n\t\tlet { pendingStates } = this, index = pendingStates.length;\n\t\treturn pendingStates.push(0), this.resetFunctions.push(reset), index;\n\t}\n\t/**\n\t* Register that a rule with `after` hook has completed linting a file.\n\t* Called by `onCodePathEnd` CFG event handler which is added to visitor for rules with `after` hooks.\n\t*\n\t* If all rules with an `after` hook which needs to be run have completed linting the file, run all `after` hooks.\n\t*/\n\truleFinished() {\n\t\tthis.lintFinishedCount++, this.lintFinishedCount === this.pendingCount && this.reset(!1);\n\t}\n\t/**\n\t* Call all reset functions where corresponding entry in `pendingStates` is `AFTER_HOOK_PENDING`.\n\t* Should only be called when some `after` hooks are pending.\n\t*\n\t* @param ignoreErrors - `true` to catch and silently ignore any errors which occur in `after` hooks.\n\t* `false` to throw them,\n\t* @throws {unknown} If `ignoreErrors` is `false` and an error occurs in any `after` hooks.\n\t*/\n\treset(ignoreErrors) {\n\t\tthis.pendingCount;\n\t\tlet { resetFunctions, pendingStates } = this, hooksLen = pendingStates.length, hasError = !1, error;\n\t\tfor (let i = 0; i < hooksLen; i++) if (pendingStates[i] !== 0) {\n\t\t\tpendingStates[i] = 0;\n\t\t\ttry {\n\t\t\t\tresetFunctions[i]();\n\t\t\t} catch (e) {\n\t\t\t\thasError === !1 && (hasError = !0, error = e);\n\t\t\t}\n\t\t}\n\t\tif (this.pendingCount = 0, this.lintFinishedCount = 0, this.sourceCode = null, hasError === !0 && ignoreErrors === !1) throw error;\n\t}\n\t/**\n\t* Schedule a microtask to run `reset` functions.\n\t*/\n\tscheduleReset() {\n\t\tqueueMicrotask(this.resetMicrotask), this.resetIsScheduled = !0;\n\t}\n\t/**\n\t* Function which is scheduled as the cleanup microtask.\n\t* `scheduleReset` uses `resetMicrotask` which is this method bound to `this`.\n\t*/\n\tresetMicrotaskImpl() {\n\t\tthis.resetIsScheduled = !1, this.pendingCount !== 0 && this.reset(!0);\n\t}\n};\n/**\n* Convert a rule.\n*\n* The `rule` object passed in is mutated in-place.\n*\n* @param rule - Rule to convert\n* @param afterHooksState - State of `after` hooks\n* @throws {Error} If `rule` is not an object\n*/\nfunction convertRule(rule, afterHooksState) {\n\tif (typeof rule != \"object\" || !rule) throw Error(\"Rule must be an object\");\n\tif (\"create\" in rule) return;\n\tlet context = null, visitor, beforeHook, setupAfterHook;\n\trule.create = (eslintContext) => {\n\t\tcontext === null && ({context, visitor, beforeHook, setupAfterHook} = createContextAndVisitor(rule, afterHooksState));\n\t\tlet eslintFileContext = Object.getPrototypeOf(eslintContext);\n\t\tif (setupAfterHook !== null) {\n\t\t\tlet { sourceCode } = eslintFileContext;\n\t\t\tafterHooksState.sourceCode !== sourceCode && (afterHooksState.sourceCode = sourceCode, afterHooksState.pendingCount !== 0 && afterHooksState.reset(!0));\n\t\t}\n\t\treturn Object.defineProperties(context, {\n\t\t\tid: { value: eslintContext.id },\n\t\t\toptions: { value: eslintContext.options },\n\t\t\treport: { value: eslintContext.report }\n\t\t}), Object.setPrototypeOf(context, eslintFileContext), beforeHook !== null && beforeHook() === !1 ? EMPTY_VISITOR : (setupAfterHook !== null && (setupAfterHook(eslintFileContext.sourceCode.ast), afterHooksState.resetIsScheduled === !1 && afterHooksState.scheduleReset()), visitor);\n\t};\n}\nconst FILE_CONTEXT = Object.freeze({\n\tget filename() {\n\t\tthrow Error(\"Cannot access `context.filename` in `createOnce`\");\n\t},\n\tgetFilename() {\n\t\tthrow Error(\"Cannot call `context.getFilename` in `createOnce`\");\n\t},\n\tget physicalFilename() {\n\t\tthrow Error(\"Cannot access `context.physicalFilename` in `createOnce`\");\n\t},\n\tgetPhysicalFilename() {\n\t\tthrow Error(\"Cannot call `context.getPhysicalFilename` in `createOnce`\");\n\t},\n\tget cwd() {\n\t\tthrow Error(\"Cannot access `context.cwd` in `createOnce`\");\n\t},\n\tgetCwd() {\n\t\tthrow Error(\"Cannot call `context.getCwd` in `createOnce`\");\n\t},\n\tget sourceCode() {\n\t\tthrow Error(\"Cannot access `context.sourceCode` in `createOnce`\");\n\t},\n\tgetSourceCode() {\n\t\tthrow Error(\"Cannot call `context.getSourceCode` in `createOnce`\");\n\t},\n\tget languageOptions() {\n\t\tthrow Error(\"Cannot access `context.languageOptions` in `createOnce`\");\n\t},\n\tget settings() {\n\t\tthrow Error(\"Cannot access `context.settings` in `createOnce`\");\n\t},\n\textend(extension) {\n\t\treturn Object.freeze(Object.assign(Object.create(this), extension));\n\t},\n\tget parserOptions() {\n\t\tthrow Error(\"Cannot access `context.parserOptions` in `createOnce`\");\n\t},\n\tget parserPath() {\n\t\tthrow Error(\"Cannot access `context.parserPath` in `createOnce`\");\n\t}\n});\n/**\n* Call `createOnce` method of rule, and return `Context`, `Visitor`, and `beforeHook` (if any).\n*\n* @param rule - Rule with `createOnce` method\n* @param afterHooksState - State of `after` hooks\n* @returns Object with `context`, `visitor`, and `beforeHook` properties,\n* and `setupAfterHook` function if visitor has an `after` hook\n*/\nfunction createContextAndVisitor(rule, afterHooksState) {\n\tlet { createOnce } = rule;\n\tif (createOnce == null) throw Error(\"Rules must define either a `create` or `createOnce` method\");\n\tif (typeof createOnce != \"function\") throw Error(\"Rule `createOnce` property must be a function\");\n\tlet context = Object.create(FILE_CONTEXT, {\n\t\tid: {\n\t\t\tvalue: null,\n\t\t\tenumerable: !0,\n\t\t\tconfigurable: !0\n\t\t},\n\t\toptions: {\n\t\t\tvalue: null,\n\t\t\tenumerable: !0,\n\t\t\tconfigurable: !0\n\t\t},\n\t\treport: {\n\t\t\tvalue() {\n\t\t\t\tthrow Error(\"Cannot report errors in `createOnce`\");\n\t\t\t},\n\t\t\tenumerable: !0,\n\t\t\tconfigurable: !0\n\t\t}\n\t}), { before: beforeHook, after: afterHook, ...visitor } = createOnce.call(rule, context);\n\tif (beforeHook === void 0) beforeHook = null;\n\telse if (beforeHook !== null && typeof beforeHook != \"function\") throw Error(\"`before` property of visitor must be a function if defined\");\n\tlet setupAfterHook = null;\n\tif (afterHook != null) {\n\t\tif (typeof afterHook != \"function\") throw Error(\"`after` property of visitor must be a function if defined\");\n\t\tlet program = null, ruleIndex = afterHooksState.registerResetFunction(() => {\n\t\t\tprogram = null, afterHook();\n\t\t});\n\t\tsetupAfterHook = (ast) => {\n\t\t\tprogram = ast, afterHooksState.pendingStates[ruleIndex] = 1, afterHooksState.pendingCount++;\n\t\t};\n\t\tlet onCodePathEnd = visitor.onCodePathEnd;\n\t\tvisitor.onCodePathEnd = onCodePathEnd == null ? function(_codePath, node) {\n\t\t\tnode === program && afterHooksState.ruleFinished();\n\t\t} : function(codePath, node) {\n\t\t\tonCodePathEnd.call(this, codePath, node), node === program && afterHooksState.ruleFinished();\n\t\t};\n\t}\n\treturn {\n\t\tcontext,\n\t\tvisitor,\n\t\tbeforeHook,\n\t\tsetupAfterHook\n\t};\n}\n//#endregion\nexport { definePlugin, defineRule, eslintCompatPlugin };\n","import { eslintCompatPlugin, type Plugin } from \"@oxlint/plugins\";\nimport { ALL_RULES } from \"./rules/registry.ts\";\n\nconst plugin: Plugin = eslintCompatPlugin({\n meta: { name: \"hook-o-gnese\" },\n rules: ALL_RULES,\n});\n\nexport const recommended = {\n jsPlugins: [\"./node_modules/hook-o-gnese/dist/index.mjs\"],\n options: { typeAware: true, typeCheck: true },\n rules: {\n \"hook-o-gnese/no-fat-effects\": \"warn\",\n \"hook-o-gnese/state-scatter\": \"warn\",\n \"hook-o-gnese/hook-coupling\": \"error\",\n \"hook-o-gnese/custom-hook-depth\": [\"warn\", { maxDepth: 3 }],\n \"typescript/no-floating-promises\": \"error\",\n \"typescript/no-misused-promises\": \"error\",\n },\n};\n\nexport default plugin;\n"],"x_google_ignoreList":[0],"mappings":";;AAyBA,MAAM,gBAAgB,EAAE;;;;;;;;;;;;;;AAcxB,SAAS,mBAAmB,QAAQ;AACnC,KAAI,OAAO,UAAU,YAAY,CAAC,OAAQ,OAAM,MAAM,2BAA2B;CACjF,IAAI,EAAE,UAAU;AAChB,KAAI,OAAO,SAAS,YAAY,CAAC,MAAO,OAAM,MAAM,iDAAiD;CACrG,IAAI,kBAAkB,IAAI,iBAAiB;AAC3C,MAAK,IAAI,YAAY,MAAO,QAAO,OAAO,OAAO,SAAS,IAAI,YAAY,MAAM,WAAW,gBAAgB;AAC3G,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,SAAiB,mBAAmB;CACxC,MAAM,EAAE,MAAM,gBAAgB;CAC9B,OAAO;CACR,CAAC;AAEF,MAAa,cAAc;CACzB,WAAW,CAAC,6CAA6C;CACzD,SAAS;EAAE,WAAW;EAAM,WAAW;EAAM;CAC7C,OAAO;EACL,+BAA+B;EAC/B,8BAA8B;EAC9B,8BAA8B;EAC9B,kCAAkC,CAAC,QAAQ,EAAE,UAAU,GAAG,CAAC;EAC3D,mCAAmC;EACnC,kCAAkC;;CAErC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../node_modules/.deno/@oxlint+plugins@1.63.0/node_modules/@oxlint/plugins/index.js","../src/index.ts"],"sourcesContent":["//#region src-js/package/define.ts\n/**\n* Define a plugin.\n*\n* No-op function, just to provide type safety. Input is passed through unchanged.\n*\n* @param plugin - Plugin to define\n* @returns Same plugin as passed in\n*/\nfunction definePlugin(plugin) {\n\treturn plugin;\n}\n/**\n* Define a rule.\n*\n* No-op function, just to provide type safety. Input is passed through unchanged.\n*\n* @param rule - Rule to define\n* @returns Same rule as passed in\n*/\nfunction defineRule(rule) {\n\treturn rule;\n}\n//#endregion\n//#region src-js/package/compat.ts\nconst EMPTY_VISITOR = {};\n/**\n* Convert a plugin which used Oxlint's `createOnce` API to also work with ESLint.\n*\n* If any of the plugin's rules use the Oxlint alternative `createOnce` API,\n* add ESLint-compatible `create` methods to those rules, which delegate to `createOnce`.\n* This makes the plugin compatible with ESLint.\n*\n* The `plugin` object passed in is mutated in-place.\n*\n* @param plugin - Plugin to convert\n* @returns Plugin with all rules having `create` method\n* @throws {Error} If `plugin` is not an object, or `plugin.rules` is not an object\n*/\nfunction eslintCompatPlugin(plugin) {\n\tif (typeof plugin != \"object\" || !plugin) throw Error(\"Plugin must be an object\");\n\tlet { rules } = plugin;\n\tif (typeof rules != \"object\" || !rules) throw Error(\"Plugin must have an object as `rules` property\");\n\tlet afterHooksState = new AfterHooksState();\n\tfor (let ruleName in rules) Object.hasOwn(rules, ruleName) && convertRule(rules[ruleName], afterHooksState);\n\treturn plugin;\n}\n/**\n* Class containing state for tracking if any `after` hooks for a plugin's rules need to be called.\n*\n* # Aims\n*\n* Aims are:\n* 1. `after` hook of each rule runs after all other AST visit functions, and CFG event handlers.\n* 2. `after` hooks for *all* a plugin's rules run after *all* that plugin's rules have completed visiting AST.\n* 3. `after` hooks for *all* a plugin's rules run before *any* of plugin's rules begin linting another file.\n* 4. In the case of an error during AST traversal, `after` hooks are always still run.\n*\n* The above exactly matches the behavior when running a `createOnce` rule in Oxlint.\n*\n* # Why this is important\n*\n* All the complication comes from ensuring `after` hooks run even after an error during AST traversal.\n*\n* In ESLint CLI, an error will crash the process, so it doesn't particularly matter if `after` hooks run or not,\n* but language servers will typically swallow errors, and keep the process running.\n*\n* Rules using `before` and `after` hooks will often rely on both hooks running in a predictable order,\n* to maintain some internal state. For example, they may use `before` and `after` hooks to maintain a per-file\n* cache of data which is shared between rules. The cache use case is why rule (2) above is important.\n*\n* Below is an example of using `before` and `after` hooks to maintain a per-file cache, shared between rules.\n* It relies on all `before` hooks running before any rule starts visiting the AST,\n* and all `after` hooks running after all rules have finished visiting the AST.\n*\n* ```ts\n* let cache: Data | null = null;\n*\n* let numRunningRules = 0;\n*\n* const setupCache = (context) => {\n* if (cache === null) cache = new Data(context);\n* numRunningRules++;\n* };\n*\n* const teardownCache = () => {\n* numRunningRules--;\n* if (numRunningRules === 0) cache = null;\n* };\n*\n* const rule1 = {\n* createOnce(context) {\n* return {\n* before() {\n* setupCache(context);\n* },\n* Identifier(node) {\n* // Use `cache`\n* },\n* after: teardownCache,\n* };\n* },\n* };\n*\n* const rule2 = {\n* // Same as above\n* };\n*\n* const rule3 = {\n* // Same as above\n* };\n* ```\n*\n* If `after` hooks did not always run, the next lint run could get stale state, and malfunction.\n* If `after` hooks ran in the wrong order (e.g. after some `before` hooks for next file),\n* `numRunningRules` would never get to 0, and cache would never be cleared.\n*\n* Note that because all rules run together in a single AST traversal, if a rule from plugin X throws an error,\n* it can disrupt rules from plugin Y. This would make it hard to debug.\n*\n* # Mechanism\n*\n* ## Initialization\n*\n* Rules with an `after` hook register themselves by:\n*\n* 1. Calling `registerResetFunction` to register a function to run `after` hook and clean up internal state.\n* This call adds the reset fn to `resetFunctions`, and adds `AFTER_HOOK_INACTIVE` to `pendingStates`.\n* 2. Adding an `onCodePathEnd` CFG event handler to the visitor which calls `ruleFinished` at end of AST traversal.\n*\n* ## Per-file setup\n*\n* Before linting a file, `create` will call `setupAfterHook` which is created by `createContextAndVisitor`.\n* This registers that the `after` hook for the rule needs to run, by setting `pendingStates[ruleIndex]`\n* to `AFTER_HOOK_PENDING`, and incrementing `pendingCount`.\n*\n* If a cleanup microtask has not been scheduled yet, one is scheduled now (see reason below).\n*\n* ## Normal operation\n*\n* AST traversal for each rule ends with `ruleFinished` hook being called from `onCodePathEnd` CFG event handler.\n* It increments `lintFinishedCount`. If `lintFinishedCount` equals `pendingCount`, all rules have finished linting\n* the file, and `reset` is called, which calls all the pending `after` hooks.\n*\n* ## Error handling\n*\n* If an error is thrown during AST traversal, we ensure that `after` hooks are still run by 2 mechanisms:\n*\n* ### 1. Next microtick\n*\n* Before any rules began linting files, a microtask was scheduled, which runs on next micro-tick.\n* All language servers we're aware of run each lint task in a separate tick, so this microtask will run in next tick\n* after a linting run, before the next lint task starts.\n*\n* If the linting run completed successfully, the microtask does nothing.\n*\n* But if an error was thrown during AST traversal, this will be visible from the state of `pendingCount`.\n* The microtask will run any `after` hooks which need to be run, and reset state to reflect that there are\n* no more pending `after` hooks.\n*\n* ### 2. Fallback: Next lint run\n*\n* Before linting any file, the state of `pendingCount` is checked.\n* If any `after` hooks are still pending, they are run immediately.\n* They're run before the `context` objects in `createOnce` closures are updated to the next file,\n* so they run with access to the old `context` object from the last file.\n*\n* This fallback should not be required, but it's included as \"belt and braces\", to handle if any language server\n* or other environment running ESLint programmatically, does not pause a tick between linting runs.\n*/\nvar AfterHooksState = class {\n\tresetFunctions = [];\n\tpendingStates = [];\n\tpendingCount = 0;\n\tlintFinishedCount = 0;\n\tresetIsScheduled = !1;\n\tsourceCode = null;\n\tresetMicrotask = this.resetMicrotaskImpl.bind(this);\n\t/**\n\t* Register a function to run `after` hook for a rule, and reset state.\n\t* @param reset - Function to run `after` hook and reset state\n\t* @returns Index of rule\n\t*/\n\tregisterResetFunction(reset) {\n\t\tlet { pendingStates } = this, index = pendingStates.length;\n\t\treturn pendingStates.push(0), this.resetFunctions.push(reset), index;\n\t}\n\t/**\n\t* Register that a rule with `after` hook has completed linting a file.\n\t* Called by `onCodePathEnd` CFG event handler which is added to visitor for rules with `after` hooks.\n\t*\n\t* If all rules with an `after` hook which needs to be run have completed linting the file, run all `after` hooks.\n\t*/\n\truleFinished() {\n\t\tthis.lintFinishedCount++, this.lintFinishedCount === this.pendingCount && this.reset(!1);\n\t}\n\t/**\n\t* Call all reset functions where corresponding entry in `pendingStates` is `AFTER_HOOK_PENDING`.\n\t* Should only be called when some `after` hooks are pending.\n\t*\n\t* @param ignoreErrors - `true` to catch and silently ignore any errors which occur in `after` hooks.\n\t* `false` to throw them,\n\t* @throws {unknown} If `ignoreErrors` is `false` and an error occurs in any `after` hooks.\n\t*/\n\treset(ignoreErrors) {\n\t\tthis.pendingCount;\n\t\tlet { resetFunctions, pendingStates } = this, hooksLen = pendingStates.length, hasError = !1, error;\n\t\tfor (let i = 0; i < hooksLen; i++) if (pendingStates[i] !== 0) {\n\t\t\tpendingStates[i] = 0;\n\t\t\ttry {\n\t\t\t\tresetFunctions[i]();\n\t\t\t} catch (e) {\n\t\t\t\thasError === !1 && (hasError = !0, error = e);\n\t\t\t}\n\t\t}\n\t\tif (this.pendingCount = 0, this.lintFinishedCount = 0, this.sourceCode = null, hasError === !0 && ignoreErrors === !1) throw error;\n\t}\n\t/**\n\t* Schedule a microtask to run `reset` functions.\n\t*/\n\tscheduleReset() {\n\t\tqueueMicrotask(this.resetMicrotask), this.resetIsScheduled = !0;\n\t}\n\t/**\n\t* Function which is scheduled as the cleanup microtask.\n\t* `scheduleReset` uses `resetMicrotask` which is this method bound to `this`.\n\t*/\n\tresetMicrotaskImpl() {\n\t\tthis.resetIsScheduled = !1, this.pendingCount !== 0 && this.reset(!0);\n\t}\n};\n/**\n* Convert a rule.\n*\n* The `rule` object passed in is mutated in-place.\n*\n* @param rule - Rule to convert\n* @param afterHooksState - State of `after` hooks\n* @throws {Error} If `rule` is not an object\n*/\nfunction convertRule(rule, afterHooksState) {\n\tif (typeof rule != \"object\" || !rule) throw Error(\"Rule must be an object\");\n\tif (\"create\" in rule) return;\n\tlet context = null, visitor, beforeHook, setupAfterHook;\n\trule.create = (eslintContext) => {\n\t\tcontext === null && ({context, visitor, beforeHook, setupAfterHook} = createContextAndVisitor(rule, afterHooksState));\n\t\tlet eslintFileContext = Object.getPrototypeOf(eslintContext);\n\t\tif (setupAfterHook !== null) {\n\t\t\tlet { sourceCode } = eslintFileContext;\n\t\t\tafterHooksState.sourceCode !== sourceCode && (afterHooksState.sourceCode = sourceCode, afterHooksState.pendingCount !== 0 && afterHooksState.reset(!0));\n\t\t}\n\t\treturn Object.defineProperties(context, {\n\t\t\tid: { value: eslintContext.id },\n\t\t\toptions: { value: eslintContext.options },\n\t\t\treport: { value: eslintContext.report }\n\t\t}), Object.setPrototypeOf(context, eslintFileContext), beforeHook !== null && beforeHook() === !1 ? EMPTY_VISITOR : (setupAfterHook !== null && (setupAfterHook(eslintFileContext.sourceCode.ast), afterHooksState.resetIsScheduled === !1 && afterHooksState.scheduleReset()), visitor);\n\t};\n}\nconst FILE_CONTEXT = Object.freeze({\n\tget filename() {\n\t\tthrow Error(\"Cannot access `context.filename` in `createOnce`\");\n\t},\n\tgetFilename() {\n\t\tthrow Error(\"Cannot call `context.getFilename` in `createOnce`\");\n\t},\n\tget physicalFilename() {\n\t\tthrow Error(\"Cannot access `context.physicalFilename` in `createOnce`\");\n\t},\n\tgetPhysicalFilename() {\n\t\tthrow Error(\"Cannot call `context.getPhysicalFilename` in `createOnce`\");\n\t},\n\tget cwd() {\n\t\tthrow Error(\"Cannot access `context.cwd` in `createOnce`\");\n\t},\n\tgetCwd() {\n\t\tthrow Error(\"Cannot call `context.getCwd` in `createOnce`\");\n\t},\n\tget sourceCode() {\n\t\tthrow Error(\"Cannot access `context.sourceCode` in `createOnce`\");\n\t},\n\tgetSourceCode() {\n\t\tthrow Error(\"Cannot call `context.getSourceCode` in `createOnce`\");\n\t},\n\tget languageOptions() {\n\t\tthrow Error(\"Cannot access `context.languageOptions` in `createOnce`\");\n\t},\n\tget settings() {\n\t\tthrow Error(\"Cannot access `context.settings` in `createOnce`\");\n\t},\n\textend(extension) {\n\t\treturn Object.freeze(Object.assign(Object.create(this), extension));\n\t},\n\tget parserOptions() {\n\t\tthrow Error(\"Cannot access `context.parserOptions` in `createOnce`\");\n\t},\n\tget parserPath() {\n\t\tthrow Error(\"Cannot access `context.parserPath` in `createOnce`\");\n\t}\n});\n/**\n* Call `createOnce` method of rule, and return `Context`, `Visitor`, and `beforeHook` (if any).\n*\n* @param rule - Rule with `createOnce` method\n* @param afterHooksState - State of `after` hooks\n* @returns Object with `context`, `visitor`, and `beforeHook` properties,\n* and `setupAfterHook` function if visitor has an `after` hook\n*/\nfunction createContextAndVisitor(rule, afterHooksState) {\n\tlet { createOnce } = rule;\n\tif (createOnce == null) throw Error(\"Rules must define either a `create` or `createOnce` method\");\n\tif (typeof createOnce != \"function\") throw Error(\"Rule `createOnce` property must be a function\");\n\tlet context = Object.create(FILE_CONTEXT, {\n\t\tid: {\n\t\t\tvalue: null,\n\t\t\tenumerable: !0,\n\t\t\tconfigurable: !0\n\t\t},\n\t\toptions: {\n\t\t\tvalue: null,\n\t\t\tenumerable: !0,\n\t\t\tconfigurable: !0\n\t\t},\n\t\treport: {\n\t\t\tvalue() {\n\t\t\t\tthrow Error(\"Cannot report errors in `createOnce`\");\n\t\t\t},\n\t\t\tenumerable: !0,\n\t\t\tconfigurable: !0\n\t\t}\n\t}), { before: beforeHook, after: afterHook, ...visitor } = createOnce.call(rule, context);\n\tif (beforeHook === void 0) beforeHook = null;\n\telse if (beforeHook !== null && typeof beforeHook != \"function\") throw Error(\"`before` property of visitor must be a function if defined\");\n\tlet setupAfterHook = null;\n\tif (afterHook != null) {\n\t\tif (typeof afterHook != \"function\") throw Error(\"`after` property of visitor must be a function if defined\");\n\t\tlet program = null, ruleIndex = afterHooksState.registerResetFunction(() => {\n\t\t\tprogram = null, afterHook();\n\t\t});\n\t\tsetupAfterHook = (ast) => {\n\t\t\tprogram = ast, afterHooksState.pendingStates[ruleIndex] = 1, afterHooksState.pendingCount++;\n\t\t};\n\t\tlet onCodePathEnd = visitor.onCodePathEnd;\n\t\tvisitor.onCodePathEnd = onCodePathEnd == null ? function(_codePath, node) {\n\t\t\tnode === program && afterHooksState.ruleFinished();\n\t\t} : function(codePath, node) {\n\t\t\tonCodePathEnd.call(this, codePath, node), node === program && afterHooksState.ruleFinished();\n\t\t};\n\t}\n\treturn {\n\t\tcontext,\n\t\tvisitor,\n\t\tbeforeHook,\n\t\tsetupAfterHook\n\t};\n}\n//#endregion\nexport { definePlugin, defineRule, eslintCompatPlugin };\n","/**\n * Oxlint plugin entrypoint for `hook-o-gnese`.\n *\n * Exports the plugin as the default export and a `recommended` config that\n * bundles the package's hook-complexity rules together with the type-aware\n * tsgolint built-ins it relies on.\n *\n * @example\n * ```ts\n * // oxlint.config.ts\n * import hookOGnese, { recommended } from \"hook-o-gnese\";\n * export default { plugins: [hookOGnese], ...recommended };\n * ```\n *\n * @module\n */\n\nimport { eslintCompatPlugin, type Plugin } from \"@oxlint/plugins\";\nimport { ALL_RULES } from \"./rules/registry.ts\";\n\nconst plugin: Plugin = eslintCompatPlugin({\n meta: { name: \"hook-o-gnese\" },\n rules: ALL_RULES,\n});\n\n/**\n * Recommended oxlint configuration for `hook-o-gnese`.\n *\n * Enables every rule the plugin ships with sensible severities, plus the\n * tsgolint type-aware rules required for full coverage. Spread into your\n * oxlint config alongside the default plugin export.\n */\nexport const recommended = {\n jsPlugins: [\"./node_modules/hook-o-gnese/dist/index.mjs\"],\n options: { typeAware: true, typeCheck: true },\n rules: {\n \"hook-o-gnese/no-fat-effects\": \"warn\",\n \"hook-o-gnese/state-scatter\": \"warn\",\n \"hook-o-gnese/hook-coupling\": \"error\",\n \"hook-o-gnese/custom-hook-depth\": [\"warn\", { maxDepth: 3 }],\n \"typescript/no-floating-promises\": \"error\",\n \"typescript/no-misused-promises\": \"error\",\n },\n};\n\n/**\n * The `hook-o-gnese` oxlint plugin. Register as a plugin in your oxlint config\n * to enable React hook complexity rules.\n */\nexport default plugin;\n"],"x_google_ignoreList":[0],"mappings":";;AAyBA,MAAM,gBAAgB,EAAE;;;;;;;;;;;;;;AAcxB,SAAS,mBAAmB,QAAQ;AACnC,KAAI,OAAO,UAAU,YAAY,CAAC,OAAQ,OAAM,MAAM,2BAA2B;CACjF,IAAI,EAAE,UAAU;AAChB,KAAI,OAAO,SAAS,YAAY,CAAC,MAAO,OAAM,MAAM,iDAAiD;CACrG,IAAI,kBAAkB,IAAI,iBAAiB;AAC3C,MAAK,IAAI,YAAY,MAAO,QAAO,OAAO,OAAO,SAAS,IAAI,YAAY,MAAM,WAAW,gBAAgB;AAC3G,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6HR,IAAI,kBAAkB,MAAM;CAC3B,iBAAiB,EAAE;CACnB,gBAAgB,EAAE;CAClB,eAAe;CACf,oBAAoB;CACpB,mBAAmB,CAAC;CACpB,aAAa;CACb,iBAAiB,KAAK,mBAAmB,KAAK,KAAK;;;;;;CAMnD,sBAAsB,OAAO;EAC5B,IAAI,EAAE,kBAAkB,MAAM,QAAQ,cAAc;AACpD,SAAO,cAAc,KAAK,EAAE,EAAE,KAAK,eAAe,KAAK,MAAM,EAAE;;;;;;;;CAQhE,eAAe;AACd,OA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;GACP,QAAQ;AACP,UAAM,MAAM,uCAAuC;;GAEpD,YAAY,CAAC;GACb,cAAc,CAAC;;EAEhB,CAAC,EAAE,EAAE,QAAQ,YAAY,OAAO,WAAW,GAAG,YAAY,WAAW,KAAK,MAAM,QAAQ;AACzF,KAAI,eAAe,KAAK,EAAG,cAAa;UAC/B,eAAe,QAAQ,OAAO,cAAc,WAAY,OAAM,MAAM,6DAA6D;CAC1I,IAAI,iBAAiB;AACrB,KAAI,aAAa,MAAM;AACtB,MAAI,OAAO,aAAa,WAAY,OAAM,MAAM,4DAA4D;EAC5G,IAAI,UAAU,MAAM,YAAY,gBAAgB,4BAA4B;AAC3E,aAAU,MAAM,WAAW;IAC1B;AACF,oBAAkB,QAAQ;AACzB,aAAU,KAAK,gBAAgB,cAAc,aAAa,GAAG,gBAAgB;;EAE9E,IAAI,gBAAgB,QAAQ;AAC5B,UAAQ,gBAAgB,iBAAiB,OAAO,SAAS,WAAW,MAAM;AACzE,YAAS,WAAW,gBAAgB,cAAc;MAC/C,SAAS,UAAU,MAAM;AAC5B,iBAAc,KAAK,MAAM,UAAU,KAAK,EAAE,SAAS,WAAW,gBAAgB,cAAc;;;AAG9F,QAAO;EACN;EACA;EACA;EACA;EACA;;;;;;;;;;;;;;;;;;;;AC7UF,MAAM,SAAiB,mBAAmB;CACxC,MAAM,EAAE,MAAM,gBAAgB;CAC9B,OAAO;CACR,CAAC;;;;;;;;AASF,MAAa,cAAc;CACzB,WAAW,CAAC,6CAA6C;CACzD,SAAS;EAAE,WAAW;EAAM,WAAW;EAAM;CAC7C,OAAO;EACL,+BAA+B;EAC/B,8BAA8B;EAC9B,8BAA8B;EAC9B,kCAAkC,CAAC,QAAQ,EAAE,UAAU,GAAG,CAAC;EAC3D,mCAAmC;EACnC,kCAAkC;;CAErC"}
@@ -1,4 +1,5 @@
1
- import ts from "typescript";
1
+ import { createRequire } from "node:module";
2
+ import { join } from "node:path";
2
3
  //#region src/ast-helpers.ts
3
4
  const HOOK_RE = /^use[A-Z]/;
4
5
  function getHookName(node) {
@@ -315,14 +316,41 @@ const hookCoupling = {
315
316
  };
316
317
  //#endregion
317
318
  //#region src/ts-program.ts
319
+ const tsCache = /* @__PURE__ */ new Map();
320
+ function requireFromCwd(cwd) {
321
+ return createRequire(join(cwd, "_"));
322
+ }
323
+ function loadTs(cwd) {
324
+ const cached = tsCache.get(cwd);
325
+ if (cached) return cached;
326
+ try {
327
+ const mod = requireFromCwd(cwd)("typescript");
328
+ const lib = mod.default ?? mod;
329
+ tsCache.set(cwd, lib);
330
+ return lib;
331
+ } catch (err) {
332
+ throw new Error("hook-o-gnese: --type-aware requires the 'typescript' package to be installed in your project. Install it with: npm i -D typescript@>=6", { cause: err });
333
+ }
334
+ }
335
+ function isTypescriptAvailable(cwd) {
336
+ try {
337
+ loadTs(cwd);
338
+ return true;
339
+ } catch {
340
+ return false;
341
+ }
342
+ }
318
343
  var TsProgramCache = class {
319
344
  program = null;
320
345
  rootDir;
346
+ ts;
321
347
  constructor(rootDir) {
322
348
  this.rootDir = rootDir;
349
+ this.ts = loadTs(rootDir);
323
350
  }
324
351
  getProgram() {
325
352
  if (this.program) return this.program;
353
+ const ts = this.ts;
326
354
  const configPath = ts.findConfigFile(this.rootDir, ts.sys.fileExists, "tsconfig.json");
327
355
  let compilerOptions = {
328
356
  target: ts.ScriptTarget.ESNext,
@@ -349,6 +377,7 @@ var TsProgramCache = class {
349
377
  return this.program;
350
378
  }
351
379
  resolveIdentifierDeclaration(filePath, identifier) {
380
+ const ts = this.ts;
352
381
  const program = this.getProgram();
353
382
  const checker = program.getTypeChecker();
354
383
  const absolute = filePath.startsWith("/") ? filePath : `${this.rootDir.replace(/\/$/, "")}/${filePath}`;
@@ -372,6 +401,7 @@ var TsProgramCache = class {
372
401
  countTransitiveHookCalls(decl, depth = 0, seen = /* @__PURE__ */ new Set()) {
373
402
  if (depth > 10 || seen.has(decl)) return depth;
374
403
  seen.add(decl);
404
+ const ts = this.ts;
375
405
  const checker = this.getProgram().getTypeChecker();
376
406
  let maxDepth = depth;
377
407
  const visit = (node) => {
@@ -455,6 +485,6 @@ const ALL_RULES = {
455
485
  }
456
486
  };
457
487
  //#endregion
458
- export { ALL_RULES as t };
488
+ export { isTypescriptAvailable as n, ALL_RULES as t };
459
489
 
460
- //# sourceMappingURL=registry-iRG6wil9.mjs.map
490
+ //# sourceMappingURL=registry-YXM4yhf2.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry-YXM4yhf2.mjs","names":["joinPath"],"sources":["../src/ast-helpers.ts","../src/scoring/effect-score.ts","../src/scoring/thresholds.ts","../src/rules/no-fat-effects.ts","../src/scoring/state-score.ts","../src/rules/state-scatter.ts","../src/scoring/coupling-score.ts","../src/rules/hook-coupling.ts","../src/ts-program.ts","../src/rules/custom-hook-depth.ts","../src/rules/registry.ts"],"sourcesContent":["type Node = { type: string; [k: string]: unknown };\n\nconst HOOK_RE = /^use[A-Z]/;\n\nexport function getHookName(node: Node): string | null {\n if (node.type !== \"CallExpression\") return null;\n const callee = (node as any).callee as Node;\n if (callee?.type !== \"Identifier\") return null;\n const name = (callee as any).name as string;\n return HOOK_RE.test(name) ? name : null;\n}\n\nexport function isHookCall(node: Node, expected: string): boolean {\n return getHookName(node) === expected;\n}\n\nexport function isReactComponent(node: Node): boolean {\n if (node.type === \"FunctionDeclaration\") {\n const name = (node as any).id?.name as string | undefined;\n if (!name || !/^[A-Z]/.test(name)) return false;\n return findReturnsJSX(node);\n }\n if (node.type === \"VariableDeclaration\") {\n const decl = (node as any).declarations?.[0];\n const name = decl?.id?.name as string | undefined;\n const init = decl?.init as Node | undefined;\n if (!name || !/^[A-Z]/.test(name) || !init) return false;\n if (\n init.type === \"ArrowFunctionExpression\" ||\n init.type === \"FunctionExpression\"\n ) {\n return findReturnsJSX(init);\n }\n }\n return false;\n}\n\nexport function findReturnsJSX(node: Node): boolean {\n let found = false;\n walk(node, (n) => {\n if (\n n.type === \"JSXElement\" ||\n n.type === \"JSXFragment\" ||\n n.type === \"JSXSelfClosingElement\"\n ) {\n found = true;\n return false;\n }\n return true;\n });\n return found;\n}\n\nexport function walk(\n node: Node,\n visit: (n: Node) => boolean | void,\n seen: WeakSet<Node> = new WeakSet(),\n): void {\n if (seen.has(node)) return;\n seen.add(node);\n const cont = visit(node);\n if (cont === false) return;\n for (const key in node) {\n if (key === \"parent\") continue;\n const val = (node as any)[key];\n if (Array.isArray(val)) {\n for (const child of val) {\n if (child && typeof child === \"object\" && \"type\" in child) {\n walk(child as Node, visit, seen);\n }\n }\n } else if (val && typeof val === \"object\" && \"type\" in val) {\n walk(val as Node, visit, seen);\n }\n }\n}\n","import { walk } from \"../ast-helpers.ts\";\n\ntype Node = { type: string; [k: string]: unknown };\n\nexport interface EffectScore {\n deps: number;\n branches: number;\n setStateCount: number;\n nestedEffects: number;\n hasCleanup: boolean;\n hasSubscriptionLike: boolean;\n total: number;\n}\n\nconst SET_STATE_RE = /^set[A-Z]/;\nconst BRANCH_TYPES = new Set([\n \"IfStatement\",\n \"ConditionalExpression\",\n \"SwitchCase\",\n \"LogicalExpression\",\n]);\n\nexport function scoreEffect(node: Node): EffectScore {\n const args = (node as any).arguments as Node[];\n const fn = args?.[0] as Node | undefined;\n const depsArr = args?.[1] as any;\n\n const deps = Array.isArray(depsArr?.elements) ? depsArr.elements.length : 0;\n let branches = 0;\n let setStateCount = 0;\n let nestedEffects = 0;\n let hasCleanup = false;\n let hasSubscriptionLike = false;\n\n if (fn) {\n const body = (fn as any).body as Node;\n if (body?.type === \"BlockStatement\") {\n for (const stmt of (body as any).body as Node[]) {\n if (stmt.type === \"ReturnStatement\") {\n const arg = (stmt as any).argument as Node | undefined;\n if (\n arg &&\n (arg.type === \"ArrowFunctionExpression\" ||\n arg.type === \"FunctionExpression\")\n ) hasCleanup = true;\n }\n }\n }\n\n walk(fn, (n) => {\n if (BRANCH_TYPES.has(n.type)) branches++;\n if (n.type === \"CallExpression\") {\n const callee = (n as any).callee as Node;\n if (callee?.type === \"Identifier\") {\n const name = (callee as any).name as string;\n if (SET_STATE_RE.test(name)) setStateCount++;\n if (name === \"useEffect\" && n !== node) nestedEffects++;\n if (\n name === \"addEventListener\" ||\n name === \"subscribe\" ||\n name === \"setInterval\" ||\n name === \"setTimeout\"\n ) hasSubscriptionLike = true;\n }\n if (callee?.type === \"MemberExpression\") {\n const prop = (callee as any).property as Node;\n if (prop?.type === \"Identifier\") {\n const name = (prop as any).name as string;\n if (\n name === \"addEventListener\" ||\n name === \"subscribe\" ||\n name === \"on\"\n ) hasSubscriptionLike = true;\n }\n }\n }\n return true;\n });\n }\n\n const cleanupPenalty = hasSubscriptionLike && !hasCleanup ? 3 : 0;\n const total = deps + branches * 2 + setStateCount * 1.5 +\n nestedEffects * 5 + cleanupPenalty;\n\n return {\n deps,\n branches,\n setStateCount,\n nestedEffects,\n hasCleanup,\n hasSubscriptionLike,\n total,\n };\n}\n","export interface Thresholds {\n fatEffect: { warn: number; error: number };\n stateScatter: { warn: number; error: number };\n hookCoupling: { warn: number; error: number };\n customHookDepth: { warn: number; error: number };\n}\n\nexport const DEFAULT_THRESHOLDS: Thresholds = {\n fatEffect: { warn: 10, error: 20 },\n stateScatter: { warn: 5, error: 8 },\n hookCoupling: { warn: 3, error: 6 },\n customHookDepth: { warn: 3, error: 5 },\n};\n","import { scoreEffect } from \"../scoring/effect-score.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { isHookCall } from \"../ast-helpers.ts\";\n\ninterface Options {\n threshold?: number;\n errorThreshold?: number;\n}\n\nexport interface RuleContext {\n options: unknown[];\n filename?: string;\n cwd?: string;\n report: (d: {\n message: string;\n node: unknown;\n severity?: \"warn\" | \"error\";\n }) => void;\n}\n\nexport const noFatEffects = {\n meta: {\n type: \"suggestion\" as const,\n docs: { description: \"Flag dense useEffect blocks\" },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const threshold = opts.threshold ?? DEFAULT_THRESHOLDS.fatEffect.warn;\n const errorThreshold = opts.errorThreshold ??\n DEFAULT_THRESHOLDS.fatEffect.error;\n return {\n CallExpression(node: any) {\n if (!isHookCall(node, \"useEffect\")) return;\n const score = scoreEffect(node);\n if (score.total >= threshold) {\n const breakdown = `deps=${score.deps} branches=${score.branches} ` +\n `setStates=${score.setStateCount} nested=${score.nestedEffects}` +\n (score.hasSubscriptionLike && !score.hasCleanup\n ? \" missing-cleanup\"\n : \"\");\n const severity = score.total >= errorThreshold ? \"error\" : \"warn\";\n context.report({\n message: `useEffect entropy ${\n score.total.toFixed(1)\n } ≥ ${threshold} (${breakdown})`,\n node,\n severity,\n });\n }\n },\n };\n },\n};\n","import { isHookCall, walk } from \"../ast-helpers.ts\";\n\ntype Node = { type: string; [k: string]: unknown };\n\nexport interface StateScore {\n useStateCount: number;\n correlatedSetters: number;\n total: number;\n}\n\nexport function scoreComponentState(componentNode: Node): StateScore {\n const setterNames = new Set<string>();\n let useStateCount = 0;\n\n // First pass: collect useState setters\n walk(componentNode, (n) => {\n if (!n) return true;\n if (n.type === \"VariableDeclarator\") {\n const init = (n as any).init as Node | undefined;\n const id = (n as any).id as Node | undefined;\n if (\n init?.type === \"CallExpression\" &&\n isHookCall(init, \"useState\") &&\n id?.type === \"ArrayPattern\"\n ) {\n useStateCount++;\n const els = (id as any).elements as Node[];\n const setter = els?.[1];\n if (setter?.type === \"Identifier\") {\n setterNames.add((setter as any).name as string);\n }\n }\n }\n return true;\n });\n\n // Second pass: count correlated setters\n let correlatedSetters = 0;\n walk(componentNode, (n) => {\n if (!n) return true;\n if (\n n.type === \"FunctionDeclaration\" ||\n n.type === \"FunctionExpression\" ||\n n.type === \"ArrowFunctionExpression\"\n ) {\n const calledSetters = new Set<string>();\n walk(n, (m) => {\n if (!m) return true;\n if (m.type === \"CallExpression\") {\n const callee = (m as any).callee as Node;\n if (callee?.type === \"Identifier\") {\n const name = (callee as any).name as string;\n if (setterNames.has(name)) calledSetters.add(name);\n }\n }\n return true;\n });\n if (calledSetters.size >= 2) correlatedSetters += calledSetters.size;\n }\n return true;\n });\n\n const total = useStateCount + correlatedSetters * 0.5;\n return { useStateCount, correlatedSetters, total };\n}\n","import { scoreComponentState } from \"../scoring/state-score.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { isReactComponent } from \"../ast-helpers.ts\";\nimport type { RuleContext } from \"./no-fat-effects.ts\";\n\ninterface Options {\n threshold?: number;\n errorThreshold?: number;\n}\n\nexport const stateScatter = {\n meta: {\n type: \"suggestion\" as const,\n docs: { description: \"Flag components with too many useState calls\" },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const threshold = opts.threshold ?? DEFAULT_THRESHOLDS.stateScatter.warn;\n const errorThreshold = opts.errorThreshold ??\n DEFAULT_THRESHOLDS.stateScatter.error;\n function check(node: any) {\n if (!isReactComponent(node)) return;\n const s = scoreComponentState(node);\n if (s.total >= threshold) {\n const severity = s.total >= errorThreshold ? \"error\" : \"warn\";\n context.report({\n message:\n `state scatter ${s.total} ≥ ${threshold} (useStates=${s.useStateCount}, correlated setters=${s.correlatedSetters}). Consider useReducer.`,\n node,\n severity,\n });\n }\n }\n return {\n FunctionDeclaration: check,\n VariableDeclaration: check,\n };\n },\n};\n","import { isHookCall, walk } from \"../ast-helpers.ts\";\n\ntype Node = { type: string; [k: string]: unknown };\n\nexport interface CouplingScore {\n total: number;\n readWriteSame: Array<{ state: string; effect: Node }>;\n}\n\nexport function scoreCoupling(componentNode: Node): CouplingScore {\n const stateBySetter = new Map<string, string>();\n walk(componentNode, (n) => {\n if (n.type === \"VariableDeclarator\") {\n const init = (n as any).init as Node | undefined;\n const id = (n as any).id as Node | undefined;\n if (\n init?.type === \"CallExpression\" &&\n isHookCall(init, \"useState\") &&\n id?.type === \"ArrayPattern\"\n ) {\n const els = (id as any).elements as Node[];\n const stateId = els?.[0];\n const setterId = els?.[1];\n if (stateId?.type === \"Identifier\" && setterId?.type === \"Identifier\") {\n stateBySetter.set(\n (setterId as any).name as string,\n (stateId as any).name as string,\n );\n }\n }\n }\n return true;\n });\n\n const readWriteSame: Array<{ state: string; effect: Node }> = [];\n let total = 0;\n\n walk(componentNode, (n) => {\n if (n.type === \"CallExpression\" && isHookCall(n, \"useEffect\")) {\n const effectFn = ((n as any).arguments as Node[])?.[0];\n if (!effectFn) return true;\n\n const stateRefs = new Set<string>();\n const stateWrites = new Set<string>();\n const stateNames = new Set(stateBySetter.values());\n\n walk(effectFn, (m) => {\n if (m.type === \"Identifier\") {\n const name = (m as any).name as string;\n if (stateNames.has(name)) stateRefs.add(name);\n }\n if (m.type === \"CallExpression\") {\n const callee = (m as any).callee as Node;\n if (callee?.type === \"Identifier\") {\n const setter = (callee as any).name as string;\n const stateName = stateBySetter.get(setter);\n if (stateName) stateWrites.add(stateName);\n }\n }\n return true;\n });\n\n for (const written of stateWrites) {\n if (stateRefs.has(written)) {\n readWriteSame.push({ state: written, effect: n });\n total += 3;\n }\n }\n }\n return true;\n });\n\n return { total, readWriteSame };\n}\n","import { scoreCoupling } from \"../scoring/coupling-score.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { isReactComponent } from \"../ast-helpers.ts\";\nimport type { RuleContext } from \"./no-fat-effects.ts\";\n\ninterface Options {\n threshold?: number;\n errorThreshold?: number;\n}\n\nexport const hookCoupling = {\n meta: {\n type: \"problem\" as const,\n docs: {\n description: \"Flag effects that read state they also write (loop bait)\",\n },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const threshold = opts.threshold ?? DEFAULT_THRESHOLDS.hookCoupling.warn;\n const errorThreshold = opts.errorThreshold ??\n DEFAULT_THRESHOLDS.hookCoupling.error;\n function check(node: any) {\n if (!isReactComponent(node)) return;\n const s = scoreCoupling(node);\n if (s.total < threshold) return;\n const severity = s.total >= errorThreshold ? \"error\" : \"warn\";\n for (const v of s.readWriteSame) {\n context.report({\n message:\n `useEffect reads + writes same state '${v.state}' (loop risk)`,\n node: v.effect,\n severity,\n });\n }\n }\n return { FunctionDeclaration: check, VariableDeclaration: check };\n },\n};\n","import { createRequire } from \"node:module\";\nimport { join as joinPath } from \"node:path\";\nimport type ts from \"typescript\";\n\ntype TS = typeof ts;\n\n// Per-cwd cache: different consumers may resolve to different `typescript`\n// installs, so the cache key must include cwd.\nconst tsCache = new Map<string, TS>();\n\n// Resolve from a fictitious file inside the consumer's CWD so Node walks UP\n// their project tree (finding their installed `typescript`), not ours. This\n// matters for `npx`, where the package lives in npm's npx cache.\nfunction requireFromCwd(cwd: string) {\n return createRequire(joinPath(cwd, \"_\"));\n}\n\nfunction loadTs(cwd: string): TS {\n const cached = tsCache.get(cwd);\n if (cached) return cached;\n try {\n const mod = requireFromCwd(cwd)(\"typescript\") as TS | { default: TS };\n const lib = ((mod as { default?: TS }).default ?? mod) as TS;\n tsCache.set(cwd, lib);\n return lib;\n } catch (err) {\n throw new Error(\n \"hook-o-gnese: --type-aware requires the 'typescript' package to be \" +\n \"installed in your project. Install it with: npm i -D typescript@>=6\",\n { cause: err as Error },\n );\n }\n}\n\nexport function isTypescriptAvailable(cwd: string): boolean {\n try {\n loadTs(cwd);\n return true;\n } catch {\n return false;\n }\n}\n\nexport class TsProgramCache {\n private program: ts.Program | null = null;\n private rootDir: string;\n private ts: TS;\n\n constructor(rootDir: string) {\n this.rootDir = rootDir;\n this.ts = loadTs(rootDir);\n }\n\n private getProgram(): ts.Program {\n if (this.program) return this.program;\n const ts = this.ts;\n const configPath = ts.findConfigFile(\n this.rootDir,\n ts.sys.fileExists,\n \"tsconfig.json\",\n );\n let compilerOptions: ts.CompilerOptions = {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n jsx: ts.JsxEmit.Preserve,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n allowJs: true,\n noEmit: true,\n skipLibCheck: true,\n strict: false,\n };\n let fileNames: string[] = [];\n if (configPath) {\n const cfg = ts.readConfigFile(configPath, ts.sys.readFile);\n const configDir = configPath.slice(0, configPath.lastIndexOf(\"/\"));\n const parsed = ts.parseJsonConfigFileContent(\n cfg.config,\n ts.sys,\n configDir,\n );\n compilerOptions = { ...compilerOptions, ...parsed.options };\n fileNames = parsed.fileNames;\n }\n this.program = ts.createProgram(fileNames, compilerOptions);\n return this.program;\n }\n\n resolveIdentifierDeclaration(\n filePath: string,\n identifier: string,\n ): ts.Declaration | null {\n const ts = this.ts;\n const program = this.getProgram();\n const checker = program.getTypeChecker();\n const absolute = filePath.startsWith(\"/\")\n ? filePath\n : `${this.rootDir.replace(/\\/$/, \"\")}/${filePath}`;\n const sourceFile = program.getSourceFile(absolute) ??\n program.getSourceFile(filePath);\n if (!sourceFile) return null;\n\n let target: ts.Node | null = null;\n function find(node: ts.Node) {\n if (target) return;\n if (ts.isIdentifier(node) && node.text === identifier) {\n target = node;\n return;\n }\n ts.forEachChild(node, find);\n }\n find(sourceFile);\n if (!target) return null;\n\n const symbol = checker.getSymbolAtLocation(target);\n if (!symbol) return null;\n const aliased = symbol.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(symbol)\n : symbol;\n return aliased.declarations?.[0] ?? null;\n }\n\n countTransitiveHookCalls(\n decl: ts.Declaration,\n depth = 0,\n seen = new Set<ts.Declaration>(),\n ): number {\n if (depth > 10 || seen.has(decl)) return depth;\n seen.add(decl);\n const ts = this.ts;\n const program = this.getProgram();\n const checker = program.getTypeChecker();\n let maxDepth = depth;\n\n const visit = (node: ts.Node) => {\n if (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n /^use[A-Z]/.test(node.expression.text)\n ) {\n const sym = checker.getSymbolAtLocation(node.expression);\n if (sym) {\n const aliased = sym.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(sym)\n : sym;\n const innerDecl = aliased.declarations?.[0];\n if (innerDecl) {\n const sf = innerDecl.getSourceFile();\n if (\n sf.fileName.includes(\"node_modules/@types/react\") ||\n sf.fileName.includes(\"node_modules/react/\")\n ) {\n maxDepth = Math.max(maxDepth, depth + 1);\n } else {\n const childDepth = this.countTransitiveHookCalls(\n innerDecl,\n depth + 1,\n seen,\n );\n maxDepth = Math.max(maxDepth, childDepth);\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(decl);\n return maxDepth;\n }\n}\n","import { TsProgramCache } from \"../ts-program.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { getHookName } from \"../ast-helpers.ts\";\nimport type { RuleContext } from \"./no-fat-effects.ts\";\n\ninterface Options {\n maxDepth?: number;\n errorMaxDepth?: number;\n}\n\nconst REACT_HOOKS = new Set([\n \"useState\",\n \"useEffect\",\n \"useLayoutEffect\",\n \"useMemo\",\n \"useCallback\",\n \"useReducer\",\n \"useContext\",\n \"useRef\",\n \"useImperativeHandle\",\n \"useDebugValue\",\n \"useId\",\n \"useTransition\",\n \"useDeferredValue\",\n \"useSyncExternalStore\",\n \"useInsertionEffect\",\n]);\n\nlet sharedCache: TsProgramCache | null = null;\n\nexport const customHookDepth = {\n meta: {\n type: \"suggestion\" as const,\n docs: {\n description:\n \"Flag custom hooks whose transitive nesting exceeds maxDepth (type-aware).\",\n },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const maxDepth = opts.maxDepth ?? DEFAULT_THRESHOLDS.customHookDepth.warn;\n const errorMaxDepth = opts.errorMaxDepth ??\n DEFAULT_THRESHOLDS.customHookDepth.error;\n const g = globalThis as {\n Deno?: { cwd(): string };\n process?: { cwd(): string };\n };\n const cwd = context.cwd ?? g.process?.cwd() ?? g.Deno?.cwd() ?? \".\";\n sharedCache ??= new TsProgramCache(cwd);\n const cache = sharedCache;\n const filename = context.filename;\n\n return {\n CallExpression(node: any) {\n const name = getHookName(node);\n if (!name || REACT_HOOKS.has(name)) return;\n if (!filename) return;\n const decl = cache.resolveIdentifierDeclaration(filename, name);\n if (!decl) return;\n const depth = cache.countTransitiveHookCalls(decl);\n if (depth >= maxDepth) {\n const severity = depth >= errorMaxDepth ? \"error\" : \"warn\";\n context.report({\n message:\n `custom hook '${name}' transitive depth ${depth} ≥ ${maxDepth}`,\n node,\n severity,\n });\n }\n },\n };\n },\n};\n","import type { Rule } from \"@oxlint/plugins\";\nimport { noFatEffects } from \"./no-fat-effects.ts\";\nimport { stateScatter } from \"./state-scatter.ts\";\nimport { hookCoupling } from \"./hook-coupling.ts\";\nimport { customHookDepth } from \"./custom-hook-depth.ts\";\n\n// Rules use our internal ESLint-compatible RuleContext shape; eslintCompatPlugin\n// adapts them to oxlint's stricter Rule contract at runtime.\nexport const ALL_RULES: Record<string, Rule> = {\n \"no-fat-effects\": noFatEffects as unknown as Rule,\n \"state-scatter\": stateScatter as unknown as Rule,\n \"hook-coupling\": hookCoupling as unknown as Rule,\n \"custom-hook-depth\": customHookDepth as unknown as Rule,\n};\n\nexport type RuleId =\n | \"no-fat-effects\"\n | \"state-scatter\"\n | \"hook-coupling\"\n | \"custom-hook-depth\";\n"],"mappings":";;;AAEA,MAAM,UAAU;AAEhB,SAAgB,YAAY,MAA2B;AACrD,KAAI,KAAK,SAAS,iBAAkB,QAAO;CAC3C,MAAM,SAAU,KAAa;AAC7B,KAAI,QAAQ,SAAS,aAAc,QAAO;CAC1C,MAAM,OAAQ,OAAe;AAC7B,QAAO,QAAQ,KAAK,KAAK,GAAG,OAAO;;AAGrC,SAAgB,WAAW,MAAY,UAA2B;AAChE,QAAO,YAAY,KAAK,KAAK;;AAG/B,SAAgB,iBAAiB,MAAqB;AACpD,KAAI,KAAK,SAAS,uBAAuB;EACvC,MAAM,OAAQ,KAAa,IAAI;AAC/B,MAAI,CAAC,QAAQ,CAAC,SAAS,KAAK,KAAK,CAAE,QAAO;AAC1C,SAAO,eAAe,KAAK;;AAE7B,KAAI,KAAK,SAAS,uBAAuB;EACvC,MAAM,OAAQ,KAAa,eAAe;EAC1C,MAAM,OAAO,MAAM,IAAI;EACvB,MAAM,OAAO,MAAM;AACnB,MA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UAAU,KAAK;AAC/D,QAAI,CAAC,KAAM;IACX,MAAM,QAAQ,MAAM,yBAAyB,KAAK;AAClD,QAAI,SAAS,UAAU;KACrB,MAAM,WAAW,SAAS,gBAAgB,UAAU;AACpD,aAAQ,OAAO;MACb,SACE,gBAAgB,KAAK,qBAAqB,MAAM,KAAK;MACvD;MACA;MACD,CAAC;;MAGP;;EC1DkB;CACtB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hook-o-gnese",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Score React hook complexity. Runs as oxlint plugin or standalone CLI.",
5
5
  "type": "module",
6
6
  "module": "./dist/index.mjs",
@@ -52,6 +52,9 @@
52
52
  "peerDependenciesMeta": {
53
53
  "oxlint": {
54
54
  "optional": true
55
+ },
56
+ "typescript": {
57
+ "optional": true
55
58
  }
56
59
  },
57
60
  "dependencies": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"engine-DJFFKwTZ.mjs","names":[],"sources":["../src/engine.ts"],"sourcesContent":["import { parseSync } from \"oxc-parser\";\nimport { ALL_RULES } from \"./rules/registry.ts\";\n\nexport type Severity = \"off\" | \"warn\" | \"error\";\n\nexport interface Diagnostic {\n file: string;\n rule: string;\n severity: Exclude<Severity, \"off\">;\n message: string;\n line: number;\n column: number;\n endLine?: number;\n endColumn?: number;\n}\n\nexport interface RuleConfig {\n severity: Severity;\n options?: unknown;\n}\n\nexport interface EngineConfig {\n rules: Record<string, RuleConfig>;\n cwd: string;\n typeAware: boolean;\n}\n\nconst TYPE_AWARE_RULES = new Set([\"hook-o-gnese/custom-hook-depth\"]);\n\nfunction ruleNamespace(id: string): string {\n return id.replace(/^hook-o-gnese\\//, \"\");\n}\n\nfunction buildLineOffsets(source: string): number[] {\n const offsets = [0];\n for (let i = 0; i < source.length; i++) {\n if (source.charCodeAt(i) === 10) offsets.push(i + 1);\n }\n return offsets;\n}\n\nfunction offsetToLineCol(\n offset: number,\n lineOffsets: number[],\n): { line: number; column: number } {\n let lo = 0;\n let hi = lineOffsets.length - 1;\n while (lo < hi) {\n const mid = (lo + hi + 1) >>> 1;\n if (lineOffsets[mid] <= offset) lo = mid;\n else hi = mid - 1;\n }\n return { line: lo + 1, column: offset - lineOffsets[lo] + 1 };\n}\n\nfunction getLoc(\n node: any,\n lineOffsets: number[],\n): { line: number; column: number; endLine?: number; endColumn?: number } {\n const startOffset = typeof node?.start === \"number\" ? node.start : undefined;\n const endOffset = typeof node?.end === \"number\" ? node.end : undefined;\n if (startOffset === undefined) {\n return { line: 1, column: 1 };\n }\n const start = offsetToLineCol(startOffset, lineOffsets);\n const end = endOffset !== undefined\n ? offsetToLineCol(endOffset, lineOffsets)\n : undefined;\n return {\n line: start.line,\n column: start.column,\n endLine: end?.line,\n endColumn: end?.column,\n };\n}\n\nfunction walkAST(node: any, handlers: Record<string, any>) {\n if (!node || typeof node !== \"object\") return;\n const enter = handlers[node.type];\n if (enter) enter(node);\n for (const key in node) {\n const v = node[key];\n if (Array.isArray(v)) {\n for (const c of v) walkAST(c, handlers);\n } else if (v && typeof v === \"object\") {\n walkAST(v, handlers);\n }\n }\n const exit = handlers[`${node.type}:exit`];\n if (exit) exit(node);\n}\n\nexport async function lintFile(\n filePath: string,\n source: string,\n config: EngineConfig,\n): Promise<Diagnostic[]> {\n const lang = filePath.endsWith(\".tsx\")\n ? \"tsx\"\n : filePath.endsWith(\".ts\")\n ? \"ts\"\n : filePath.endsWith(\".jsx\")\n ? \"jsx\"\n : \"js\";\n\n const parsed = parseSync(filePath, source, {\n lang,\n sourceType: \"module\",\n });\n\n const lineOffsets = buildLineOffsets(source);\n\n if (parsed.errors?.length) {\n return parsed.errors.map((e: any) => {\n const offset = typeof e.labels?.[0]?.start === \"number\"\n ? e.labels[0].start\n : undefined;\n const loc = offset !== undefined\n ? offsetToLineCol(offset, lineOffsets)\n : { line: 1, column: 1 };\n return {\n file: filePath,\n rule: \"parse-error\",\n severity: \"error\" as const,\n message: e.message ?? \"parse error\",\n line: loc.line,\n column: loc.column,\n };\n });\n }\n\n // Bail early on non-React files\n const imports = parsed.module?.staticImports ?? [];\n const hasReact = imports.some((i: any) =>\n (i.moduleRequest?.value ?? i.source?.value) === \"react\"\n );\n if (!hasReact) return [];\n\n const out: Diagnostic[] = [];\n\n for (const [ruleId, ruleCfg] of Object.entries(config.rules)) {\n if (ruleCfg.severity === \"off\") continue;\n if (!config.typeAware && TYPE_AWARE_RULES.has(ruleId)) continue;\n\n const rule = (ALL_RULES as any)[ruleNamespace(ruleId)];\n if (!rule) continue;\n\n const localDiags: Diagnostic[] = [];\n const context = {\n options: ruleCfg.options ? [ruleCfg.options] : [],\n filename: filePath,\n cwd: config.cwd,\n report(d: { message: string; node: any; severity?: \"warn\" | \"error\" }) {\n const loc = getLoc(d.node, lineOffsets);\n const cfgSev = ruleCfg.severity as \"warn\" | \"error\";\n // Rule-emitted severity only escalates (warn → error); never downgrades.\n const severity = d.severity === \"error\" ? \"error\" : cfgSev;\n localDiags.push({\n file: filePath,\n rule: ruleId,\n severity,\n message: d.message,\n ...loc,\n });\n },\n };\n\n const handlers = rule.create(context);\n walkAST(parsed.program, handlers);\n out.push(...localDiags);\n }\n\n return out;\n}\n\nexport type ReadTextFile = (path: string) => Promise<string>;\n\nexport async function lintFiles(\n filePaths: string[],\n config: EngineConfig,\n readTextFile: ReadTextFile,\n): Promise<Diagnostic[]> {\n const results = await Promise.all(\n filePaths.map(async (p) => {\n const src = await readTextFile(p);\n return lintFile(p, src, config);\n }),\n );\n return results.flat();\n}\n"],"mappings":";;;AA2BA,MAAM,mBAAmB,IAAI,IAAI,CAAC,iCAAiC,CAAC;AAEpE,SAAS,cAAc,IAAoB;AACzC,QAAO,GAAG,QAAQ,mBAAmB,GAAG;;AAG1C,SAAS,iBAAiB,QAA0B;CAClD,MAAM,UAAU,CAAC,EAAE;AACnB,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IACjC,KAAI,OAAO,WAAW,EAAE,K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K,OAAO,QAAQ;AACrC,UAAQ,OAAO,SAAS,SAAS;AACjC,MAAI,KAAK,GAAG,WAAW;;AAGzB,QAAO;;AAKT,eAAsB,UACpB,WACA,QACA,cACuB;AAOvB,SAAO,MANe,QAAQ,IAC5B,UAAU,IAAI,OAAO,MAAM;AAEzB,SAAO,SAAS,GAAG,MADD,aAAa,EAAE,EACT,OAAO;GAC/B,CACH,EACc,MAAM"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry-iRG6wil9.mjs","names":[],"sources":["../src/ast-helpers.ts","../src/scoring/effect-score.ts","../src/scoring/thresholds.ts","../src/rules/no-fat-effects.ts","../src/scoring/state-score.ts","../src/rules/state-scatter.ts","../src/scoring/coupling-score.ts","../src/rules/hook-coupling.ts","../src/ts-program.ts","../src/rules/custom-hook-depth.ts","../src/rules/registry.ts"],"sourcesContent":["type Node = { type: string; [k: string]: unknown };\n\nconst HOOK_RE = /^use[A-Z]/;\n\nexport function getHookName(node: Node): string | null {\n if (node.type !== \"CallExpression\") return null;\n const callee = (node as any).callee as Node;\n if (callee?.type !== \"Identifier\") return null;\n const name = (callee as any).name as string;\n return HOOK_RE.test(name) ? name : null;\n}\n\nexport function isHookCall(node: Node, expected: string): boolean {\n return getHookName(node) === expected;\n}\n\nexport function isReactComponent(node: Node): boolean {\n if (node.type === \"FunctionDeclaration\") {\n const name = (node as any).id?.name as string | undefined;\n if (!name || !/^[A-Z]/.test(name)) return false;\n return findReturnsJSX(node);\n }\n if (node.type === \"VariableDeclaration\") {\n const decl = (node as any).declarations?.[0];\n const name = decl?.id?.name as string | undefined;\n const init = decl?.init as Node | undefined;\n if (!name || !/^[A-Z]/.test(name) || !init) return false;\n if (\n init.type === \"ArrowFunctionExpression\" ||\n init.type === \"FunctionExpression\"\n ) {\n return findReturnsJSX(init);\n }\n }\n return false;\n}\n\nexport function findReturnsJSX(node: Node): boolean {\n let found = false;\n walk(node, (n) => {\n if (\n n.type === \"JSXElement\" ||\n n.type === \"JSXFragment\" ||\n n.type === \"JSXSelfClosingElement\"\n ) {\n found = true;\n return false;\n }\n return true;\n });\n return found;\n}\n\nexport function walk(\n node: Node,\n visit: (n: Node) => boolean | void,\n seen: WeakSet<Node> = new WeakSet(),\n): void {\n if (seen.has(node)) return;\n seen.add(node);\n const cont = visit(node);\n if (cont === false) return;\n for (const key in node) {\n if (key === \"parent\") continue;\n const val = (node as any)[key];\n if (Array.isArray(val)) {\n for (const child of val) {\n if (child && typeof child === \"object\" && \"type\" in child) {\n walk(child as Node, visit, seen);\n }\n }\n } else if (val && typeof val === \"object\" && \"type\" in val) {\n walk(val as Node, visit, seen);\n }\n }\n}\n","import { walk } from \"../ast-helpers.ts\";\n\ntype Node = { type: string; [k: string]: unknown };\n\nexport interface EffectScore {\n deps: number;\n branches: number;\n setStateCount: number;\n nestedEffects: number;\n hasCleanup: boolean;\n hasSubscriptionLike: boolean;\n total: number;\n}\n\nconst SET_STATE_RE = /^set[A-Z]/;\nconst BRANCH_TYPES = new Set([\n \"IfStatement\",\n \"ConditionalExpression\",\n \"SwitchCase\",\n \"LogicalExpression\",\n]);\n\nexport function scoreEffect(node: Node): EffectScore {\n const args = (node as any).arguments as Node[];\n const fn = args?.[0] as Node | undefined;\n const depsArr = args?.[1] as any;\n\n const deps = Array.isArray(depsArr?.elements) ? depsArr.elements.length : 0;\n let branches = 0;\n let setStateCount = 0;\n let nestedEffects = 0;\n let hasCleanup = false;\n let hasSubscriptionLike = false;\n\n if (fn) {\n const body = (fn as any).body as Node;\n if (body?.type === \"BlockStatement\") {\n for (const stmt of (body as any).body as Node[]) {\n if (stmt.type === \"ReturnStatement\") {\n const arg = (stmt as any).argument as Node | undefined;\n if (\n arg &&\n (arg.type === \"ArrowFunctionExpression\" ||\n arg.type === \"FunctionExpression\")\n ) hasCleanup = true;\n }\n }\n }\n\n walk(fn, (n) => {\n if (BRANCH_TYPES.has(n.type)) branches++;\n if (n.type === \"CallExpression\") {\n const callee = (n as any).callee as Node;\n if (callee?.type === \"Identifier\") {\n const name = (callee as any).name as string;\n if (SET_STATE_RE.test(name)) setStateCount++;\n if (name === \"useEffect\" && n !== node) nestedEffects++;\n if (\n name === \"addEventListener\" ||\n name === \"subscribe\" ||\n name === \"setInterval\" ||\n name === \"setTimeout\"\n ) hasSubscriptionLike = true;\n }\n if (callee?.type === \"MemberExpression\") {\n const prop = (callee as any).property as Node;\n if (prop?.type === \"Identifier\") {\n const name = (prop as any).name as string;\n if (\n name === \"addEventListener\" ||\n name === \"subscribe\" ||\n name === \"on\"\n ) hasSubscriptionLike = true;\n }\n }\n }\n return true;\n });\n }\n\n const cleanupPenalty = hasSubscriptionLike && !hasCleanup ? 3 : 0;\n const total = deps + branches * 2 + setStateCount * 1.5 +\n nestedEffects * 5 + cleanupPenalty;\n\n return {\n deps,\n branches,\n setStateCount,\n nestedEffects,\n hasCleanup,\n hasSubscriptionLike,\n total,\n };\n}\n","export interface Thresholds {\n fatEffect: { warn: number; error: number };\n stateScatter: { warn: number; error: number };\n hookCoupling: { warn: number; error: number };\n customHookDepth: { warn: number; error: number };\n}\n\nexport const DEFAULT_THRESHOLDS: Thresholds = {\n fatEffect: { warn: 10, error: 20 },\n stateScatter: { warn: 5, error: 8 },\n hookCoupling: { warn: 3, error: 6 },\n customHookDepth: { warn: 3, error: 5 },\n};\n","import { scoreEffect } from \"../scoring/effect-score.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { isHookCall } from \"../ast-helpers.ts\";\n\ninterface Options {\n threshold?: number;\n errorThreshold?: number;\n}\n\nexport interface RuleContext {\n options: unknown[];\n filename?: string;\n cwd?: string;\n report: (d: {\n message: string;\n node: unknown;\n severity?: \"warn\" | \"error\";\n }) => void;\n}\n\nexport const noFatEffects = {\n meta: {\n type: \"suggestion\" as const,\n docs: { description: \"Flag dense useEffect blocks\" },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const threshold = opts.threshold ?? DEFAULT_THRESHOLDS.fatEffect.warn;\n const errorThreshold = opts.errorThreshold ??\n DEFAULT_THRESHOLDS.fatEffect.error;\n return {\n CallExpression(node: any) {\n if (!isHookCall(node, \"useEffect\")) return;\n const score = scoreEffect(node);\n if (score.total >= threshold) {\n const breakdown = `deps=${score.deps} branches=${score.branches} ` +\n `setStates=${score.setStateCount} nested=${score.nestedEffects}` +\n (score.hasSubscriptionLike && !score.hasCleanup\n ? \" missing-cleanup\"\n : \"\");\n const severity = score.total >= errorThreshold ? \"error\" : \"warn\";\n context.report({\n message: `useEffect entropy ${\n score.total.toFixed(1)\n } ≥ ${threshold} (${breakdown})`,\n node,\n severity,\n });\n }\n },\n };\n },\n};\n","import { isHookCall, walk } from \"../ast-helpers.ts\";\n\ntype Node = { type: string; [k: string]: unknown };\n\nexport interface StateScore {\n useStateCount: number;\n correlatedSetters: number;\n total: number;\n}\n\nexport function scoreComponentState(componentNode: Node): StateScore {\n const setterNames = new Set<string>();\n let useStateCount = 0;\n\n // First pass: collect useState setters\n walk(componentNode, (n) => {\n if (!n) return true;\n if (n.type === \"VariableDeclarator\") {\n const init = (n as any).init as Node | undefined;\n const id = (n as any).id as Node | undefined;\n if (\n init?.type === \"CallExpression\" &&\n isHookCall(init, \"useState\") &&\n id?.type === \"ArrayPattern\"\n ) {\n useStateCount++;\n const els = (id as any).elements as Node[];\n const setter = els?.[1];\n if (setter?.type === \"Identifier\") {\n setterNames.add((setter as any).name as string);\n }\n }\n }\n return true;\n });\n\n // Second pass: count correlated setters\n let correlatedSetters = 0;\n walk(componentNode, (n) => {\n if (!n) return true;\n if (\n n.type === \"FunctionDeclaration\" ||\n n.type === \"FunctionExpression\" ||\n n.type === \"ArrowFunctionExpression\"\n ) {\n const calledSetters = new Set<string>();\n walk(n, (m) => {\n if (!m) return true;\n if (m.type === \"CallExpression\") {\n const callee = (m as any).callee as Node;\n if (callee?.type === \"Identifier\") {\n const name = (callee as any).name as string;\n if (setterNames.has(name)) calledSetters.add(name);\n }\n }\n return true;\n });\n if (calledSetters.size >= 2) correlatedSetters += calledSetters.size;\n }\n return true;\n });\n\n const total = useStateCount + correlatedSetters * 0.5;\n return { useStateCount, correlatedSetters, total };\n}\n","import { scoreComponentState } from \"../scoring/state-score.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { isReactComponent } from \"../ast-helpers.ts\";\nimport type { RuleContext } from \"./no-fat-effects.ts\";\n\ninterface Options {\n threshold?: number;\n errorThreshold?: number;\n}\n\nexport const stateScatter = {\n meta: {\n type: \"suggestion\" as const,\n docs: { description: \"Flag components with too many useState calls\" },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const threshold = opts.threshold ?? DEFAULT_THRESHOLDS.stateScatter.warn;\n const errorThreshold = opts.errorThreshold ??\n DEFAULT_THRESHOLDS.stateScatter.error;\n function check(node: any) {\n if (!isReactComponent(node)) return;\n const s = scoreComponentState(node);\n if (s.total >= threshold) {\n const severity = s.total >= errorThreshold ? \"error\" : \"warn\";\n context.report({\n message:\n `state scatter ${s.total} ≥ ${threshold} (useStates=${s.useStateCount}, correlated setters=${s.correlatedSetters}). Consider useReducer.`,\n node,\n severity,\n });\n }\n }\n return {\n FunctionDeclaration: check,\n VariableDeclaration: check,\n };\n },\n};\n","import { isHookCall, walk } from \"../ast-helpers.ts\";\n\ntype Node = { type: string; [k: string]: unknown };\n\nexport interface CouplingScore {\n total: number;\n readWriteSame: Array<{ state: string; effect: Node }>;\n}\n\nexport function scoreCoupling(componentNode: Node): CouplingScore {\n const stateBySetter = new Map<string, string>();\n walk(componentNode, (n) => {\n if (n.type === \"VariableDeclarator\") {\n const init = (n as any).init as Node | undefined;\n const id = (n as any).id as Node | undefined;\n if (\n init?.type === \"CallExpression\" &&\n isHookCall(init, \"useState\") &&\n id?.type === \"ArrayPattern\"\n ) {\n const els = (id as any).elements as Node[];\n const stateId = els?.[0];\n const setterId = els?.[1];\n if (stateId?.type === \"Identifier\" && setterId?.type === \"Identifier\") {\n stateBySetter.set(\n (setterId as any).name as string,\n (stateId as any).name as string,\n );\n }\n }\n }\n return true;\n });\n\n const readWriteSame: Array<{ state: string; effect: Node }> = [];\n let total = 0;\n\n walk(componentNode, (n) => {\n if (n.type === \"CallExpression\" && isHookCall(n, \"useEffect\")) {\n const effectFn = ((n as any).arguments as Node[])?.[0];\n if (!effectFn) return true;\n\n const stateRefs = new Set<string>();\n const stateWrites = new Set<string>();\n const stateNames = new Set(stateBySetter.values());\n\n walk(effectFn, (m) => {\n if (m.type === \"Identifier\") {\n const name = (m as any).name as string;\n if (stateNames.has(name)) stateRefs.add(name);\n }\n if (m.type === \"CallExpression\") {\n const callee = (m as any).callee as Node;\n if (callee?.type === \"Identifier\") {\n const setter = (callee as any).name as string;\n const stateName = stateBySetter.get(setter);\n if (stateName) stateWrites.add(stateName);\n }\n }\n return true;\n });\n\n for (const written of stateWrites) {\n if (stateRefs.has(written)) {\n readWriteSame.push({ state: written, effect: n });\n total += 3;\n }\n }\n }\n return true;\n });\n\n return { total, readWriteSame };\n}\n","import { scoreCoupling } from \"../scoring/coupling-score.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { isReactComponent } from \"../ast-helpers.ts\";\nimport type { RuleContext } from \"./no-fat-effects.ts\";\n\ninterface Options {\n threshold?: number;\n errorThreshold?: number;\n}\n\nexport const hookCoupling = {\n meta: {\n type: \"problem\" as const,\n docs: {\n description: \"Flag effects that read state they also write (loop bait)\",\n },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const threshold = opts.threshold ?? DEFAULT_THRESHOLDS.hookCoupling.warn;\n const errorThreshold = opts.errorThreshold ??\n DEFAULT_THRESHOLDS.hookCoupling.error;\n function check(node: any) {\n if (!isReactComponent(node)) return;\n const s = scoreCoupling(node);\n if (s.total < threshold) return;\n const severity = s.total >= errorThreshold ? \"error\" : \"warn\";\n for (const v of s.readWriteSame) {\n context.report({\n message:\n `useEffect reads + writes same state '${v.state}' (loop risk)`,\n node: v.effect,\n severity,\n });\n }\n }\n return { FunctionDeclaration: check, VariableDeclaration: check };\n },\n};\n","import ts from \"typescript\";\n\nexport class TsProgramCache {\n private program: ts.Program | null = null;\n private rootDir: string;\n\n constructor(rootDir: string) {\n this.rootDir = rootDir;\n }\n\n private getProgram(): ts.Program {\n if (this.program) return this.program;\n const configPath = ts.findConfigFile(\n this.rootDir,\n ts.sys.fileExists,\n \"tsconfig.json\",\n );\n let compilerOptions: ts.CompilerOptions = {\n target: ts.ScriptTarget.ESNext,\n module: ts.ModuleKind.ESNext,\n jsx: ts.JsxEmit.Preserve,\n moduleResolution: ts.ModuleResolutionKind.Bundler,\n allowJs: true,\n noEmit: true,\n skipLibCheck: true,\n strict: false,\n };\n let fileNames: string[] = [];\n if (configPath) {\n const cfg = ts.readConfigFile(configPath, ts.sys.readFile);\n const configDir = configPath.slice(0, configPath.lastIndexOf(\"/\"));\n const parsed = ts.parseJsonConfigFileContent(\n cfg.config,\n ts.sys,\n configDir,\n );\n compilerOptions = { ...compilerOptions, ...parsed.options };\n fileNames = parsed.fileNames;\n }\n this.program = ts.createProgram(fileNames, compilerOptions);\n return this.program;\n }\n\n resolveIdentifierDeclaration(\n filePath: string,\n identifier: string,\n ): ts.Declaration | null {\n const program = this.getProgram();\n const checker = program.getTypeChecker();\n const absolute = filePath.startsWith(\"/\")\n ? filePath\n : `${this.rootDir.replace(/\\/$/, \"\")}/${filePath}`;\n const sourceFile = program.getSourceFile(absolute) ??\n program.getSourceFile(filePath);\n if (!sourceFile) return null;\n\n let target: ts.Node | null = null;\n function find(node: ts.Node) {\n if (target) return;\n if (ts.isIdentifier(node) && node.text === identifier) {\n target = node;\n return;\n }\n ts.forEachChild(node, find);\n }\n find(sourceFile);\n if (!target) return null;\n\n const symbol = checker.getSymbolAtLocation(target);\n if (!symbol) return null;\n const aliased = symbol.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(symbol)\n : symbol;\n return aliased.declarations?.[0] ?? null;\n }\n\n countTransitiveHookCalls(\n decl: ts.Declaration,\n depth = 0,\n seen = new Set<ts.Declaration>(),\n ): number {\n if (depth > 10 || seen.has(decl)) return depth;\n seen.add(decl);\n const program = this.getProgram();\n const checker = program.getTypeChecker();\n let maxDepth = depth;\n\n const visit = (node: ts.Node) => {\n if (\n ts.isCallExpression(node) &&\n ts.isIdentifier(node.expression) &&\n /^use[A-Z]/.test(node.expression.text)\n ) {\n const sym = checker.getSymbolAtLocation(node.expression);\n if (sym) {\n const aliased = sym.flags & ts.SymbolFlags.Alias\n ? checker.getAliasedSymbol(sym)\n : sym;\n const innerDecl = aliased.declarations?.[0];\n if (innerDecl) {\n const sf = innerDecl.getSourceFile();\n if (\n sf.fileName.includes(\"node_modules/@types/react\") ||\n sf.fileName.includes(\"node_modules/react/\")\n ) {\n maxDepth = Math.max(maxDepth, depth + 1);\n } else {\n const childDepth = this.countTransitiveHookCalls(\n innerDecl,\n depth + 1,\n seen,\n );\n maxDepth = Math.max(maxDepth, childDepth);\n }\n }\n }\n }\n ts.forEachChild(node, visit);\n };\n\n visit(decl);\n return maxDepth;\n }\n}\n","import { TsProgramCache } from \"../ts-program.ts\";\nimport { DEFAULT_THRESHOLDS } from \"../scoring/thresholds.ts\";\nimport { getHookName } from \"../ast-helpers.ts\";\nimport type { RuleContext } from \"./no-fat-effects.ts\";\n\ninterface Options {\n maxDepth?: number;\n errorMaxDepth?: number;\n}\n\nconst REACT_HOOKS = new Set([\n \"useState\",\n \"useEffect\",\n \"useLayoutEffect\",\n \"useMemo\",\n \"useCallback\",\n \"useReducer\",\n \"useContext\",\n \"useRef\",\n \"useImperativeHandle\",\n \"useDebugValue\",\n \"useId\",\n \"useTransition\",\n \"useDeferredValue\",\n \"useSyncExternalStore\",\n \"useInsertionEffect\",\n]);\n\nlet sharedCache: TsProgramCache | null = null;\n\nexport const customHookDepth = {\n meta: {\n type: \"suggestion\" as const,\n docs: {\n description:\n \"Flag custom hooks whose transitive nesting exceeds maxDepth (type-aware).\",\n },\n },\n create(context: RuleContext) {\n const opts = (context.options[0] as Options | undefined) ?? {};\n const maxDepth = opts.maxDepth ?? DEFAULT_THRESHOLDS.customHookDepth.warn;\n const errorMaxDepth = opts.errorMaxDepth ??\n DEFAULT_THRESHOLDS.customHookDepth.error;\n const g = globalThis as {\n Deno?: { cwd(): string };\n process?: { cwd(): string };\n };\n const cwd = context.cwd ?? g.process?.cwd() ?? g.Deno?.cwd() ?? \".\";\n sharedCache ??= new TsProgramCache(cwd);\n const cache = sharedCache;\n const filename = context.filename;\n\n return {\n CallExpression(node: any) {\n const name = getHookName(node);\n if (!name || REACT_HOOKS.has(name)) return;\n if (!filename) return;\n const decl = cache.resolveIdentifierDeclaration(filename, name);\n if (!decl) return;\n const depth = cache.countTransitiveHookCalls(decl);\n if (depth >= maxDepth) {\n const severity = depth >= errorMaxDepth ? \"error\" : \"warn\";\n context.report({\n message:\n `custom hook '${name}' transitive depth ${depth} ≥ ${maxDepth}`,\n node,\n severity,\n });\n }\n },\n };\n },\n};\n","import type { Rule } from \"@oxlint/plugins\";\nimport { noFatEffects } from \"./no-fat-effects.ts\";\nimport { stateScatter } from \"./state-scatter.ts\";\nimport { hookCoupling } from \"./hook-coupling.ts\";\nimport { customHookDepth } from \"./custom-hook-depth.ts\";\n\n// Rules use our internal ESLint-compatible RuleContext shape; eslintCompatPlugin\n// adapts them to oxlint's stricter Rule contract at runtime.\nexport const ALL_RULES: Record<string, Rule> = {\n \"no-fat-effects\": noFatEffects as unknown as Rule,\n \"state-scatter\": stateScatter as unknown as Rule,\n \"hook-coupling\": hookCoupling as unknown as Rule,\n \"custom-hook-depth\": customHookDepth as unknown as Rule,\n};\n\nexport type RuleId =\n | \"no-fat-effects\"\n | \"state-scatter\"\n | \"hook-coupling\"\n | \"custom-hook-depth\";\n"],"mappings":";;AAEA,MAAM,UAAU;AAEhB,SAAgB,YAAY,MAA2B;AACrD,KAAI,KAAK,SAAS,iBAAkB,QAAO;CAC3C,MAAM,SAAU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