@webpieces/ai-hook-rules 0.4.716 → 0.4.717
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
|
@@ -114,7 +114,9 @@ and per-line opt-outs use `// webpieces-disable <rule> -- reason`.
|
|
|
114
114
|
## Starter rules
|
|
115
115
|
|
|
116
116
|
- `no-any` — disallow the `any` keyword
|
|
117
|
-
- `max-file-lines` — cap file length
|
|
117
|
+
- `max-file-lines` — cap file length (machine-generated trees — `**/__generated__/**`, `**/generated/**`,
|
|
118
|
+
`**/*.generated.ts(x)`, `dist` — are exempt with no configuration; `allowedPaths` adds your own
|
|
119
|
+
un-authored trees to that list, and is never for hand-written code)
|
|
118
120
|
- `file-location` — every `.ts` must belong to a project's `src/`
|
|
119
121
|
- `no-destructure` — use explicit property access
|
|
120
122
|
- `require-return-type` — every function declares its return type
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/ai-hook-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.717",
|
|
4
4
|
"description": "Pluggable write-time validation framework for AI coding agents (@webpieces/ai-hook-rules). Claude Code PreToolUse + openclaw before_tool_call adapters share one rule engine.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"directory": "packages/tooling/ai-hook-rules"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@webpieces/rules-config": "0.4.
|
|
28
|
+
"@webpieces/rules-config": "0.4.717",
|
|
29
29
|
"inversify": "7.10.4",
|
|
30
30
|
"reflect-metadata": "0.2.2"
|
|
31
31
|
},
|
|
@@ -11,12 +11,18 @@ class MaxFileLinesRule extends rule_base_1.FileRuleBase {
|
|
|
11
11
|
constructor(config) { super(config, 'max-file-lines', 'max-file-lines'); }
|
|
12
12
|
description = 'Cap file length at a configured line limit.';
|
|
13
13
|
files = ['**/*.ts', '**/*.tsx'];
|
|
14
|
-
defaultOptions = { limit: DEFAULT_LIMIT };
|
|
14
|
+
defaultOptions = { limit: DEFAULT_LIMIT, allowedPaths: [] };
|
|
15
15
|
get fixHint() {
|
|
16
|
-
return new fix_hint_1.FixHint('File exceeds the max-file-lines limit.', '
|
|
16
|
+
return new fix_hint_1.FixHint('File exceeds the max-file-lines limit.', 'Pick one:', [
|
|
17
|
+
new rules_config_1.Option('Refactor to reduce the file size — READ the instruct-ai doc at the absolute path on the violation line above.', true),
|
|
18
|
+
new rules_config_1.Option('If this file is MACHINE-GENERATED and its size is not yours to control, add its tree to max-file-lines.allowedPaths in webpieces.config.json (the generated trees in GENERATED_CODE_PATHS are already exempt with no config at all). Never do this for hand-written code.'),
|
|
19
|
+
], new fix_hint_1.DisableEscape(this.config.disableAllowed ?? true, '// eslint-disable-next-line @webpieces/max-file-lines (also suppresses the eslint rule)'));
|
|
17
20
|
}
|
|
18
21
|
check(ctx) {
|
|
19
22
|
const limit = this.config.limit ?? DEFAULT_LIMIT;
|
|
23
|
+
// Machine-generated trees are exempt unconditionally; allowedPaths ADDS to that floor.
|
|
24
|
+
if ((0, rules_config_1.isPathExcluded)(ctx.relativePath, [...rules_config_1.GENERATED_CODE_PATHS, ...(this.config.allowedPaths ?? [])]))
|
|
25
|
+
return [];
|
|
20
26
|
if (ctx.projectedFileLines <= limit)
|
|
21
27
|
return [];
|
|
22
28
|
(0, rules_config_1.writeTemplateIfMissing)(ctx.workspaceRoot, INSTRUCT_FILE);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"max-file-lines.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/max-file-lines.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"max-file-lines.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/ai-hook-rules/src/core/rules/max-file-lines.ts"],"names":[],"mappings":";;;A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E,aAAa,CAAC,CAAC;QACzF,OAAO,CAAC,IAAI,iBAAC,CACT,CAAC,EACD,cAAc,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,SAAS,EACrD,gBAAgB,MAAM,CAAC,GAAG,CAAC,kBAAkB,CAAC,yBAAyB,MAAM,CAAC,KAAK,CAAC,qBAAqB,OAAO,yCAAyC,CAC5J,CAAC,CAAC;IACP,CAAC;CACJ;AA/BD,4CA+BC","sourcesContent":["import { MaxFileLinesConfig, writeTemplateIfMissing, RepoRootFinder, isPathExcluded, GENERATED_CODE_PATHS, Option } from '@webpieces/rules-config';\n\nimport type { FileContext, Violation } from '../types';\nimport { Violation as V } from '../types';\nimport { FileRuleBase } from '../rule-base';\nimport { FixHint, DisableEscape } from '../fix-hint';\n\nconst DEFAULT_LIMIT = 900;\nconst INSTRUCT_FILE = 'webpieces.filesize.md';\n\nexport class MaxFileLinesRule extends FileRuleBase<MaxFileLinesConfig> {\n constructor(config: MaxFileLinesConfig) { super(config, 'max-file-lines', 'max-file-lines'); }\n\n readonly description = 'Cap file length at a configured line limit.';\n override readonly files = ['**/*.ts', '**/*.tsx'];\n override readonly defaultOptions = { limit: DEFAULT_LIMIT, allowedPaths: [] };\n get fixHint(): FixHint {\n return new FixHint(\n 'File exceeds the max-file-lines limit.',\n 'Pick one:',\n [\n new Option('Refactor to reduce the file size — READ the instruct-ai doc at the absolute path on the violation line above.', true),\n new Option('If this file is MACHINE-GENERATED and its size is not yours to control, add its tree to max-file-lines.allowedPaths in webpieces.config.json (the generated trees in GENERATED_CODE_PATHS are already exempt with no config at all). Never do this for hand-written code.'),\n ],\n new DisableEscape(this.config.disableAllowed ?? true, '// eslint-disable-next-line @webpieces/max-file-lines (also suppresses the eslint rule)'),\n );\n }\n\n check(ctx: FileContext): readonly Violation[] {\n const limit = this.config.limit ?? DEFAULT_LIMIT;\n // Machine-generated trees are exempt unconditionally; allowedPaths ADDS to that floor.\n if (isPathExcluded(ctx.relativePath, [...GENERATED_CODE_PATHS, ...(this.config.allowedPaths ?? [])])) return [];\n if (ctx.projectedFileLines <= limit) return [];\n writeTemplateIfMissing(ctx.workspaceRoot, INSTRUCT_FILE);\n const docPath = new RepoRootFinder().instructAiDocPath(ctx.workspaceRoot, INSTRUCT_FILE);\n return [new V(\n 1,\n `(projected ${String(ctx.projectedFileLines)} lines)`,\n `File will be ${String(ctx.projectedFileLines)} lines, exceeding the ${String(limit)}-line limit. READ ${docPath} for detailed refactoring instructions.`,\n )];\n }\n}\n"]}
|