@interlace/eslint-devkit 1.16.0 → 1.16.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interlace/eslint-devkit",
3
- "version": "1.16.0",
3
+ "version": "1.16.1",
4
4
  "description": "Toolkit for building ESLint plugins in TypeScript — AST helpers, type utilities, rule-creation scaffolding, security benchmarks, and SARIF output.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * Whole-word membership tests over an identifier's segments.
8
+ *
9
+ * WHY THIS EXISTS
10
+ *
11
+ * Seven rules independently wrote `haystack.includes(word)` against a
12
+ * vocabulary, and every one of them shipped the same false positives, because
13
+ * English words contain other English words:
14
+ *
15
+ * passengers contains pass → "Password length requirement is too weak"
16
+ * microphoneEnabled contains phone → "PII in console logs"
17
+ * casserole contains role → "Authentication logic in client code"
18
+ * contractAddress contains address → "Sensitive field sent to analytics"
19
+ * promoteOffer contains promote → "Privilege escalation"
20
+ * midnight contains dn → "LDAP injection"
21
+ * sessionStorageKey contains session → "Hardcoded session token"
22
+ *
23
+ * Those are not hypotheticals. Each was produced by running the shipped rule
24
+ * against the snippet above, and `no-client-side-auth-logic` — the `casserole`
25
+ * one — is in `browser-security/recommended` at `error`, so it reached every
26
+ * consumer of the preset.
27
+ *
28
+ * WHAT THIS DOES AND DOES NOT LICENSE
29
+ *
30
+ * Matching a name by whole word is still matching a NAME. CLAUDE.md permits it
31
+ * only where the name NARROWS evidence the rule has already proven — a resolved
32
+ * sink, a resolved taint root, a specific call shape — and never as the whole
33
+ * verdict. Swapping `includes()` for this helper fixes the false-positive half
34
+ * of that defect; it does nothing for the false-negative half, where renaming a
35
+ * genuinely tainted variable silences a real finding. That half needs binding
36
+ * resolution, not better string matching.
37
+ *
38
+ * In other words: this makes a permitted pattern correct. It does not make a
39
+ * forbidden pattern permitted.
40
+ */
41
+ /**
42
+ * Split an identifier into lower-cased words.
43
+ *
44
+ * Handles camelCase, PascalCase, snake_case, kebab-case, SCREAMING_SNAKE, and
45
+ * the acronym boundary (`parseXMLDocument` → `parse`, `xml`, `document`), which
46
+ * a naive `/(?=[A-Z])/` split gets wrong by producing `x`, `m`, `l`.
47
+ */
48
+ export declare function identifierWords(name: string): string[];
49
+ /**
50
+ * Does `name` contain `term` as a whole word (or whole consecutive phrase)?
51
+ *
52
+ * A multi-word term matches a consecutive run of segments, so `'access token'`,
53
+ * `'accessToken'` and `'access_token'` all match the identifier `accessToken`
54
+ * and none of them match `accessTokenizerFactory`... but `'token'` DOES match
55
+ * `accessToken`, because `token` is a whole segment there. That is the intended
56
+ * behaviour: segment-level membership, not substring, not full-name equality.
57
+ */
58
+ export declare function nameHasWord(name: string, term: string): boolean;
59
+ /** Does `name` contain ANY term in `vocabulary` as a whole word? */
60
+ export declare function nameHasAnyWord(name: string, vocabulary: Iterable<string>): boolean;
61
+ /** The terms that matched, for a report's `data` — so a message can say WHICH word it saw. */
62
+ export declare function matchedWords(name: string, vocabulary: Iterable<string>): string[];
Binary file
@@ -6,3 +6,6 @@
6
6
  export * from '../ast/ast-utils';
7
7
  export * from './static-expression';
8
8
  export * from './module-binding';
9
+ export * from './identifier-words';
10
+ export * from './type-syntax';
11
+ export * from './user-regex';
package/src/ast/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});__exportStar(require("../ast/ast-utils"),exports);__exportStar(require("./static-expression"),exports);__exportStar(require("./module-binding"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});__exportStar(require("../ast/ast-utils"),exports);__exportStar(require("./static-expression"),exports);__exportStar(require("./module-binding"),exports);__exportStar(require("./identifier-words"),exports);__exportStar(require("./type-syntax"),exports);__exportStar(require("./user-regex"),exports);
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * Strip TypeScript-only expression wrappers before analysing a value.
8
+ *
9
+ * WHY THIS EXISTS
10
+ *
11
+ * Every taint walker in this repo dispatches on `node.type` and falls through to
12
+ * `return null` / `return false` for anything it does not recognise. None of them
13
+ * had an arm for `TSAsExpression`. That single omission silences the rules on the
14
+ * shape TypeScript users are FORCED to write:
15
+ *
16
+ * app.get('/s', (req, res) => {
17
+ * new RegExp(req.query.q as string, 'i'); // QUIET — the cast hid the taint
18
+ * new RegExp(req.query.q, 'i'); // reports
19
+ * });
20
+ *
21
+ * The cast is not stylistic. In Express's own types `req.query.q` is
22
+ * `string | string[] | ParsedQs | undefined`, so a TS codebase CANNOT pass it
23
+ * where a string is expected without `as string` (or `!`, or `String(...)`).
24
+ * The practical effect is that the affected rules never fire on TypeScript
25
+ * Express code at all — which is most of the audience these plugins are aimed at.
26
+ *
27
+ * Confirmed across no-ssrf, no-timing-unsafe-compare, no-sql-injection,
28
+ * no-template-injection, no-unsafe-deserialization, no-unsafe-regex-construction
29
+ * and no-unchecked-loop-condition. `grep -c 'as string' *.test.ts` returned ZERO
30
+ * for all of them: no test in any of those suites is written in the dialect their
31
+ * users write, which is exactly why the gap survived every review.
32
+ *
33
+ * These wrappers are erased at compile time and change no runtime value, so
34
+ * unwrapping is always sound for provenance: `x as string` reads exactly what
35
+ * `x` reads.
36
+ */
37
+ import type { TSESTree } from '@typescript-eslint/utils';
38
+ /**
39
+ * Return the innermost expression, stripping every type-only wrapper.
40
+ *
41
+ * Nesting is real in the wild — `(req.query.q as string)!` — so this loops
42
+ * rather than unwrapping once. `undefined` in, `undefined` out, so it can be
43
+ * dropped into an optional-chained walk without a guard.
44
+ */
45
+ export declare function unwrapTypeSyntax<T extends TSESTree.Node | null | undefined>(node: T): T extends null | undefined ? T : TSESTree.Node;
46
+ /** Is this node a type-only wrapper that `unwrapTypeSyntax` would strip? */
47
+ export declare function isTypeSyntaxWrapper(node: TSESTree.Node | null | undefined): boolean;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.unwrapTypeSyntax=unwrapTypeSyntax;exports.isTypeSyntaxWrapper=isTypeSyntaxWrapper;const ast_node_types_1=require("../ast-node-types");const TYPE_ONLY_WRAPPERS=new Set([ast_node_types_1.AST_NODE_TYPES.TSAsExpression,ast_node_types_1.AST_NODE_TYPES.TSNonNullExpression,ast_node_types_1.AST_NODE_TYPES.TSSatisfiesExpression,ast_node_types_1.AST_NODE_TYPES.TSTypeAssertion,ast_node_types_1.AST_NODE_TYPES.TSInstantiationExpression]);function unwrapTypeSyntax(node){let current=node;while(current&&TYPE_ONLY_WRAPPERS.has(current.type)){const inner=current.expression;if(!inner)break;current=inner}return current}function isTypeSyntaxWrapper(node){return node!==null&&node!==void 0&&TYPE_ONLY_WRAPPERS.has(node.type)}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Copyright (c) 2025 Ofri Peretz
3
+ * Licensed under the MIT License. Use of this source code is governed by the
4
+ * MIT license that can be found in the LICENSE file.
5
+ */
6
+ /**
7
+ * Compile a regex that came from a USER'S CONFIG, without handing them a way to
8
+ * crash or hang their own lint run.
9
+ *
10
+ * WHY THIS EXISTS
11
+ *
12
+ * Six rules accept regex options (`ignorePatterns`, `secretPatterns`,
13
+ * `userInputPatterns`, `testFilePattern`) and passed them straight to
14
+ * `new RegExp(...)`. Measured, not theorised:
15
+ *
16
+ * ignorePatterns: ['(a+)+$'] against a 30-char subject
17
+ * → 54.9s in no-hardcoded-credentials (control: 1.21s)
18
+ * → 58.2s in no-missing-authentication (control: 1.65s)
19
+ * → 47.5s in no-timing-unsafe-compare (control: 1.40s)
20
+ * Timings scale 1.0 / 70 / 901 / 14045 / 62215 ms at n = 20/24/28/30/32.
21
+ * Textbook exponential backtracking.
22
+ *
23
+ * ignorePatterns: ['[']
24
+ * → "Invalid regular expression: /[/: Unterminated character class",
25
+ * thrown out of create(). The WHOLE lint run dies, not just the rule.
26
+ *
27
+ * A user misconfiguring one option should degrade that option, never take down
28
+ * the process. Three of the six rules already caught the throw and fell back to
29
+ * a substring match; this makes the other three consistent and adds the
30
+ * backtracking guard none of them had.
31
+ *
32
+ * WHAT THIS DOES NOT DO
33
+ *
34
+ * `looksCatastrophic` is a HEURISTIC over the pattern's shape — nested
35
+ * quantifiers and quantified alternations with overlapping branches. It is not
36
+ * a decision procedure; a determined pattern can evade it, and some safe
37
+ * patterns will be refused. That trade is deliberate: the cost of a false
38
+ * refusal is one option falling back to substring matching, and the cost of a
39
+ * miss is a 60-second hang on every file. If exactness is ever needed, this
40
+ * repo already ships a real automaton analysis in `no-redos-vulnerable-regex`.
41
+ */
42
+ /**
43
+ * The minimal shape a pattern test needs.
44
+ *
45
+ * `RegExp` satisfies this structurally, so a call site can migrate from
46
+ * `RegExp[]` to `PatternTest[]` without touching its callers — which is the
47
+ * whole reason the guarded matcher is shaped like a RegExp.
48
+ */
49
+ export interface PatternTest {
50
+ test(input: string): boolean;
51
+ }
52
+ /** A compiled matcher. Always safe to call; never throws. */
53
+ export interface UserMatcher extends PatternTest {
54
+ /** How the pattern was handled, so a rule can explain itself to the user. */
55
+ readonly mode: 'regex' | 'literal-invalid' | 'literal-catastrophic';
56
+ readonly source: string;
57
+ }
58
+ /**
59
+ * Compile one user-supplied pattern.
60
+ *
61
+ * Never throws. An invalid or dangerous pattern degrades to a case-insensitive
62
+ * substring test, which is what a user writing a plain name like `apiKey` almost
63
+ * always meant anyway.
64
+ */
65
+ export declare function compileUserPattern(pattern: string, flags?: string): UserMatcher;
66
+ /** Compile a list of user patterns. */
67
+ export declare function compileUserPatterns(patterns: readonly string[], flags?: string): UserMatcher[];
68
+ /** Does any compiled pattern match? The common call shape at every site. */
69
+ export declare function matchesAnyUserPattern(matchers: readonly UserMatcher[], input: string): boolean;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.compileUserPattern=compileUserPattern;exports.compileUserPatterns=compileUserPatterns;exports.matchesAnyUserPattern=matchesAnyUserPattern;function looksCatastrophic(pattern){if(/\([^()+*}]*[+*}][^()]*\)\s*[+*]/.test(pattern))return true;if(/\([^()|]*\|[^()]*\)\s*[+*]/.test(pattern))return true;if(/\)[+*]\s*\([^()]*\)[+*]/.test(pattern))return true;return false}function literalMatcher(pattern,mode){const needle=pattern.toLowerCase();return{test:input=>input.toLowerCase().includes(needle),mode,source:pattern}}function compileUserPattern(pattern,flags=""){if(looksCatastrophic(pattern))return literalMatcher(pattern,"literal-catastrophic");try{const regex=new RegExp(pattern,flags);return{test:input=>{regex.lastIndex=0;return regex.test(input)},mode:"regex",source:pattern}}catch{return literalMatcher(pattern,"literal-invalid")}}function compileUserPatterns(patterns,flags=""){return patterns.map(p=>compileUserPattern(p,flags))}function matchesAnyUserPattern(matchers,input){return matchers.some(m=>m.test(input))}
package/src/index.d.ts CHANGED
@@ -23,6 +23,9 @@ export * from './rule-creation';
23
23
  export * from './ast/ast-utils';
24
24
  export * from './ast/module-binding';
25
25
  export * from './ast/static-expression';
26
+ export * from './ast/identifier-words';
27
+ export * from './ast/type-syntax';
28
+ export * from './ast/user-regex';
26
29
  export * from './types/type-utils';
27
30
  export * from './messaging';
28
31
  export * from './security';
package/src/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});exports.ESLintUtils=exports.AST_NODE_TYPES=exports.toSARIF=exports.severityToCVSS=exports.getSecurityBenchmarks=exports.MessageIcons=exports.OWASP_2021_TO_2025=exports.OWASP_SERVERLESS_DETAILS=exports.OWASP_2021_DETAILS=exports.OWASP_2025_DETAILS=exports.OWASP_DETAILS=exports.CWE_COMPLIANCE_MAPPING=exports.CWE_MAPPING=exports.CVSS_RANGES=void 0;require("./types/meta-augmentation");__exportStar(require("./rule-creation"),exports);__exportStar(require("./ast/ast-utils"),exports);__exportStar(require("./ast/module-binding"),exports);__exportStar(require("./ast/static-expression"),exports);__exportStar(require("./types/type-utils"),exports);__exportStar(require("./messaging"),exports);__exportStar(require("./security"),exports);__exportStar(require("./node"),exports);__exportStar(require("./resolver"),exports);__exportStar(require("./aria-definitions"),exports);var messaging_1=require("./messaging");Object.defineProperty(exports,"CVSS_RANGES",{enumerable:true,get:function(){return messaging_1.CVSS_RANGES}});Object.defineProperty(exports,"CWE_MAPPING",{enumerable:true,get:function(){return messaging_1.CWE_MAPPING}});Object.defineProperty(exports,"CWE_COMPLIANCE_MAPPING",{enumerable:true,get:function(){return messaging_1.CWE_COMPLIANCE_MAPPING}});Object.defineProperty(exports,"OWASP_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_DETAILS}});Object.defineProperty(exports,"OWASP_2025_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_2025_DETAILS}});Object.defineProperty(exports,"OWASP_2021_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_2021_DETAILS}});Object.defineProperty(exports,"OWASP_SERVERLESS_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_SERVERLESS_DETAILS}});Object.defineProperty(exports,"OWASP_2021_TO_2025",{enumerable:true,get:function(){return messaging_1.OWASP_2021_TO_2025}});Object.defineProperty(exports,"MessageIcons",{enumerable:true,get:function(){return messaging_1.MessageIcons}});Object.defineProperty(exports,"getSecurityBenchmarks",{enumerable:true,get:function(){return messaging_1.getSecurityBenchmarks}});Object.defineProperty(exports,"severityToCVSS",{enumerable:true,get:function(){return messaging_1.severityToCVSS}});Object.defineProperty(exports,"toSARIF",{enumerable:true,get:function(){return messaging_1.toSARIF}});var ast_node_types_1=require("./ast-node-types");Object.defineProperty(exports,"AST_NODE_TYPES",{enumerable:true,get:function(){return ast_node_types_1.AST_NODE_TYPES}});var rule_creator_1=require("./rule-creation/rule-creator");Object.defineProperty(exports,"ESLintUtils",{enumerable:true,get:function(){return rule_creator_1.ESLintUtils}});
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(o,m,k,k2){if(k2===void 0)k2=k;var desc=Object.getOwnPropertyDescriptor(m,k);if(!desc||("get"in desc?!m.__esModule:desc.writable||desc.configurable)){desc={enumerable:true,get:function(){return m[k]}}}Object.defineProperty(o,k2,desc)}):(function(o,m,k,k2){if(k2===void 0)k2=k;o[k2]=m[k]}));var __exportStar=this&&this.__exportStar||function(m,exports2){for(var p in m)if(p!=="default"&&!Object.prototype.hasOwnProperty.call(exports2,p))__createBinding(exports2,m,p)};Object.defineProperty(exports,"__esModule",{value:true});exports.ESLintUtils=exports.AST_NODE_TYPES=exports.toSARIF=exports.severityToCVSS=exports.getSecurityBenchmarks=exports.MessageIcons=exports.OWASP_2021_TO_2025=exports.OWASP_SERVERLESS_DETAILS=exports.OWASP_2021_DETAILS=exports.OWASP_2025_DETAILS=exports.OWASP_DETAILS=exports.CWE_COMPLIANCE_MAPPING=exports.CWE_MAPPING=exports.CVSS_RANGES=void 0;require("./types/meta-augmentation");__exportStar(require("./rule-creation"),exports);__exportStar(require("./ast/ast-utils"),exports);__exportStar(require("./ast/module-binding"),exports);__exportStar(require("./ast/static-expression"),exports);__exportStar(require("./ast/identifier-words"),exports);__exportStar(require("./ast/type-syntax"),exports);__exportStar(require("./ast/user-regex"),exports);__exportStar(require("./types/type-utils"),exports);__exportStar(require("./messaging"),exports);__exportStar(require("./security"),exports);__exportStar(require("./node"),exports);__exportStar(require("./resolver"),exports);__exportStar(require("./aria-definitions"),exports);var messaging_1=require("./messaging");Object.defineProperty(exports,"CVSS_RANGES",{enumerable:true,get:function(){return messaging_1.CVSS_RANGES}});Object.defineProperty(exports,"CWE_MAPPING",{enumerable:true,get:function(){return messaging_1.CWE_MAPPING}});Object.defineProperty(exports,"CWE_COMPLIANCE_MAPPING",{enumerable:true,get:function(){return messaging_1.CWE_COMPLIANCE_MAPPING}});Object.defineProperty(exports,"OWASP_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_DETAILS}});Object.defineProperty(exports,"OWASP_2025_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_2025_DETAILS}});Object.defineProperty(exports,"OWASP_2021_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_2021_DETAILS}});Object.defineProperty(exports,"OWASP_SERVERLESS_DETAILS",{enumerable:true,get:function(){return messaging_1.OWASP_SERVERLESS_DETAILS}});Object.defineProperty(exports,"OWASP_2021_TO_2025",{enumerable:true,get:function(){return messaging_1.OWASP_2021_TO_2025}});Object.defineProperty(exports,"MessageIcons",{enumerable:true,get:function(){return messaging_1.MessageIcons}});Object.defineProperty(exports,"getSecurityBenchmarks",{enumerable:true,get:function(){return messaging_1.getSecurityBenchmarks}});Object.defineProperty(exports,"severityToCVSS",{enumerable:true,get:function(){return messaging_1.severityToCVSS}});Object.defineProperty(exports,"toSARIF",{enumerable:true,get:function(){return messaging_1.toSARIF}});var ast_node_types_1=require("./ast-node-types");Object.defineProperty(exports,"AST_NODE_TYPES",{enumerable:true,get:function(){return ast_node_types_1.AST_NODE_TYPES}});var rule_creator_1=require("./rule-creation/rule-creator");Object.defineProperty(exports,"ESLintUtils",{enumerable:true,get:function(){return rule_creator_1.ESLintUtils}});
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createWithMockContext=createWithMockContext;function createWithMockContext(rule,opts={}){const reports=[];const filename=opts.filename??"mock.ts";const emptyScope={variables:[],references:[],childScopes:[]};const sourceCode={ast:opts.ast??{type:"Program",body:[],tokens:[],comments:[]},text:opts.sourceText??"",getText:()=>opts.sourceText??"",getScope:()=>opts.scope??emptyScope,getAncestors:()=>[],getCommentsBefore:()=>[],getDeclaredVariables:()=>[]};const context={id:"mock-rule",filename,physicalFilename:filename,cwd:"/",options:opts.options??rule.defaultOptions??[],settings:opts.settings??{},parserOptions:{},languageOptions:{},sourceCode,getFilename:()=>filename,getPhysicalFilename:()=>filename,getCwd:()=>"/",getSourceCode:()=>sourceCode,getScope:()=>opts.scope??emptyScope,getAncestors:()=>[],report:descriptor=>{reports.push(descriptor)}};const listeners=rule.create(context);return{listeners,reports,context}}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createWithMockContext=createWithMockContext;function createWithMockContext(rule,opts={}){const reports=[];const filename=opts.filename??"mock.ts";const emptyScope={variables:[],references:[],childScopes:[],set:new Map,upper:null};const sourceCode={ast:opts.ast??{type:"Program",body:[],tokens:[],comments:[]},text:opts.sourceText??"",getText:()=>opts.sourceText??"",getScope:()=>opts.scope??emptyScope,getAncestors:()=>[],getCommentsBefore:()=>[],getDeclaredVariables:()=>[]};const context={id:"mock-rule",filename,physicalFilename:filename,cwd:"/",options:opts.options??rule.defaultOptions??[],settings:opts.settings??{},parserOptions:{},languageOptions:{},sourceCode,getFilename:()=>filename,getPhysicalFilename:()=>filename,getCwd:()=>"/",getSourceCode:()=>sourceCode,getScope:()=>opts.scope??emptyScope,getAncestors:()=>[],report:descriptor=>{reports.push(descriptor)}};const listeners=rule.create(context);return{listeners,reports,context}}
@@ -39,6 +39,20 @@ export type NamedCreateRuleMeta<MessageIds extends string, PluginDocs = unknown,
39
39
  export interface RuleCreateAndOptions<Options extends readonly unknown[], MessageIds extends string> {
40
40
  create: (context: Readonly<TSESLint.RuleContext<MessageIds, Options>>, optionsWithDefault: Readonly<Options>) => TSESLint.RuleListener;
41
41
  defaultOptions?: Readonly<Options>;
42
+ /**
43
+ * BENCHMARK-CRITERIA.md §B1: "self-skips test files — by path and by filename
44
+ * (`*.spec.*`, `*.test.*`), **independent of the harness**".
45
+ *
46
+ * Opt-in rather than default-on, deliberately. Every plugin in this monorepo
47
+ * shares one `createRule`, so flipping the default would silently cut findings
48
+ * for consumers of all 19 published packages on a patch bump — and it would be
49
+ * wrong for the non-security plugins, where a naming or complexity rule
50
+ * *should* apply to a test file.
51
+ *
52
+ * Set it as each rule goes through the lock protocol, alongside the test that
53
+ * pins it.
54
+ */
55
+ skipTestFiles?: boolean;
42
56
  }
43
57
  export interface RuleWithMeta<Options extends readonly unknown[], MessageIds extends string, Docs = unknown> extends RuleCreateAndOptions<Options, MessageIds> {
44
58
  meta: TSESLint.RuleMetaData<MessageIds, Docs, Options>;
@@ -51,6 +65,7 @@ export interface RuleWithMetaAndName<Options extends readonly unknown[], Message
51
65
  export type RuleModuleWithName<MessageIds extends string, Options extends readonly unknown[] = [], Docs = unknown> = TSESLint.RuleModule<MessageIds, Options, Docs> & {
52
66
  name: string;
53
67
  };
68
+ export declare function isTestFilePath(filename: string): boolean;
54
69
  /**
55
70
  * Port of `ESLintUtils.RuleCreator`.
56
71
  *
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.docsUrlFor=exports.ESLintUtils=exports.createRule=void 0;exports.applyDefault=applyDefault;exports.RuleCreator=RuleCreator;exports.createRuleCreator=createRuleCreator;exports.withCanonicalDocsUrls=withCanonicalDocsUrls;function isObjectNotArray(obj){return typeof obj==="object"&&obj!=null&&!Array.isArray(obj)}function deepMerge(first,second){const keys=new Set([...Object.keys(first),...Object.keys(second)]);return Object.fromEntries([...keys].map(key=>{const firstHasKey=key in first;const secondHasKey=key in second;const firstValue=first[key];const secondValue=second[key];if(firstHasKey&&secondHasKey){return[key,isObjectNotArray(firstValue)&&isObjectNotArray(secondValue)?deepMerge(firstValue,secondValue):secondValue]}return[key,firstHasKey?firstValue:secondValue]}))}function applyDefault(defaultOptions,userOptions){const options=structuredClone(defaultOptions);if(userOptions==null){return options}options.forEach((opt,i)=>{if(userOptions[i]!==void 0){const userOpt=userOptions[i];options[i]=isObjectNotArray(userOpt)&&isObjectNotArray(opt)?deepMerge(opt,userOpt):userOpt}});return options}function createRuleInternal({create,defaultOptions,meta,name}){const resolvedDefaultOptions=defaultOptions??[];return{create(context){return create(context,applyDefault(resolvedDefaultOptions,context.options))},defaultOptions:resolvedDefaultOptions,meta,name}}function RuleCreator(urlCreator){return({meta,name,...rule})=>createRuleInternal({meta:{...meta,docs:{...meta.docs,url:urlCreator(name)}},name,...rule})}RuleCreator.withoutDocs=args=>createRuleInternal(args);function createRuleCreator(urlCreator){return RuleCreator(urlCreator)}exports.createRule=RuleCreator(name=>`https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin/docs/rules/${name}.md`);exports.ESLintUtils={RuleCreator,applyDefault};const docsUrlFor=(pluginSlug,ruleName)=>`https://eslint.interlace.tools/docs/security/${pluginSlug}/rules/${ruleName}`;exports.docsUrlFor=docsUrlFor;function withCanonicalDocsUrls(pluginSlug,rules){for(const name of Object.keys(rules)){const descriptor=Object.getOwnPropertyDescriptor(rules,name);const{get}=descriptor;if(get){Object.defineProperty(rules,name,{...descriptor,get(){const rule=get.call(this);stampDocsUrl(pluginSlug,name,rule);return rule}});continue}stampDocsUrl(pluginSlug,name,descriptor.value)}return rules}function stampDocsUrl(pluginSlug,name,rule){const docs=rule?.meta?.docs;if(docs)docs.url=(0,exports.docsUrlFor)(pluginSlug,name)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.docsUrlFor=exports.ESLintUtils=exports.createRule=void 0;exports.applyDefault=applyDefault;exports.isTestFilePath=isTestFilePath;exports.RuleCreator=RuleCreator;exports.createRuleCreator=createRuleCreator;exports.withCanonicalDocsUrls=withCanonicalDocsUrls;function isObjectNotArray(obj){return typeof obj==="object"&&obj!=null&&!Array.isArray(obj)}function deepMerge(first,second){const keys=new Set([...Object.keys(first),...Object.keys(second)]);return Object.fromEntries([...keys].map(key=>{const firstHasKey=key in first;const secondHasKey=key in second;const firstValue=first[key];const secondValue=second[key];if(firstHasKey&&secondHasKey){return[key,isObjectNotArray(firstValue)&&isObjectNotArray(secondValue)?deepMerge(firstValue,secondValue):secondValue]}return[key,firstHasKey?firstValue:secondValue]}))}function applyDefault(defaultOptions,userOptions){const options=structuredClone(defaultOptions);if(userOptions==null){return options}options.forEach((opt,i)=>{if(userOptions[i]!==void 0){const userOpt=userOptions[i];options[i]=isObjectNotArray(userOpt)&&isObjectNotArray(opt)?deepMerge(opt,userOpt):userOpt}});return options}const TEST_DIR_SEGMENTS=new Set(["__tests__","__test__","test","tests","spec","specs","e2e","__mocks__","mocks","fixtures","__fixtures__"]);const TEST_BASENAME=/\.(test|spec|fixture|mock|e2e-spec)\.[cm]?[jt]sx?$/;function isTestFilePath(filename){if(!filename||filename==="<input>"||filename==="<text>")return false;const slash=Math.max(filename.lastIndexOf("/"),filename.lastIndexOf("\\"));if(TEST_BASENAME.test(filename.slice(slash+1)))return true;if(slash<0)return false;return filename.slice(0,slash).split(/[\\/]/).some(segment=>TEST_DIR_SEGMENTS.has(segment))}function createRuleInternal({create,defaultOptions,meta,name,skipTestFiles}){const resolvedDefaultOptions=defaultOptions??[];return{create(context){if(skipTestFiles&&isTestFilePath(context.filename))return{};return create(context,applyDefault(resolvedDefaultOptions,context.options))},defaultOptions:resolvedDefaultOptions,meta,name}}function RuleCreator(urlCreator){return({meta,name,...rule})=>createRuleInternal({meta:{...meta,docs:{...meta.docs,url:urlCreator(name)}},name,...rule})}RuleCreator.withoutDocs=args=>createRuleInternal(args);function createRuleCreator(urlCreator){return RuleCreator(urlCreator)}exports.createRule=RuleCreator(name=>`https://github.com/ofri-peretz/eslint/blob/main/packages/eslint-plugin/docs/rules/${name}.md`);exports.ESLintUtils={RuleCreator,applyDefault};const docsUrlFor=(pluginSlug,ruleName)=>`https://eslint.interlace.tools/docs/security/${pluginSlug}/rules/${ruleName}`;exports.docsUrlFor=docsUrlFor;function withCanonicalDocsUrls(pluginSlug,rules){for(const name of Object.keys(rules)){const descriptor=Object.getOwnPropertyDescriptor(rules,name);const{get}=descriptor;if(get){Object.defineProperty(rules,name,{...descriptor,get(){const rule=get.call(this);stampDocsUrl(pluginSlug,name,rule);return rule}});continue}stampDocsUrl(pluginSlug,name,descriptor.value)}return rules}function stampDocsUrl(pluginSlug,name,rule){const docs=rule?.meta?.docs;if(docs)docs.url=(0,exports.docsUrlFor)(pluginSlug,name)}