@webpieces/ai-hook-rules 0.4.843 → 0.4.845
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 +3 -1
- package/package.json +10 -5
- package/src/adapters/hook-app-fixtures.js +5 -2
- package/src/adapters/hook-app-fixtures.js.map +1 -1
- package/src/configs/rule-configs.d.ts +23 -0
- package/src/configs/rule-configs.js +38 -0
- package/src/configs/rule-configs.js.map +1 -0
- package/src/core/load-rules.d.ts +1 -1
- package/src/core/load-rules.js.map +1 -1
- package/src/core/rules/catch-error-pattern.d.ts +3 -3
- package/src/core/rules/catch-error-pattern.js +1 -1
- package/src/core/rules/catch-error-pattern.js.map +1 -1
- package/src/core/rules/max-file-lines.d.ts +3 -3
- package/src/core/rules/max-file-lines.js.map +1 -1
- package/src/core/rules/no-any-unknown.d.ts +3 -3
- package/src/core/rules/no-any-unknown.js +1 -2
- package/src/core/rules/no-any-unknown.js.map +1 -1
- package/src/core/rules/no-custom-css.d.ts +3 -3
- package/src/core/rules/no-custom-css.js +1 -1
- package/src/core/rules/no-custom-css.js.map +1 -1
- package/src/core/rules/no-destructure.d.ts +3 -3
- package/src/core/rules/no-destructure.js +1 -1
- package/src/core/rules/no-destructure.js.map +1 -1
- package/src/core/rules/no-implicit-any.d.ts +3 -3
- package/src/core/rules/no-implicit-any.js +1 -2
- package/src/core/rules/no-implicit-any.js.map +1 -1
- package/src/core/rules/no-js-files.d.ts +1 -1
- package/src/core/rules/no-js-files.js.map +1 -1
- package/src/core/rules/no-process-exit-outside-main.d.ts +3 -3
- package/src/core/rules/no-process-exit-outside-main.js +1 -1
- package/src/core/rules/no-process-exit-outside-main.js.map +1 -1
- package/src/core/rules/no-symbol-di-tokens.d.ts +3 -3
- package/src/core/rules/no-symbol-di-tokens.js +1 -1
- package/src/core/rules/no-symbol-di-tokens.js.map +1 -1
- package/src/core/rules/no-unmanaged-exceptions.d.ts +3 -3
- package/src/core/rules/no-unmanaged-exceptions.js +1 -1
- package/src/core/rules/no-unmanaged-exceptions.js.map +1 -1
- package/src/core/rules/require-return-type.d.ts +3 -3
- package/src/core/rules/require-return-type.js +1 -2
- package/src/core/rules/require-return-type.js.map +1 -1
- package/src/core/rules/throw-cause-required.d.ts +1 -1
- package/src/core/rules/throw-cause-required.js +1 -1
- package/src/core/rules/throw-cause-required.js.map +1 -1
- package/src/core/rules/validate-ts-in-src.d.ts +1 -1
- package/src/core/rules/validate-ts-in-src.js.map +1 -1
- package/src/core/source-contribution-config.d.ts +9 -0
- package/src/core/source-contribution-config.js +14 -0
- package/src/core/source-contribution-config.js.map +1 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +9 -2
- package/src/index.js.map +1 -1
- package/src/rule-pack.d.ts +2 -0
- package/src/rule-pack.js +27 -0
- package/src/rule-pack.js.map +1 -0
- package/src/rule-settings.d.ts +5 -0
- package/src/rule-settings.js +40 -0
- package/src/rule-settings.js.map +1 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-destructure.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-destructure.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"no-destructure.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-destructure.ts"],"names":[],"mappings":";;;AACA,0DAAiE;AAGjE,0DAAyD;AACzD,0DAAuD;AACvD,0DAAiE;AAEjE,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAExD,MAAa,iBAAkB,SAAQ,2BAAsC;IACzE,YAAY,MAAgC,IAAI,KAAK,CAAC,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAE3F,WAAW,GAAG,8GAA8G,CAAC;IACpH,KAAK,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAChC,cAAc,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC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luded, Option } from \"@webpieces/rules-config\";\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\n\nconst VARIABLE_DESTRUCTURE = /\\b(?:const|let|var)\\s*\\{/;\n\nexport class NoDestructureRule extends EditRuleBase<SourceContributionConfig> {\n constructor(config: SourceContributionConfig) { super(config, 'no-destructure', 'no-destructure'); }\n\n readonly description = 'Disallow destructuring patterns. Assign the whole result and pass it around or access properties explicitly.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n override readonly defaultOptions = { allowTopLevel: true, allowedPaths: [] };\n get fixHint(): FixHint {\n return new FixHint(\n 'Destructuring pattern on a call result.',\n 'Pick one:',\n [\n new Option('Assign the whole result instead: const obj = methodCall(); then pass obj around or use obj.x.', true),\n new Option('If this whole tree is destructuring by construction (a React/React Native component or hook tree), add a glob to no-destructure.allowedPaths in webpieces.config.json'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable no-destructure -- <reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const allowedPaths = this.config.allowedPaths ?? [];\n if (isPathExcluded(ctx.relativePath, allowedPaths)) return [];\n\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n for (let i = 0; i < ctx.strippedLines.length; i += 1) {\n const stripped = ctx.strippedLines[i];\n if (!VARIABLE_DESTRUCTURE.test(stripped)) continue;\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"no-destructure\")) continue;\n violations.push(new V(lineNum, ctx.lines[i].trim()));\n }\n return violations;\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SourceContributionConfig } from "../source-contribution-config";
|
|
2
2
|
import type { EditContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { EditRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
5
|
-
export declare class NoImplicitAnyRule extends EditRuleBase<
|
|
6
|
-
constructor(config:
|
|
5
|
+
export declare class NoImplicitAnyRule extends EditRuleBase<SourceContributionConfig> {
|
|
6
|
+
constructor(config: SourceContributionConfig);
|
|
7
7
|
readonly description = "Disallow function parameters without explicit type annotations (implicit-any).";
|
|
8
8
|
readonly files: string[];
|
|
9
9
|
get fixHint(): FixHint;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NoImplicitAnyRule = void 0;
|
|
4
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
4
|
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
6
5
|
const hook_runtime_2 = require("@webpieces/hook-runtime");
|
|
7
6
|
const hook_runtime_3 = require("@webpieces/hook-runtime");
|
|
@@ -57,7 +56,7 @@ class NoImplicitAnyRule extends hook_runtime_2.EditRuleBase {
|
|
|
57
56
|
for (let i = 0; i < ctx.strippedLines.length; i += 1) {
|
|
58
57
|
const stripped = ctx.strippedLines[i];
|
|
59
58
|
const lineNum = i + 1;
|
|
60
|
-
if (disableAllowed && ctx.isLineDisabled(lineNum,
|
|
59
|
+
if (disableAllowed && ctx.isLineDisabled(lineNum, "no-implicit-any"))
|
|
61
60
|
continue;
|
|
62
61
|
const offender = findOffender(stripped);
|
|
63
62
|
if (!offender)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-implicit-any.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-implicit-any.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"no-implicit-any.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-implicit-any.ts"],"names":[],"mappings":";;;AAIA,0DAAyD;AACzD,0DAAuD;AACvD,0DAA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;gBAAE,SAAS;YAC/E,MAAM,QAAQ,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ;gBAAE,SAAS;YACxB,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CACjB,OAAO,EACP,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EACnB,cAAc,QAAQ,uEAAuE,CAChG,CAAC,CAAC;QACP,CAAC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AA/BD,8CA+BC","sourcesContent":["import { SourceContributionConfig } from \"../source-contribution-config\";\n\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\n\nconst ARROW_PARAMS_RE = /\\(([^()]*)\\)\\s*=>/g;\nconst FN_DECL_PARAMS_RE = /\\bfunction\\s*[\\w$]*\\s*\\(([^()]*)\\)/g;\n\nfunction firstUntypedParam(paramsStr: string): string | null {\n if (paramsStr.includes('{') || paramsStr.includes('[')) return null;\n const parts = paramsStr.split(',').map((p: string) => p.trim()).filter((p: string) => p.length > 0);\n for (const part of parts) {\n if (part.startsWith('...')) continue;\n if (part.includes(':')) continue;\n if (part.includes('=')) continue;\n if (part === 'this') continue;\n if (/^[a-zA-Z_$][\\w$]*$/.test(part)) return part;\n }\n return null;\n}\n\nfunction findOffender(line: string): string | null {\n ARROW_PARAMS_RE.lastIndex = 0;\n let m: RegExpExecArray | null = ARROW_PARAMS_RE.exec(line);\n while (m !== null) {\n const bad = firstUntypedParam(m[1]);\n if (bad) return bad;\n m = ARROW_PARAMS_RE.exec(line);\n }\n FN_DECL_PARAMS_RE.lastIndex = 0;\n m = FN_DECL_PARAMS_RE.exec(line);\n while (m !== null) {\n const bad = firstUntypedParam(m[1]);\n if (bad) return bad;\n m = FN_DECL_PARAMS_RE.exec(line);\n }\n return null;\n}\n\nexport class NoImplicitAnyRule extends EditRuleBase<SourceContributionConfig> {\n constructor(config: SourceContributionConfig) { super(config, 'no-implicit-any', 'no-implicit-any'); }\n\n readonly description = 'Disallow function parameters without explicit type annotations (implicit-any).';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n get fixHint(): FixHint {\n return new FixHint(\n 'A parameter has no type annotation (implicit any).',\n 'Add explicit types: (x: string) => ... or function foo(x: number).',\n [],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable no-implicit-any -- <one-line reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n for (let i = 0; i < ctx.strippedLines.length; i += 1) {\n const stripped = ctx.strippedLines[i];\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"no-implicit-any\")) continue;\n const offender = findOffender(stripped);\n if (!offender) continue;\n violations.push(new V(\n lineNum,\n ctx.lines[i].trim(),\n `Parameter \"${offender}\" has no type annotation. Add an explicit type to avoid implicit-any.`,\n ));\n }\n return violations;\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NoJsFilesConfig } from
|
|
1
|
+
import { NoJsFilesConfig } from "../../configs/rule-configs";
|
|
2
2
|
import type { FileContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { FileRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-js-files.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-js-files.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"no-js-files.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-js-files.ts"],"names":[],"mappings":";;;AAAA,0DAAiE;AAIjE,0DAAyD;AACzD,0DAAuD;AACvD,0DAAkD;AAElD,MAAa,aAAc,SAAQ,2BAA6B;IAC5D,YAAY,MAAuB,IAAI,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IAE5E,WAAW,GAAG,4DAA4D,CAAC;IAClE,KAAK,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAChC,cAAc,GAAG,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC;IAC/C,OAAO,GAAG,IAAI,sBAAO,CAC1B,8DAA8D,EAC9D,WAAW,EACX;QACI,IAAI,qBAAM,CAAC,+CAA+C,EAAE,IAAI,CAAC;QACjE,IAAI,qBAAM,CAAC,0GAA0G,CAAC;KACzH,CACJ,CAAC;IAEF,KAAK,CAAC,GAAgB;QAClB,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO;YAAE,OAAO,EAAE,CAAC;QAEpC,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC;QAEpD,IAAI,IAAA,6BAAc,EAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC;YAAE,OAAO,EAAE,CAAC;QAE9D,OAAO,CAAC,IAAI,wBAAC,CAAC,CAAC,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC;IACxC,CAAC;CACJ;AAxBD,sCAwBC","sourcesContent":["import { isPathExcluded, Option } from \"@webpieces/rules-config\";\nimport { NoJsFilesConfig } from \"../../configs/rule-configs\";\n\nimport type { FileContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { FileRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint } from '@webpieces/hook-runtime';\n\nexport class NoJsFilesRule extends FileRuleBase<NoJsFilesConfig> {\n constructor(config: NoJsFilesConfig) { super(config, 'no-js-files', 'no-js-files'); }\n\n readonly description = 'Disallow writing new .js/.jsx files. Use .ts/.tsx instead.';\n override readonly files = ['**/*.js', '**/*.jsx'];\n override readonly defaultOptions = { allowedPaths: [] };\n readonly fixHint = new FixHint(\n 'Writing .js/.jsx files is not allowed. Use .ts/.tsx instead.',\n 'Pick one:',\n [\n new Option('Write a .ts or .tsx file instead of .js/.jsx.', true),\n new Option('If this path must be .js (generated/legacy), add it to no-js-files.allowedPaths in webpieces.config.json'),\n ],\n );\n\n check(ctx: FileContext): readonly Violation[] {\n if (ctx.tool !== 'Write') return [];\n\n const allowedPaths = this.config.allowedPaths ?? [];\n\n if (isPathExcluded(ctx.relativePath, allowedPaths)) return [];\n\n return [new V(1, ctx.relativePath)];\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SourceContributionConfig } from "../source-contribution-config";
|
|
2
2
|
import type { EditContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { EditRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
5
|
-
export declare class NoProcessExitOutsideMainRule extends EditRuleBase<
|
|
6
|
-
constructor(config:
|
|
5
|
+
export declare class NoProcessExitOutsideMainRule extends EditRuleBase<SourceContributionConfig> {
|
|
6
|
+
constructor(config: SourceContributionConfig);
|
|
7
7
|
readonly description = "Disallow process.exit() outside a main()/runMain wrapper (and importing another module's main). A deep exit crashes a reused server/command too early; throw a semantic error and let main pick the exit code.";
|
|
8
8
|
readonly files: string[];
|
|
9
9
|
readonly defaultOptions: {};
|
|
@@ -48,7 +48,7 @@ class NoProcessExitOutsideMainRule extends hook_runtime_2.EditRuleBase {
|
|
|
48
48
|
if (!isExit && !isImportMain)
|
|
49
49
|
continue;
|
|
50
50
|
const lineNum = i + 1;
|
|
51
|
-
if (disableAllowed && ctx.isLineDisabled(lineNum,
|
|
51
|
+
if (disableAllowed && ctx.isLineDisabled(lineNum, "no-process-exit-outside-main"))
|
|
52
52
|
continue;
|
|
53
53
|
const docPath = new rules_config_1.RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);
|
|
54
54
|
violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i]?.trim() ?? '', `A process exit outside main()/runMain. READ ${docPath} — throw a semantic error and let main pick the exit code.`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-process-exit-outside-main.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-process-exit-outside-main.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"no-process-exit-outside-main.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-process-exit-outside-main.ts"],"names":[],"mappings":";;;AACA,0DAAyF;AAGzF,0DAAyD;AACzD,0DAAuD;AACvD,0DAAiE;AAEjE,MAAM,aAAa,GAAG,2BAA2B,CAAC;AAClD,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAC1C,gGAAgG;AAChG,MAAM,iBAAiB,GAAG,sDAAsD,CAAC;AACjF,iGAAiG;AACjG,8FAA8F;AAC9F,uGAAuG;AACvG,MAAM,cAAc,GAAG,2HAA2H,CAAC;AACnJ,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAEhD,gGAAgG;AAChG,iGAAiG;AACjG,0FAA0F;AAC1F,SAAS,qBAAqB,CAAC,aAAgC,EAAE,GAAW;IACxE,KAAK,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/B,MAAM,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QACtD,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACvC,CAAC;IACD,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,MAAa,4BAA6B,SAAQ,2BAAsC;IACpF,YAAY,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,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,8BAA8B,CAAC;gBAAE,SAAS;YAC5F,MAAM,OAAO,GAAG,IAAI,6BAAc,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;YACzF,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EACrD,+CAA+C,OAAO,4DAA4D,CAAC,CAAC,CAAC;QAC7H,CAAC;QACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;YAAE,IAAA,qCAAsB,EAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QACpF,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AArCD,oEAqCC","sourcesContent":["import { SourceContributionConfig } from \"../source-contribution-config\";\nimport { writeTemplateIfMissing, RepoRootFinder, Option } from \"@webpieces/rules-config\";\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\n\nconst INSTRUCT_FILE = 'webpieces.noexitinmain.md';\nconst EXIT_REGEX = /\\bprocess\\.exit\\s*\\(/;\n// `import { ... main ... } from '...'` — importing another module's `main` (incl. `main as X`).\nconst IMPORT_MAIN_REGEX = /^\\s*import\\b[^;]*\\{[^}]*\\bmain\\b[^}]*\\}[^;]*\\bfrom\\b/;\n// Named function / arrow-const openers, used to find the enclosing function's name. Deliberately\n// only matches DEFINITIONS (`function foo(`, `const foo = (`/`= function`), never a call like\n// `main()` — so `main().catch(...)` inside runMain is skipped and the scan reaches `function runMain`.\nconst FUNC_DEF_REGEX = /(?:export\\s+)?(?:async\\s+)?function\\s+(\\w+)\\s*\\(|(?:export\\s+)?(?:const|let)\\s+(\\w+)\\s*=\\s*(?:async\\s*)?(?:\\(|function\\b)/;\nconst ALLOWED_FN = new Set(['main', 'runMain']);\n\n// Walk backward from `idx` for the nearest NAMED function/arrow definition and return its name.\n// Line-based heuristic (the edit engine has no AST): good enough to recognise a `main`/`runMain`\n// wrapper enclosing the exit. Returns null at module scope (no enclosing named function).\nfunction enclosingFunctionName(strippedLines: readonly string[], idx: number): string | null {\n for (let j = idx; j >= 0; j -= 1) {\n const m = FUNC_DEF_REGEX.exec(strippedLines[j] ?? '');\n if (m) return m[1] ?? m[2] ?? null;\n }\n return null;\n}\n\nexport class NoProcessExitOutsideMainRule extends EditRuleBase<SourceContributionConfig> {\n constructor(config: SourceContributionConfig) { super(config, 'no-process-exit-outside-main', 'no-process-exit-outside-main'); }\n\n readonly description = 'Disallow process.exit() outside a main()/runMain wrapper (and importing another module\\'s main). A deep exit crashes a reused server/command too early; throw a semantic error and let main pick the exit code.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n override readonly defaultOptions = {};\n get fixHint(): FixHint {\n return new FixHint(\n 'process.exit() outside main()/runMain (or an import of another module\\'s `main`) — a deep exit can crash a reused server or command far too early, and exit 0 masquerades as success.',\n 'READ the instruct-ai doc at the absolute path on the violation line above, then:',\n [\n new Option('Throw a semantic error instead of exiting — RuleFailError for an expected failure, an ordinary Error for a bug/precondition — and let main()/runMain translate it to an exit code.', true),\n new Option('A bin owns the single exit: `if (require.main === module) runMain(main)`. Need a specific code deep down? `throw new CliExitError(code, message)`.'),\n new Option('Do not import another module\\'s `main` — call a named function; only a thin wrapper calls main.'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable no-process-exit-outside-main -- <reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n for (let i = 0; i < ctx.strippedLines.length; i += 1) {\n const stripped = ctx.strippedLines[i] ?? '';\n const isExit = EXIT_REGEX.test(stripped)\n && !ALLOWED_FN.has(enclosingFunctionName(ctx.strippedLines, i) ?? '');\n const isImportMain = IMPORT_MAIN_REGEX.test(stripped);\n if (!isExit && !isImportMain) continue;\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"no-process-exit-outside-main\")) continue;\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n violations.push(new V(lineNum, ctx.lines[i]?.trim() ?? '',\n `A process exit outside main()/runMain. READ ${docPath} — throw a semantic error and let main pick the exit code.`));\n }\n if (violations.length > 0) writeTemplateIfMissing(ctx.workspaceRoot, INSTRUCT_FILE);\n return violations;\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SourceContributionConfig } from "../source-contribution-config";
|
|
2
2
|
import type { EditContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { EditRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
5
|
-
export declare class NoSymbolDiTokensRule extends EditRuleBase<
|
|
6
|
-
constructor(config:
|
|
5
|
+
export declare class NoSymbolDiTokensRule extends EditRuleBase<SourceContributionConfig> {
|
|
6
|
+
constructor(config: SourceContributionConfig);
|
|
7
7
|
readonly description = "Disallow Symbol() DI tokens outside explicitly configured paths. Use @injectable(bindingScopeValues.Singleton) + inject-by-type instead.";
|
|
8
8
|
readonly files: string[];
|
|
9
9
|
readonly defaultOptions: {
|
|
@@ -67,7 +67,7 @@ class NoSymbolDiTokensRule extends hook_runtime_2.EditRuleBase {
|
|
|
67
67
|
if (!SYMBOL_DI_REGEX.test(stripped ?? ''))
|
|
68
68
|
continue;
|
|
69
69
|
const lineNum = i + 1;
|
|
70
|
-
if (disableAllowed && ctx.isLineDisabled(lineNum,
|
|
70
|
+
if (disableAllowed && ctx.isLineDisabled(lineNum, "no-symbol-di-tokens"))
|
|
71
71
|
continue;
|
|
72
72
|
violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i]?.trim() ?? ''));
|
|
73
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-symbol-di-tokens.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-symbol-di-tokens.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"no-symbol-di-tokens.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-symbol-di-tokens.ts"],"names":[],"mappings":";;;AACA,0DAAiD;AAGjD,0DAAyD;AACzD,0DAAuD;AACvD,0DAAiE;AAEjE,MAAM,eAAe,GAAG,wBAAwB,CAAC;AAEjD,MAAM,UAAU,GAAa,CAAC,aAAa,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC;AAE3E,SAAS,WAAW,CAAC,OAAe;IAChC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QACxB,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,IAAI,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;gBACzB,EAAE,IAAI,IAAI,CAAC;gBACX,CAAC,IAAI,CAAC,CAAC;gBACP,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG;oBAAE,CAAC,IAAI,CAAC,CAAC;gBAC/B,SAAS;YACb,CAAC;YACD,EAAE,IAAI,OAAO,CAAC;YACd,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACb,EAAE,IAAI,MAAM,CAAC;YACb,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACb,CAAC;QACD,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;YAC/B,EAAE,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AAE,CAAC;QACpD,IAAI,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,YAAY,CAAC;YAAE,OAAO,EAAE,CAAC;QAE7D,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;QAC1D,MAAM,UAAU,GAAQ,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YACtC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAC;gBAAE,SAAS;YACpD,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,cAAc,IAAI,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,qBAAqB,CAAC;gBAAE,SAAS;YACnF,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAChE,CAAC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAlCD,oDAkCC","sourcesContent":["import { SourceContributionConfig } from \"../source-contribution-config\";\nimport { Option } from \"@webpieces/rules-config\";\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\n\nconst SYMBOL_DI_REGEX = /=\\s*Symbol(?:\\.for)?\\(/;\n\nconst TEST_PATHS: RegExp[] = [/\\.test\\.ts$/, /\\.spec\\.ts$/, /__tests__\\//];\n\nfunction globToRegex(pattern: string): RegExp {\n let re = '';\n let i = 0;\n while (i < pattern.length) {\n const ch = pattern[i];\n if (ch === '*') {\n if (pattern[i + 1] === '*') {\n re += '.*';\n i += 2;\n if (pattern[i] === '/') i += 1;\n continue;\n }\n re += '[^/]*';\n i += 1;\n continue;\n }\n if (ch === '?') {\n re += '[^/]';\n i += 1;\n continue;\n }\n if ('.+^$(){}|[]\\\\'.includes(ch)) {\n re += '\\\\' + ch;\n i += 1;\n continue;\n }\n re += ch;\n i += 1;\n }\n return new RegExp('^' + re + '$');\n}\n\nfunction isAllowedPath(relativePath: string, allowedPaths: readonly string[]): boolean {\n if (TEST_PATHS.some((re: RegExp) => re.test(relativePath))) return true;\n return allowedPaths.some((pattern: string) => globToRegex(pattern).test(relativePath));\n}\n\nexport class NoSymbolDiTokensRule extends EditRuleBase<SourceContributionConfig> {\n constructor(config: SourceContributionConfig) { super(config, 'no-symbol-di-tokens', 'no-symbol-di-tokens'); }\n\n readonly description = 'Disallow Symbol() DI tokens outside explicitly configured paths. Use @injectable(bindingScopeValues.Singleton) + inject-by-type instead.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n override readonly defaultOptions = { allowedPaths: [] };\n get fixHint(): FixHint {\n return new FixHint(\n 'Symbol() used as a DI token — we avoid Symbol DI tokens where we can.',\n 'Pick one:',\n [\n new Option('Use @injectable(bindingScopeValues.Singleton) on the class and inject by type — no Symbol needed.', true),\n new Option('Implement an API interface — import the Symbol from the API definition and use @provideSingletonDefaultForApi(TOKEN).'),\n new Option('External lib class (DataSource, Anthropic, etc.) — bind<Cls>(Cls).toDynamicValue(...).inSingletonScope() — no Symbol.'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable no-symbol-di-tokens -- <reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const allowedPaths = this.config.allowedPaths ?? [];\n if (isAllowedPath(ctx.relativePath, allowedPaths)) return [];\n\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n for (let i = 0; i < ctx.strippedLines.length; i += 1) {\n const stripped = ctx.strippedLines[i];\n if (!SYMBOL_DI_REGEX.test(stripped ?? '')) continue;\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"no-symbol-di-tokens\")) continue;\n violations.push(new V(lineNum, ctx.lines[i]?.trim() ?? ''));\n }\n return violations;\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SourceContributionConfig } from "../source-contribution-config";
|
|
2
2
|
import type { EditContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { EditRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
5
|
-
export declare class NoUnmanagedExceptionsRule extends EditRuleBase<
|
|
6
|
-
constructor(config:
|
|
5
|
+
export declare class NoUnmanagedExceptionsRule extends EditRuleBase<SourceContributionConfig> {
|
|
6
|
+
constructor(config: SourceContributionConfig);
|
|
7
7
|
readonly description = "try/catch is generally not allowed. Only allowed in chokepoints (filter, globalErrorHandler) or other rare locations.";
|
|
8
8
|
readonly files: string[];
|
|
9
9
|
get fixHint(): FixHint;
|
|
@@ -38,7 +38,7 @@ class NoUnmanagedExceptionsRule extends hook_runtime_2.EditRuleBase {
|
|
|
38
38
|
if (!TRY_PATTERN.test(stripped))
|
|
39
39
|
continue;
|
|
40
40
|
const lineNum = i + 1;
|
|
41
|
-
if (disableAllowed && ctx.isLineDisabled(lineNum,
|
|
41
|
+
if (disableAllowed && ctx.isLineDisabled(lineNum, "no-unmanaged-exceptions"))
|
|
42
42
|
continue;
|
|
43
43
|
if (disableAllowed && hasPrecedingDisable(ctx.lines, i))
|
|
44
44
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-unmanaged-exceptions.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/no-unmanaged-exceptions.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"no-unmanaged-exceptions.js","sourceRoot":"","sources":["../../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IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YACtC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAAE,SAAS;YAC1C,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,cAAc,IAAI,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,yBAAyB,CAAC;gBAAE,SAAS;YACvF,IAAI,cAAc,IAAI,mBAAmB,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;gBAAE,SAAS;YAClE,MAAM,OAAO,GAAG,IAAI,6BAAc,EAAE,CAAC,iBAAiB,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;YACzF,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAC9C,iDAAiD,OAAO,wEAAwE,CAAC,CAAC,CAAC;QAC3I,CAAC;QACD,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;YAAE,IAAA,qCAAsB,EAAC,GAAG,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;QACpF,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAvCD,8DAuCC","sourcesContent":["import { SourceContributionConfig } from \"../source-contribution-config\";\nimport { RepoRootFinder, Option } from \"@webpieces/rules-config\";\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\nimport { writeTemplateIfMissing } from '@webpieces/rules-config';\n\nconst INSTRUCT_FILE = 'webpieces.exceptions.md';\nconst TRY_PATTERN = /\\btry\\s*\\{/;\n\n// Both webpieces-disable and the existing ESLint directive suppress this rule\nconst DISABLE_PATTERN = /@webpieces\\/no-unmanaged-exceptions|webpieces-disable\\s+(?:[\\w-]+,\\s*)*no-unmanaged-exceptions/;\n\nfunction hasPrecedingDisable(lines: readonly string[], idx: number): boolean {\n if (idx === 0) return false;\n const prevLine = lines[idx - 1];\n return DISABLE_PATTERN.test(prevLine);\n}\n\nexport class NoUnmanagedExceptionsRule extends EditRuleBase<SourceContributionConfig> {\n constructor(config: SourceContributionConfig) { super(config, 'no-unmanaged-exceptions', 'no-unmanaged-exceptions'); }\n\n readonly description = 'try/catch is generally not allowed. Only allowed in chokepoints (filter, globalErrorHandler) or other rare locations.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n get fixHint(): FixHint {\n return new FixHint(\n 'try/catch is generally not allowed. READ the instruct-ai doc at the absolute path on the violation line above. Only chokepoints (filter, globalErrorHandler) may catch exceptions.',\n 'Pick one (NOTE: for external calls — execSync, fs, network — the preferred option is almost always right; let it throw, the top-level runner reports it):',\n [\n new Option('Remove the try/catch — let the exception bubble to the top-level chokepoint (filter, globalErrorHandler) where it is already logged and handled.', true),\n new Option(\n 'If you genuinely believe this IS a chokepoint, STOP and ask the human first:\\n'\n + ' - What exception could be thrown here\\n'\n + ' - What the current top-level chokepoint is (the try/catch at the top of the call stack)\\n'\n + ' - Why throwing to that chokepoint would be wrong in this specific case\\n'\n + ' Then ask whether to remove the try/catch or add a disable comment.',\n ),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable no-unmanaged-exceptions -- <reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n for (let i = 0; i < ctx.strippedLines.length; i += 1) {\n const stripped = ctx.strippedLines[i];\n if (!TRY_PATTERN.test(stripped)) continue;\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"no-unmanaged-exceptions\")) continue;\n if (disableAllowed && hasPrecedingDisable(ctx.lines, i)) continue;\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n violations.push(new V(lineNum, ctx.lines[i].trim(),\n `try/catch is generally not allowed here. READ ${docPath} — only chokepoints (filter, globalErrorHandler) may catch exceptions.`));\n }\n if (violations.length > 0) writeTemplateIfMissing(ctx.workspaceRoot, INSTRUCT_FILE);\n return violations;\n }\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SourceContributionConfig } from "../source-contribution-config";
|
|
2
2
|
import type { EditContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { EditRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
5
|
-
export declare class RequireReturnTypeRule extends EditRuleBase<
|
|
6
|
-
constructor(config:
|
|
5
|
+
export declare class RequireReturnTypeRule extends EditRuleBase<SourceContributionConfig> {
|
|
6
|
+
constructor(config: SourceContributionConfig);
|
|
7
7
|
readonly description = "Every function and method must declare its return type.";
|
|
8
8
|
readonly files: string[];
|
|
9
9
|
get fixHint(): FixHint;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RequireReturnTypeRule = void 0;
|
|
4
|
-
const rules_config_1 = require("@webpieces/rules-config");
|
|
5
4
|
const hook_runtime_1 = require("@webpieces/hook-runtime");
|
|
6
5
|
const hook_runtime_2 = require("@webpieces/hook-runtime");
|
|
7
6
|
const hook_runtime_3 = require("@webpieces/hook-runtime");
|
|
@@ -43,7 +42,7 @@ class RequireReturnTypeRule extends hook_runtime_2.EditRuleBase {
|
|
|
43
42
|
if (!isMissingReturnType(stripped))
|
|
44
43
|
continue;
|
|
45
44
|
const lineNum = i + 1;
|
|
46
|
-
if (disableAllowed && ctx.isLineDisabled(lineNum,
|
|
45
|
+
if (disableAllowed && ctx.isLineDisabled(lineNum, "require-return-type"))
|
|
47
46
|
continue;
|
|
48
47
|
violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i].trim()));
|
|
49
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"require-return-type.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/require-return-type.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"require-return-type.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/require-return-type.ts"],"names":[],"mappings":";;;AAIA,0DAAyD;AACzD,0DAAuD;AACvD,0DAAiE;AAEjE,gGAAgG;AAChG,4EAA4E;AAC5E,MAAM,iBAAiB,GAAG,kDAAkD,CAAC;AAE7E,8EAA8E;AAC9E,MAAM,cAAc,GAAG,yDAAyD,CAAC;AAEjF,qFAAqF;AACrF,MAAM,aAAa,GAAG,gEAAgE,CAAC;AAEvF,qEAAqE;AACrE,MAAM,eAAe,GAAG,aAAa,CAAC;AAEtC,iEAAiE;AACjE,MAAM,YAAY,GAAG,kFAAkF,CAAC;AAExG,SAAS,mBAAmB,CAAC,IAAY;IACrC,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1C,MAAM,UAAU,GACZ,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC;QAC5B,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC;QACzB,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,IAAI,CAAC;AAChB,CAAC;AAED,MAAa,qBAAsB,SAAQ,2BAAsC;IAC7E,YAAY,MAAgC,IAAI,KAAK,CAAC,MAAM,EAAE,qBAAqB,EAAE,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAErG,WAAW,GAAG,yDAAyD,CAAC;IAC/D,KAAK,GAAG,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;IAClD,IAAI,OAAO;QACP,OAAO,IAAI,sBAAO,CACd,iCAAiC,EACjC,4DAA4D,EAC5D,EAAE,EACF,IAAI,4BAAa,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,IAAI,EAAE,sDAAsD,CAAC,CAChH,CAAC;IACN,CAAC;IAED,KAAK,CAAC,GAAgB;QAClB,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,IAAI,IAAI,CAAC;QAC1D,MAAM,UAAU,GAAQ,EAAE,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;YACnD,MAAM,QAAQ,GAAG,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;YACtC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;gBAAE,SAAS;YAC7C,MAAM,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,cAAc,IAAI,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,qBAAqB,CAAC;gBAAE,SAAS;YACnF,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AA1BD,sDA0BC","sourcesContent":["import { SourceContributionConfig } from \"../source-contribution-config\";\n\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\n\n// Matches function/method signatures that don't have `: ReturnType` before the `{` body opener.\n// Pattern: function name(<params>) { — missing `: Type` between `)` and `{`\nconst FUNC_DECL_MISSING = /\\bfunction\\s+\\w+\\s*(?:<[^>]*>)?\\s*\\([^)]*\\)\\s*\\{/;\n\n// Matches class method signatures: indented, optional async, name(<params>) {\nconst METHOD_MISSING = /^\\s{2,}(?:async\\s+)?\\w+\\s*(?:<[^>]*>)?\\s*\\([^)]*\\)\\s*\\{/;\n\n// Arrow function: const name = (async)? (<params>) => — missing `: Type` before `=>`\nconst ARROW_MISSING = /\\bconst\\s+\\w+\\s*=\\s*(?:async\\s+)?(?:<[^>]*>)?\\s*\\([^)]*\\)\\s*=>/;\n\n// Lines that have ): ReturnType before { or => — these are COMPLIANT\nconst HAS_RETURN_TYPE = /\\)\\s*:\\s*\\S/;\n\n// Skip constructors, getters, setters, and control flow keywords\nconst SKIP_PATTERN = /\\b(?:constructor|get\\s+\\w+|set\\s+\\w+|if|else|while|for|switch|catch|return)\\s*\\(/;\n\nfunction isMissingReturnType(line: string): boolean {\n if (SKIP_PATTERN.test(line)) return false;\n const isFuncLike =\n FUNC_DECL_MISSING.test(line) ||\n METHOD_MISSING.test(line) ||\n ARROW_MISSING.test(line);\n if (!isFuncLike) return false;\n if (HAS_RETURN_TYPE.test(line)) return false;\n return true;\n}\n\nexport class RequireReturnTypeRule extends EditRuleBase<SourceContributionConfig> {\n constructor(config: SourceContributionConfig) { super(config, 'require-return-type', 'require-return-type'); }\n\n readonly description = 'Every function and method must declare its return type.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n get fixHint(): FixHint {\n return new FixHint(\n 'Missing return type annotation.',\n 'Add a return type: function foo(x: T): ReturnType { ... }.',\n [],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable require-return-type -- <reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n for (let i = 0; i < ctx.strippedLines.length; i += 1) {\n const stripped = ctx.strippedLines[i];\n if (!isMissingReturnType(stripped)) continue;\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"require-return-type\")) continue;\n violations.push(new V(lineNum, ctx.lines[i].trim()));\n }\n return violations;\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ThrowCauseRequiredConfig } from
|
|
1
|
+
import { ThrowCauseRequiredConfig } from "../../configs/rule-configs";
|
|
2
2
|
import type { EditContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { EditRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
@@ -42,7 +42,7 @@ class ThrowCauseRequiredRule extends hook_runtime_2.EditRuleBase {
|
|
|
42
42
|
if (CAUSE_PATTERN.test(stripped))
|
|
43
43
|
continue;
|
|
44
44
|
const lineNum = i + 1;
|
|
45
|
-
if (disableAllowed && ctx.isLineDisabled(lineNum,
|
|
45
|
+
if (disableAllowed && ctx.isLineDisabled(lineNum, "throw-cause-required"))
|
|
46
46
|
continue;
|
|
47
47
|
violations.push(new hook_runtime_1.Violation(lineNum, ctx.lines[i].trim()));
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"throw-cause-required.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/throw-cause-required.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"throw-cause-required.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/throw-cause-required.ts"],"names":[],"mappings":";;;AAAA,0DAAiD;AAIjD,0DAAyD;AACzD,0DAAuD;AACvD,0DAAiE;AACjE,0DAAiE;AAEjE;;GAEG;AACH,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAErD;;GAEG;AACH,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD;;GAEG;AACH,MAAM,aAAa,GAAG,0BAA0B,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E,SAAS;YAEpF,UAAU,CAAC,IAAI,CAAC,IAAI,wBAAC,CAAC,OAAO,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;QACzD,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC;YAAE,IAAA,qCAAsB,EAAC,GAAG,CAAC,aAAa,EAAE,yBAAyB,CAAC,CAAC;QAChG,OAAO,UAAU,CAAC;IACtB,CAAC;CACJ;AAtCD,wDAsCC","sourcesContent":["import { Option } from \"@webpieces/rules-config\";\nimport { ThrowCauseRequiredConfig } from \"../../configs/rule-configs\";\n\nimport type { EditContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { EditRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint, DisableEscape } from '@webpieces/hook-runtime';\nimport { writeTemplateIfMissing } from '@webpieces/rules-config';\n\n/**\n * Matches: throw new SomeClass(\n */\nconst THROW_NEW_PATTERN = /\\bthrow\\s+new\\s+\\w+\\s*\\(/;\n\n/**\n * Matches: error.message or error2.message or error3.message\n */\nconst ERROR_MESSAGE_PATTERN = /\\berror\\d*\\.message\\b/;\n\n/**\n * Matches: cause: error or cause: error2 etc. (the good pattern)\n */\nconst CAUSE_PATTERN = /\\bcause\\s*:\\s*error\\d*\\b/;\n\nexport class ThrowCauseRequiredRule extends EditRuleBase<ThrowCauseRequiredConfig> {\n constructor(config: ThrowCauseRequiredConfig) { super(config, 'throw-cause-required', 'throw-cause-required'); }\n\n readonly description = 'When rethrowing with added context, chain the original exception: throw new Error(\"msg\", { cause: error })';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n get fixHint(): FixHint {\n return new FixHint(\n 'Rethrowing with error.message loses the original stack trace. Use { cause: error } to chain it.',\n 'Pick one:',\n [\n new Option('Remove the try-catch entirely. Letting the original exception bubble is usually the best option.', true),\n new Option('throw new Error(\"add more info here\", { cause: error }); chains the error and preserves the full stack trace.'),\n new Option('throw new SpecificError(\"add info here\", { cause: error }); e.g. new InformAiError(\"what happened for AI\", { cause: error }).'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// webpieces-disable throw-cause-required -- <reason>'),\n );\n }\n\n check(ctx: EditContext): readonly Violation[] {\n const disableAllowed = this.config.disableAllowed ?? true;\n const violations: V[] = [];\n const lines = ctx.strippedLines;\n\n for (let i = 0; i < lines.length; i += 1) {\n const stripped = lines[i];\n if (!THROW_NEW_PATTERN.test(stripped)) continue;\n if (!ERROR_MESSAGE_PATTERN.test(stripped)) continue;\n if (CAUSE_PATTERN.test(stripped)) continue;\n\n const lineNum = i + 1;\n if (disableAllowed && ctx.isLineDisabled(lineNum, \"throw-cause-required\")) continue;\n\n violations.push(new V(lineNum, ctx.lines[i].trim()));\n }\n\n if (violations.length > 0) writeTemplateIfMissing(ctx.workspaceRoot, 'webpieces.exceptions.md');\n return violations;\n }\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ValidateTsInSrcConfig } from
|
|
1
|
+
import { ValidateTsInSrcConfig } from "../../configs/rule-configs";
|
|
2
2
|
import type { FileContext, Violation } from '@webpieces/hook-runtime';
|
|
3
3
|
import { FileRuleBase } from '@webpieces/hook-runtime';
|
|
4
4
|
import { FixHint } from '@webpieces/hook-runtime';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-ts-in-src.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/validate-ts-in-src.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAE7B,
|
|
1
|
+
{"version":3,"file":"validate-ts-in-src.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/validate-ts-in-src.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAE7B,0DAAiE;AAIjE,0DAAyD;AACzD,0DAAuD;AACvD,0DAAkD;AAElD,MAAM,qBAAqB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AgB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,IAAI,0BAA0B,CAAC;QAEpF,kEAAkE;QAClE,IAAI,IAAA,6BAAc,EAAC,GAAG,CAAC,kBAAkB,EAAE,YAAY,CAAC;YAAE,OAAO,EAAE,CAAC;QAEpE,MAAM,QAAQ,GAAG,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC;YAAE,OAAO,EAAE,CAAC;QAEzF,MAAM,WAAW,GAAG,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QAElE,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,OAAO,CAAC,IAAI,wBAAC,CACT,CAAC,EACD,GAAG,CAAC,kBAAkB,EACtB,8EAA8E,CACjF,CAAC,CAAC;QACP,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9D,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,YAAY,KAAK,KAAK,EAAE,CAAC;YACvE,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;YAC/D,OAAO,CAAC,IAAI,wBAAC,CACT,CAAC,EACD,GAAG,CAAC,kBAAkB,EACtB,4BAA4B,WAAW,uDAAuD,CACjG,CAAC,CAAC;QACP,CAAC;QAED,OAAO,EAAE,CAAC;IACd,CAAC;CACJ;AApDD,kDAoDC","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\n\nimport { isPathExcluded, Option } from \"@webpieces/rules-config\";\nimport { ValidateTsInSrcConfig } from \"../../configs/rule-configs\";\n\nimport type { FileContext, Violation } from '@webpieces/hook-runtime';\nimport { Violation as V } from '@webpieces/hook-runtime';\nimport { FileRuleBase } from '@webpieces/hook-runtime';\nimport { FixHint } from '@webpieces/hook-runtime';\n\nconst DEFAULT_EXCLUDE_PATHS = [\n 'node_modules', 'dist', '.nx', '.git',\n '**/*.d.ts', '**/jest.config.ts',\n];\nconst DEFAULT_ALLOWED_ROOT_FILES = ['jest.setup.ts'];\n\nfunction findProjectRoot(filePath: string, workspaceRoot: string): string | null {\n let dir = path.dirname(filePath);\n while (dir !== workspaceRoot && dir.startsWith(workspaceRoot)) {\n if (fs.existsSync(path.join(dir, 'project.json'))) return dir;\n dir = path.dirname(dir);\n }\n return null;\n}\n\nexport class ValidateTsInSrcRule extends FileRuleBase<ValidateTsInSrcConfig> {\n constructor(config: ValidateTsInSrcConfig) { super(config, 'validate-ts-in-src', 'validate-ts-in-src'); }\n\n readonly description = 'Every .ts file must belong to a project\\'s src/ directory.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n override readonly defaultOptions = {\n excludePaths: DEFAULT_EXCLUDE_PATHS,\n allowedRootFiles: DEFAULT_ALLOWED_ROOT_FILES,\n };\n readonly fixHint = new FixHint(\n 'TypeScript file is outside a project src/ directory.',\n 'Fix by one of:',\n [\n new Option('Move the file into an existing project\\'s src/ directory, or create a new project with project.json that owns the directory.', true),\n new Option('Add a dir or glob (e.g. \"**/codegen.ts\") to validate-ts-in-src.excludePaths in webpieces.config.json'),\n ],\n );\n\n check(ctx: FileContext): readonly Violation[] {\n if (ctx.tool !== 'Write') return [];\n\n const excludePaths = this.config.excludePaths ?? DEFAULT_EXCLUDE_PATHS;\n const allowedRootFiles = this.config.allowedRootFiles ?? DEFAULT_ALLOWED_ROOT_FILES;\n\n // Holistic exclusion (Layer 1 + Layer 2): bare dir names + globs.\n if (isPathExcluded(ctx.targetRelativePath, excludePaths)) return [];\n\n const relParts = ctx.targetRelativePath.split(path.sep);\n if (relParts.length === 1 && allowedRootFiles.indexOf(relParts[0] ?? '') >= 0) return [];\n\n const projectRoot = findProjectRoot(ctx.filePath, ctx.targetRoot);\n\n if (!projectRoot) {\n return [new V(\n 1,\n ctx.targetRelativePath,\n 'File is not inside any Nx project. Move it into a project\\'s src/ directory.',\n )];\n }\n\n const relToProject = path.relative(projectRoot, ctx.filePath);\n if (!relToProject.startsWith('src' + path.sep) && relToProject !== 'src') {\n const projectName = path.relative(ctx.targetRoot, projectRoot);\n return [new V(\n 1,\n ctx.targetRelativePath,\n `File is inside project \\`${projectName}\\` but outside its src/ directory. Move it into src/.`,\n )];\n }\n\n return [];\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BaseRuleConfig } from '@webpieces/rules-sdk';
|
|
2
|
+
/** Resolved settings consumed by source contributions; the canonical owner validates their schema. */
|
|
3
|
+
export declare class SourceContributionConfig extends BaseRuleConfig {
|
|
4
|
+
limit?: number;
|
|
5
|
+
disableAllowed?: boolean;
|
|
6
|
+
allowTopLevel?: boolean;
|
|
7
|
+
allowedPaths?: string[];
|
|
8
|
+
allowGlobs?: string[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SourceContributionConfig = void 0;
|
|
4
|
+
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
5
|
+
/** Resolved settings consumed by source contributions; the canonical owner validates their schema. */
|
|
6
|
+
class SourceContributionConfig extends rules_sdk_1.BaseRuleConfig {
|
|
7
|
+
limit;
|
|
8
|
+
disableAllowed;
|
|
9
|
+
allowTopLevel;
|
|
10
|
+
allowedPaths;
|
|
11
|
+
allowGlobs;
|
|
12
|
+
}
|
|
13
|
+
exports.SourceContributionConfig = SourceContributionConfig;
|
|
14
|
+
//# sourceMappingURL=source-contribution-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-contribution-config.js","sourceRoot":"","sources":["../../../../../../packages/tooling/ai-hook-rules/src/core/source-contribution-config.ts"],"names":[],"mappings":";;;AAAA,oDAAsD;AAEtD,sGAAsG;AACtG,MAAa,wBAAyB,SAAQ,0BAAc;IACxD,KAAK,CAAU;IACf,cAAc,CAAW;IACzB,aAAa,CAAW;IACxB,YAAY,CAAY;IACxB,UAAU,CAAY;CACzB;AAND,4DAMC","sourcesContent":["import { BaseRuleConfig } from '@webpieces/rules-sdk';\n\n/** Resolved settings consumed by source contributions; the canonical owner validates their schema. */\nexport class SourceContributionConfig extends BaseRuleConfig {\n limit?: number;\n disableAllowed?: boolean;\n allowTopLevel?: boolean;\n allowedPaths?: string[];\n allowGlobs?: string[];\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -12,3 +12,5 @@ export { NoProcessExitOutsideMainRule } from './core/rules/no-process-exit-outsi
|
|
|
12
12
|
export { NoCustomCssRule } from './core/rules/no-custom-css';
|
|
13
13
|
export { NoJsFilesRule } from './core/rules/no-js-files';
|
|
14
14
|
export { SourceHookRules } from './core/runner';
|
|
15
|
+
export { THROW_CAUSE_MODES, VALIDATE_TS_MODES, ThrowCauseRequiredConfig, NoJsFilesConfig, ValidateTsInSrcConfig } from './configs/rule-configs';
|
|
16
|
+
export type { ThrowCauseMode, ValidateTsMode } from './configs/rule-configs';
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SourceHookRules = exports.NoJsFilesRule = exports.NoCustomCssRule = exports.NoProcessExitOutsideMainRule = exports.NoSymbolDiTokensRule = exports.ThrowCauseRequiredRule = exports.CatchErrorPatternRule = exports.NoUnmanagedExceptionsRule = exports.RequireReturnTypeRule = exports.NoDestructureRule = exports.ValidateTsInSrcRule = exports.MaxFileLinesRule = exports.NoImplicitAnyRule = exports.NoAnyUnknownRule = void 0;
|
|
4
|
-
//
|
|
3
|
+
exports.ValidateTsInSrcConfig = exports.NoJsFilesConfig = exports.ThrowCauseRequiredConfig = exports.VALIDATE_TS_MODES = exports.THROW_CAUSE_MODES = exports.SourceHookRules = exports.NoJsFilesRule = exports.NoCustomCssRule = exports.NoProcessExitOutsideMainRule = exports.NoSymbolDiTokensRule = exports.ThrowCauseRequiredRule = exports.CatchErrorPatternRule = exports.NoUnmanagedExceptionsRule = exports.RequireReturnTypeRule = exports.NoDestructureRule = exports.ValidateTsInSrcRule = exports.MaxFileLinesRule = exports.NoImplicitAnyRule = exports.NoAnyUnknownRule = void 0;
|
|
4
|
+
// Source-owned configs are exported below; contributed source rules use the internal
|
|
5
|
+
// SourceContributionConfig, and shared scope contracts come from @webpieces/rules-sdk.
|
|
5
6
|
var no_any_unknown_1 = require("./core/rules/no-any-unknown");
|
|
6
7
|
Object.defineProperty(exports, "NoAnyUnknownRule", { enumerable: true, get: function () { return no_any_unknown_1.NoAnyUnknownRule; } });
|
|
7
8
|
var no_implicit_any_1 = require("./core/rules/no-implicit-any");
|
|
@@ -30,4 +31,10 @@ var no_js_files_1 = require("./core/rules/no-js-files");
|
|
|
30
31
|
Object.defineProperty(exports, "NoJsFilesRule", { enumerable: true, get: function () { return no_js_files_1.NoJsFilesRule; } });
|
|
31
32
|
var runner_1 = require("./core/runner");
|
|
32
33
|
Object.defineProperty(exports, "SourceHookRules", { enumerable: true, get: function () { return runner_1.SourceHookRules; } });
|
|
34
|
+
var rule_configs_1 = require("./configs/rule-configs");
|
|
35
|
+
Object.defineProperty(exports, "THROW_CAUSE_MODES", { enumerable: true, get: function () { return rule_configs_1.THROW_CAUSE_MODES; } });
|
|
36
|
+
Object.defineProperty(exports, "VALIDATE_TS_MODES", { enumerable: true, get: function () { return rule_configs_1.VALIDATE_TS_MODES; } });
|
|
37
|
+
Object.defineProperty(exports, "ThrowCauseRequiredConfig", { enumerable: true, get: function () { return rule_configs_1.ThrowCauseRequiredConfig; } });
|
|
38
|
+
Object.defineProperty(exports, "NoJsFilesConfig", { enumerable: true, get: function () { return rule_configs_1.NoJsFilesConfig; } });
|
|
39
|
+
Object.defineProperty(exports, "ValidateTsInSrcConfig", { enumerable: true, get: function () { return rule_configs_1.ValidateTsInSrcConfig; } });
|
|
33
40
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/ai-hook-rules/src/index.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/tooling/ai-hook-rules/src/index.ts"],"names":[],"mappings":";;;AAAA,qFAAqF;AACrF,uFAAuF;AACvF,8DAA+D;AAAtD,kHAAA,gBAAgB,OAAA;AACzB,gEAAiE;AAAxD,oHAAA,iBAAiB,OAAA;AAC1B,8DAA+D;AAAtD,kHAAA,gBAAgB,OAAA;AACzB,sEAAsE;AAA7D,yHAAA,mBAAmB,OAAA;AAC5B,8DAAgE;AAAvD,mHAAA,iBAAiB,OAAA;AAC1B,wEAAyE;AAAhE,4HAAA,qBAAqB,OAAA;AAC9B,gFAAiF;AAAxE,oIAAA,yBAAyB,OAAA;AAClC,wEAAyE;AAAhE,4HAAA,qBAAqB,OAAA;AAC9B,0EAA2E;AAAlE,8HAAA,sBAAsB,OAAA;AAC/B,wEAAwE;AAA/D,2HAAA,oBAAoB,OAAA;AAC7B,0FAAyF;AAAhF,4IAAA,4BAA4B,OAAA;AACrC,4DAA6D;AAApD,gHAAA,eAAe,OAAA;AACxB,wDAAyD;AAAhD,4GAAA,aAAa,OAAA;AAEtB,wCAAgD;AAAvC,yGAAA,eAAe,OAAA;AAExB,uDAAgJ;AAAvI,iHAAA,iBAAiB,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAAE,wHAAA,wBAAwB,OAAA;AAAE,+GAAA,eAAe,OAAA;AAAE,qHAAA,qBAAqB,OAAA","sourcesContent":["// Source-owned configs are exported below; contributed source rules use the internal\n// SourceContributionConfig, and shared scope contracts come from @webpieces/rules-sdk.\nexport { NoAnyUnknownRule } from './core/rules/no-any-unknown';\nexport { NoImplicitAnyRule } from './core/rules/no-implicit-any';\nexport { MaxFileLinesRule } from './core/rules/max-file-lines';\nexport { ValidateTsInSrcRule } from './core/rules/validate-ts-in-src';\nexport { NoDestructureRule } from './core/rules/no-destructure';\nexport { RequireReturnTypeRule } from './core/rules/require-return-type';\nexport { NoUnmanagedExceptionsRule } from './core/rules/no-unmanaged-exceptions';\nexport { CatchErrorPatternRule } from './core/rules/catch-error-pattern';\nexport { ThrowCauseRequiredRule } from './core/rules/throw-cause-required';\nexport { NoSymbolDiTokensRule } from './core/rules/no-symbol-di-tokens';\nexport { NoProcessExitOutsideMainRule } from './core/rules/no-process-exit-outside-main';\nexport { NoCustomCssRule } from './core/rules/no-custom-css';\nexport { NoJsFilesRule } from './core/rules/no-js-files';\n\nexport { SourceHookRules } from './core/runner';\n\nexport { THROW_CAUSE_MODES, VALIDATE_TS_MODES, ThrowCauseRequiredConfig, NoJsFilesConfig, ValidateTsInSrcConfig } from './configs/rule-configs';\nexport type { ThrowCauseMode, ValidateTsMode } from './configs/rule-configs';\n"]}
|
package/src/rule-pack.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rulePackManifest = void 0;
|
|
4
|
+
const rule_settings_1 = require("./rule-settings");
|
|
5
|
+
const rules_sdk_1 = require("@webpieces/rules-sdk");
|
|
6
|
+
const rule_configs_1 = require("./configs/rule-configs");
|
|
7
|
+
const package_json_1 = require("../package.json");
|
|
8
|
+
/** Source policies own their schema; other contributions consume their canonical owner's settings. */
|
|
9
|
+
const ownedRules = [
|
|
10
|
+
new rules_sdk_1.OwnedRuleDefinition('throw-cause-required', rule_configs_1.ThrowCauseRequiredConfig.SCHEMA, rules_sdk_1.RULE_SCHEMA_API_VERSION, rule_settings_1.optionalTuning['throw-cause-required'], rule_settings_1.recommendedSeeds['throw-cause-required'], 'rules'),
|
|
11
|
+
new rules_sdk_1.OwnedRuleDefinition('no-js-files', rule_configs_1.NoJsFilesConfig.SCHEMA, rules_sdk_1.RULE_SCHEMA_API_VERSION, rule_settings_1.optionalTuning['no-js-files'], rule_settings_1.recommendedSeeds['no-js-files'], 'rules'),
|
|
12
|
+
new rules_sdk_1.OwnedRuleDefinition('validate-ts-in-src', rule_configs_1.ValidateTsInSrcConfig.SCHEMA, rules_sdk_1.RULE_SCHEMA_API_VERSION, rule_settings_1.optionalTuning['validate-ts-in-src'], rule_settings_1.recommendedSeeds['validate-ts-in-src'], 'rules'),
|
|
13
|
+
];
|
|
14
|
+
exports.rulePackManifest = new rules_sdk_1.RulePackManifest('@webpieces/ai-hook-rules', package_json_1.version, rules_sdk_1.RULE_PACK_API_VERSION, ownedRules, [
|
|
15
|
+
...ownedRules.map(rule => new rules_sdk_1.RuleContribution(rule.id, '@webpieces/ai-hook-rules', 'source-hook')),
|
|
16
|
+
new rules_sdk_1.RuleContribution('no-any-unknown', '@webpieces/code-rules', 'source-hook'),
|
|
17
|
+
new rules_sdk_1.RuleContribution('no-implicit-any', '@webpieces/code-rules', 'source-hook'),
|
|
18
|
+
new rules_sdk_1.RuleContribution('max-file-lines', '@webpieces/code-rules', 'source-hook'),
|
|
19
|
+
new rules_sdk_1.RuleContribution('no-destructure', '@webpieces/code-rules', 'source-hook'),
|
|
20
|
+
new rules_sdk_1.RuleContribution('require-return-type', '@webpieces/code-rules', 'source-hook'),
|
|
21
|
+
new rules_sdk_1.RuleContribution('no-unmanaged-exceptions', '@webpieces/code-rules', 'source-hook'),
|
|
22
|
+
new rules_sdk_1.RuleContribution('catch-error-pattern', '@webpieces/code-rules', 'source-hook'),
|
|
23
|
+
new rules_sdk_1.RuleContribution('no-symbol-di-tokens', '@webpieces/code-rules', 'source-hook'),
|
|
24
|
+
new rules_sdk_1.RuleContribution('no-custom-css', '@webpieces/code-rules', 'source-hook'),
|
|
25
|
+
new rules_sdk_1.RuleContribution('no-process-exit-outside-main', '@webpieces/code-rules', 'source-hook'),
|
|
26
|
+
], [], []);
|
|
27
|
+
//# sourceMappingURL=rule-pack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-pack.js","sourceRoot":"","sources":["../../../../../packages/tooling/ai-hook-rules/src/rule-pack.ts"],"names":[],"mappings":";;;AAAA,mDAAmE;AACnE,oDAA+I;AAC/I,yDAA0G;AAC1G,kDAA0C;AAE1C,sGAAsG;AACtG,MAAM,UAAU,GAAG;IACf,IAAI,+BAAmB,CAAC,sBAAsB,EAAE,uCAAwB,CAAC,MAAM,EAAE,mCAAuB,EAAE,8BAAc,CAAC,sBAAsB,CAAC,EAAE,gCAAgB,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACpM,IAAI,+BAAmB,CAAC,aAAa,EAAE,8BAAe,CAAC,MAAM,EAAE,mCAAuB,EAAE,8BAAc,CAAC,aAAa,CAAC,EAAE,gCAAgB,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC;IAChK,IAAI,+BAAmB,CAAC,oBAAoB,EAAE,oCAAqB,CAAC,MAAM,EAAE,mCAAuB,EAAE,8BAAc,CAAC,oBAAoB,CAAC,EAAE,gCAAgB,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAC9L,CAAC;AAEW,QAAA,gBAAgB,GAAG,IAAI,4BAAgB,CAChD,0BAA0B,EAC1B,sBAAO,EACP,iCAAqB,EACrB,UAAU,EACV;IACI,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,4BAAgB,CAAC,IAAI,CAAC,EAAE,EAAE,0BAA0B,EAAE,aAAa,CAAC,CAAC;IACnG,IAAI,4BAAgB,CAAC,gBAAgB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IAC9E,IAAI,4BAAgB,CAAC,iBAAiB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IAC/E,IAAI,4BAAgB,CAAC,gBAAgB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IAC9E,IAAI,4BAAgB,CAAC,gBAAgB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IAC9E,IAAI,4BAAgB,CAAC,qBAAqB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IACnF,IAAI,4BAAgB,CAAC,yBAAyB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IACvF,IAAI,4BAAgB,CAAC,qBAAqB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IACnF,IAAI,4BAAgB,CAAC,qBAAqB,EAAE,uBAAuB,EAAE,aAAa,CAAC;IACnF,IAAI,4BAAgB,CAAC,eAAe,EAAE,uBAAuB,EAAE,aAAa,CAAC;IAC7E,IAAI,4BAAgB,CAAC,8BAA8B,EAAE,uBAAuB,EAAE,aAAa,CAAC;CAC/F,EACD,EAAE,EACF,EAAE,CACL,CAAC","sourcesContent":["import { optionalTuning, recommendedSeeds } from './rule-settings';\nimport { OwnedRuleDefinition, RuleContribution, RulePackManifest, RULE_PACK_API_VERSION, RULE_SCHEMA_API_VERSION } from '@webpieces/rules-sdk';\nimport { ThrowCauseRequiredConfig, NoJsFilesConfig, ValidateTsInSrcConfig } from './configs/rule-configs';\nimport { version } from '../package.json';\n\n/** Source policies own their schema; other contributions consume their canonical owner's settings. */\nconst ownedRules = [\n new OwnedRuleDefinition('throw-cause-required', ThrowCauseRequiredConfig.SCHEMA, RULE_SCHEMA_API_VERSION, optionalTuning['throw-cause-required'], recommendedSeeds['throw-cause-required'], 'rules'),\n new OwnedRuleDefinition('no-js-files', NoJsFilesConfig.SCHEMA, RULE_SCHEMA_API_VERSION, optionalTuning['no-js-files'], recommendedSeeds['no-js-files'], 'rules'),\n new OwnedRuleDefinition('validate-ts-in-src', ValidateTsInSrcConfig.SCHEMA, RULE_SCHEMA_API_VERSION, optionalTuning['validate-ts-in-src'], recommendedSeeds['validate-ts-in-src'], 'rules'),\n];\n\nexport const rulePackManifest = new RulePackManifest(\n '@webpieces/ai-hook-rules',\n version,\n RULE_PACK_API_VERSION,\n ownedRules,\n [\n ...ownedRules.map(rule => new RuleContribution(rule.id, '@webpieces/ai-hook-rules', 'source-hook')),\n new RuleContribution('no-any-unknown', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('no-implicit-any', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('max-file-lines', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('no-destructure', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('require-return-type', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('no-unmanaged-exceptions', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('catch-error-pattern', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('no-symbol-di-tokens', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('no-custom-css', '@webpieces/code-rules', 'source-hook'),\n new RuleContribution('no-process-exit-outside-main', '@webpieces/code-rules', 'source-hook'),\n ],\n [],\n [],\n);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ConfigObject } from '@webpieces/rules-sdk';
|
|
2
|
+
/** Optional knobs only. Required behaviour is always supplied by the repository. */
|
|
3
|
+
export declare const optionalTuning: Readonly<Record<string, ConfigObject>>;
|
|
4
|
+
/** Written for review by setup/sync; never used as a loader fallback. */
|
|
5
|
+
export declare const recommendedSeeds: Readonly<Record<string, ConfigObject>>;
|