@gobing-ai/ts-rule-engine 0.2.8 → 0.3.0
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/dist/config/extensions.d.ts +5 -4
- package/dist/config/extensions.d.ts.map +1 -1
- package/dist/config/extensions.js +6 -5
- package/dist/config/loader.d.ts +10 -2
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +73 -19
- package/dist/engine.d.ts +8 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +9 -19
- package/dist/evaluators/coverage-gate-evaluator.js +12 -3
- package/dist/evaluators/file-utils.d.ts +55 -0
- package/dist/evaluators/file-utils.d.ts.map +1 -1
- package/dist/evaluators/file-utils.js +49 -0
- package/dist/evaluators/forbidden-import-evaluator.d.ts +5 -0
- package/dist/evaluators/forbidden-import-evaluator.d.ts.map +1 -1
- package/dist/evaluators/forbidden-import-evaluator.js +14 -17
- package/dist/evaluators/import-boundary-evaluator.d.ts +5 -0
- package/dist/evaluators/import-boundary-evaluator.d.ts.map +1 -1
- package/dist/evaluators/import-boundary-evaluator.js +45 -15
- package/dist/evaluators/regex-evaluator.d.ts +9 -1
- package/dist/evaluators/regex-evaluator.d.ts.map +1 -1
- package/dist/evaluators/regex-evaluator.js +43 -14
- package/dist/evaluators/secrets-scanner-evaluator.d.ts +5 -0
- package/dist/evaluators/secrets-scanner-evaluator.d.ts.map +1 -1
- package/dist/evaluators/secrets-scanner-evaluator.js +13 -13
- package/dist/evaluators/tsdoc-export-evaluator.d.ts.map +1 -1
- package/dist/evaluators/tsdoc-export-evaluator.js +9 -11
- package/dist/formatters/json.d.ts.map +1 -1
- package/dist/formatters/json.js +2 -0
- package/dist/formatters/text.d.ts.map +1 -1
- package/dist/formatters/text.js +2 -0
- package/dist/host/bundled-rules.d.ts +26 -0
- package/dist/host/bundled-rules.d.ts.map +1 -0
- package/dist/host/bundled-rules.js +76 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/resolvers/test-path-resolver.d.ts.map +1 -1
- package/dist/resolvers/test-path-resolver.js +5 -0
- package/dist/types.d.ts +22 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +35 -9
- package/package.json +6 -3
- package/rules/quality/coverage-gate.yaml +21 -0
- package/rules/recommended.yaml +10 -0
- package/rules/spur-dev.yaml +6 -0
- package/rules/structure/test-location.yaml +38 -0
- package/rules/typescript/no-biome-suppressions.yaml +23 -0
- package/rules/typescript/tsdoc-exports.yaml +24 -0
- package/schemas/preset.schema.json +19 -5
- package/src/config/extensions.ts +8 -7
- package/src/config/loader.ts +92 -21
- package/src/engine.ts +9 -19
- package/src/evaluators/coverage-gate-evaluator.ts +15 -5
- package/src/evaluators/file-utils.ts +92 -0
- package/src/evaluators/forbidden-import-evaluator.ts +14 -19
- package/src/evaluators/import-boundary-evaluator.ts +56 -40
- package/src/evaluators/regex-evaluator.ts +43 -13
- package/src/evaluators/secrets-scanner-evaluator.ts +13 -14
- package/src/evaluators/tsdoc-export-evaluator.ts +10 -9
- package/src/formatters/json.ts +2 -0
- package/src/formatters/text.ts +2 -0
- package/src/host/bundled-rules.ts +78 -0
- package/src/index.ts +1 -0
- package/src/resolvers/test-path-resolver.ts +5 -0
- package/src/types.ts +39 -9
package/src/types.ts
CHANGED
|
@@ -56,6 +56,8 @@ export interface ConstraintRuleFile {
|
|
|
56
56
|
severity?: RuleSeverity;
|
|
57
57
|
/** Rule definitions. */
|
|
58
58
|
rules: ConstraintRule[];
|
|
59
|
+
/** Custom capability modules contributed by this rule file (opt-in to load). */
|
|
60
|
+
extensions?: PresetExtensions;
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
/** Relative module paths a preset contributes per capability kind. */
|
|
@@ -198,7 +200,10 @@ export const ConstraintRuleSchema = z.object({
|
|
|
198
200
|
id: z.string().min(1),
|
|
199
201
|
description: z.string().default(''),
|
|
200
202
|
enabled: z.boolean().default(true),
|
|
201
|
-
|
|
203
|
+
// Severity is intentionally NOT defaulted here: an omitted rule severity must
|
|
204
|
+
// stay absent at parse time so the loader can apply the file-level default
|
|
205
|
+
// (`rule.severity ?? file.severity ?? 'error'`). Normalization always fills it.
|
|
206
|
+
severity: z.enum(['error', 'warning', 'info']).optional(),
|
|
202
207
|
evaluator: z.object({
|
|
203
208
|
type: z.string().min(1),
|
|
204
209
|
config: z.record(z.string(), z.unknown()).optional(),
|
|
@@ -208,6 +213,37 @@ export const ConstraintRuleSchema = z.object({
|
|
|
208
213
|
fix: RuleFixConfigSchema.optional(),
|
|
209
214
|
});
|
|
210
215
|
|
|
216
|
+
/**
|
|
217
|
+
* A relative module path a preset or rule file may load as an extension.
|
|
218
|
+
*
|
|
219
|
+
* Rejects absolute paths and `..` traversal: extension declarations are data, and a
|
|
220
|
+
* path that escapes the declaring file's directory is a trust-boundary violation even
|
|
221
|
+
* when extension loading is explicitly allowed.
|
|
222
|
+
*/
|
|
223
|
+
const relativeExtensionPath = z
|
|
224
|
+
.string()
|
|
225
|
+
.min(1)
|
|
226
|
+
.refine((value) => !/^([/\\]|[A-Za-z]:[/\\])/.test(value), {
|
|
227
|
+
message: 'extension path must be relative (no absolute paths)',
|
|
228
|
+
})
|
|
229
|
+
.refine((value) => !value.split(/[/\\]/).includes('..'), {
|
|
230
|
+
message: 'extension path must not contain ".." traversal',
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Shared zod schema for an `extensions` block, used by both preset and rule-file
|
|
235
|
+
* schemas so they validate identically. `.strict()` makes a typo'd or misplaced key
|
|
236
|
+
* a hard error rather than a silently-ignored field.
|
|
237
|
+
*/
|
|
238
|
+
export const ExtensionsSchema = z
|
|
239
|
+
.object({
|
|
240
|
+
resolvers: z.array(relativeExtensionPath).optional(),
|
|
241
|
+
evaluators: z.array(relativeExtensionPath).optional(),
|
|
242
|
+
fixers: z.array(relativeExtensionPath).optional(),
|
|
243
|
+
formatters: z.array(relativeExtensionPath).optional(),
|
|
244
|
+
})
|
|
245
|
+
.strict();
|
|
246
|
+
|
|
211
247
|
/** Zod schema for a constraint rule file. */
|
|
212
248
|
export const ConstraintRuleFileSchema = z.object({
|
|
213
249
|
$schema: z.string().optional(),
|
|
@@ -215,6 +251,7 @@ export const ConstraintRuleFileSchema = z.object({
|
|
|
215
251
|
exclude: z.array(z.string()).optional(),
|
|
216
252
|
severity: z.enum(['error', 'warning', 'info']).optional(),
|
|
217
253
|
rules: z.array(ConstraintRuleSchema),
|
|
254
|
+
extensions: ExtensionsSchema.optional(),
|
|
218
255
|
});
|
|
219
256
|
|
|
220
257
|
/** Zod schema for a preset definition. */
|
|
@@ -226,12 +263,5 @@ export const PresetDefinitionSchema = z.object({
|
|
|
226
263
|
overrides: z
|
|
227
264
|
.record(z.string(), z.object({ fix: z.object({ mode: z.enum(['none', 'suggest', 'auto']) }).optional() }))
|
|
228
265
|
.optional(),
|
|
229
|
-
extensions:
|
|
230
|
-
.object({
|
|
231
|
-
resolvers: z.array(z.string()).optional(),
|
|
232
|
-
evaluators: z.array(z.string()).optional(),
|
|
233
|
-
fixers: z.array(z.string()).optional(),
|
|
234
|
-
formatters: z.array(z.string()).optional(),
|
|
235
|
-
})
|
|
236
|
-
.optional(),
|
|
266
|
+
extensions: ExtensionsSchema.optional(),
|
|
237
267
|
});
|