@interlace/eslint-devkit 1.17.4 → 1.18.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/package.json +1 -1
- package/src/ast/index.d.ts +1 -0
- package/src/ast/index.js +1 -1
- package/src/ast/spellings.d.ts +113 -0
- package/src/ast/spellings.js +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.0",
|
|
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",
|
package/src/ast/index.d.ts
CHANGED
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);__exportStar(require("./identifier-words"),exports);__exportStar(require("./type-syntax"),exports);__exportStar(require("./user-regex"),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);__exportStar(require("./spellings"),exports);
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
* One thing, written several ways.
|
|
8
|
+
*
|
|
9
|
+
* JavaScript spells a constant string two ways and a property name three, and
|
|
10
|
+
* a rule that reads only the common spelling of each sees a strict subset of
|
|
11
|
+
* its own subject. That is not a judgement call the rule made — it is what
|
|
12
|
+
* `node.type === 'Literal'` means when the grammar also allows a template
|
|
13
|
+
* literal, and it is invisible in review because the test suite is written in
|
|
14
|
+
* the same spelling as the rule.
|
|
15
|
+
*
|
|
16
|
+
* Measured across this repository in 2026-08: 3,825 meaning-preserving
|
|
17
|
+
* rewrites of known true positives produced **1,156 cases where the rule
|
|
18
|
+
* reported the original and went silent on the rewrite**, across 163 of 470
|
|
19
|
+
* rules. Not one of them was a decision anybody made.
|
|
20
|
+
*
|
|
21
|
+
* The spellings that matter, and why each is not exotic:
|
|
22
|
+
*
|
|
23
|
+
* 'x' vs `x` a no-substitution template literal IS a string
|
|
24
|
+
* constant. Prettier leaves them, codegen emits them,
|
|
25
|
+
* and `String.raw` requires them.
|
|
26
|
+
* o.k vs o['k'] the same property. Minifiers, obfuscators and any
|
|
27
|
+
* key that is not a valid identifier use the second.
|
|
28
|
+
* {k:v} vs {['k']:v} the same declaration, and what a spread-with-
|
|
29
|
+
* conditional lowers to.
|
|
30
|
+
*
|
|
31
|
+
* Reach for these instead of matching a node type directly whenever the rule
|
|
32
|
+
* cares about WHICH string or WHICH property, not about how it was written.
|
|
33
|
+
* When a rule genuinely means "a quoted literal and nothing else", match the
|
|
34
|
+
* node type and say why in a comment — that is a position, and positions are
|
|
35
|
+
* fine. Silence by omission is not.
|
|
36
|
+
*/
|
|
37
|
+
import type { TSESTree, TSESLint } from '@typescript-eslint/utils';
|
|
38
|
+
/**
|
|
39
|
+
* The string a node names, in either spelling, or `null` if it does not name
|
|
40
|
+
* one statically.
|
|
41
|
+
*
|
|
42
|
+
* A template literal with expressions is deliberately `null`: `` `a${b}` ``
|
|
43
|
+
* has no single value, and guessing one is the data-flow question a
|
|
44
|
+
* type-unaware rule does not ask.
|
|
45
|
+
*/
|
|
46
|
+
export declare function staticString(node: TSESTree.Node | null | undefined): string | null;
|
|
47
|
+
/** Whether a node names this exact string, however it is spelled. */
|
|
48
|
+
export declare const isStaticString: (node: TSESTree.Node | null | undefined, value: string) => boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The property a member expression reads — `o.k`, `o['k']` and `` o[`k`] ``
|
|
51
|
+
* all return `'k'`.
|
|
52
|
+
*
|
|
53
|
+
* A computed key that is not a static string returns `null`: `o[k]` is decided
|
|
54
|
+
* at runtime, and which property it names is not a question the AST answers.
|
|
55
|
+
*/
|
|
56
|
+
export declare function propertyName(node: TSESTree.MemberExpression): string | null;
|
|
57
|
+
/**
|
|
58
|
+
* The key an object property declares — `{ k: v }`, `{ 'k': v }` and
|
|
59
|
+
* `{ ['k']: v }` all return `'k'`.
|
|
60
|
+
*
|
|
61
|
+
* Numeric keys come back as their source text, so `{ 200: v }` is `'200'` —
|
|
62
|
+
* `obj[200]` and `obj['200']` are the same property in JavaScript, and a rule
|
|
63
|
+
* matching on names should see them as one.
|
|
64
|
+
*/
|
|
65
|
+
export declare function objectKeyName(node: TSESTree.Property | TSESTree.MethodDefinition | TSESTree.PropertyDefinition): string | null;
|
|
66
|
+
/**
|
|
67
|
+
* The dotted path a member chain spells, root first, or `null` if any link is
|
|
68
|
+
* not statically nameable. `crypto['createHash']` and `crypto.createHash`
|
|
69
|
+
* both give `['crypto', 'createHash']`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function memberPath(node: TSESTree.Node): string[] | null;
|
|
72
|
+
/**
|
|
73
|
+
* Does this expression read caller-supplied data off a request?
|
|
74
|
+
*
|
|
75
|
+
* Decided from the SHAPE, not the receiver's name. Rules here matched
|
|
76
|
+
* `['req', 'request', 'ctx', 'event']` on the root identifier, so a codebase
|
|
77
|
+
* writing `(inbound, outbound) => …` — or the very common TypeScript
|
|
78
|
+
* `(request: Request, response: Response)` — got nothing at all from
|
|
79
|
+
* `no-sql-injection`, `no-ssrf` and `no-insecure-redirects`. Measured with
|
|
80
|
+
* `scripts/name-dependence-probe.mts`.
|
|
81
|
+
*
|
|
82
|
+
* The receiver must be a FUNCTION PARAMETER. That is what keeps `config.params`
|
|
83
|
+
* and `node.body` out: a request arrives as an argument, and a module-local
|
|
84
|
+
* object with a `.body` is somebody's own data structure. Requiring the
|
|
85
|
+
* parameter is a structural fact, and it is the part the old name test was
|
|
86
|
+
* standing in for.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* readsRequestShape(node, context.sourceCode); // inbound.query.id -> true
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export interface RequestShapeOptions {
|
|
94
|
+
/**
|
|
95
|
+
* Whether a bare `.body` needs a second level before it counts. Default
|
|
96
|
+
* `true`.
|
|
97
|
+
*
|
|
98
|
+
* `body` is both a request property and the commonest property name in this
|
|
99
|
+
* ecosystem — `node.body`, `response.body`, `message.body` — so at depth 1
|
|
100
|
+
* it is too ambiguous to act on, and every caller so far wanted the strict
|
|
101
|
+
* reading.
|
|
102
|
+
*
|
|
103
|
+
* A caller may turn it off when the POSITION already supplies the meaning.
|
|
104
|
+
* `db.collection('u').find(req.body)` is one: the whole request body used as
|
|
105
|
+
* a Mongo filter document is the canonical NoSQL authentication bypass
|
|
106
|
+
* (`{"$ne": null}` as a password matches every user), and nobody passes an
|
|
107
|
+
* arbitrary `.body` there by accident. See ILB-0121.
|
|
108
|
+
*/
|
|
109
|
+
bodyNeedsDepth?: boolean;
|
|
110
|
+
}
|
|
111
|
+
export declare function readsRequestShape(node: TSESTree.Node, sourceCode: {
|
|
112
|
+
getScope: (node: TSESTree.Node) => TSESLint.Scope.Scope;
|
|
113
|
+
}, options?: RequestShapeOptions): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.isStaticString=void 0;exports.staticString=staticString;exports.propertyName=propertyName;exports.objectKeyName=objectKeyName;exports.memberPath=memberPath;exports.readsRequestShape=readsRequestShape;const ast_node_types_1=require("../ast-node-types");function staticString(node){if(!node)return null;if(node.type===ast_node_types_1.AST_NODE_TYPES.Literal){return typeof node.value==="string"?node.value:null}if(node.type===ast_node_types_1.AST_NODE_TYPES.TemplateLiteral&&node.expressions.length===0){const[only]=node.quasis;return only.value.cooked}return null}const isStaticString=(node,value)=>staticString(node)===value;exports.isStaticString=isStaticString;function propertyName(node){if(!node.computed){return node.property.type===ast_node_types_1.AST_NODE_TYPES.Identifier?node.property.name:null}return staticString(node.property)}function objectKeyName(node){const key=node.key;if(!node.computed&&key.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return key.name;if(key.type===ast_node_types_1.AST_NODE_TYPES.Literal&&typeof key.value==="number")return String(key.value);return staticString(key)}function memberPath(node){if(node.type===ast_node_types_1.AST_NODE_TYPES.Identifier)return[node.name];if(node.type!==ast_node_types_1.AST_NODE_TYPES.MemberExpression)return null;const head=memberPath(node.object);if(head===null)return null;const tail=propertyName(node);return tail===null?null:[...head,tail]}const REQUEST_SHAPE=new Set(["query","params","headers","cookies","queryStringParameters","pathParameters","multiValueHeaders"]);const REQUEST_SHAPE_NEEDS_DEPTH=new Set(["body"]);function readsRequestShape(node,sourceCode,options={}){let current=node;let firstProperty=null;let secondProperty=null;let depth=0;while(current.type===ast_node_types_1.AST_NODE_TYPES.MemberExpression){const name=propertyName(current);if(name!==null){secondProperty=firstProperty;firstProperty=name}depth+=1;current=current.object}if(current.type!==ast_node_types_1.AST_NODE_TYPES.Identifier)return false;if(firstProperty===null)return false;if((firstProperty==="request"||firstProperty==="req")&&secondProperty!==null){firstProperty=secondProperty;depth-=1}const known=REQUEST_SHAPE.has(firstProperty);const needsDepth=REQUEST_SHAPE_NEEDS_DEPTH.has(firstProperty);if(!known&&!needsDepth)return false;if(needsDepth&&(options.bodyNeedsDepth??true)&&depth<2)return false;const scope=sourceCode.getScope(current);for(let s=scope;s!==null;s=s.upper){const variable=s.set.get(current.name);if(variable===void 0)continue;return variable.defs.some(d=>d.type==="Parameter")}return false}
|
package/src/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import './types/meta-augmentation';
|
|
22
22
|
export * from './rule-creation';
|
|
23
23
|
export * from './ast/ast-utils';
|
|
24
|
+
export * from './ast/spellings';
|
|
24
25
|
export * from './ast/module-binding';
|
|
25
26
|
export * from './ast/static-expression';
|
|
26
27
|
export * from './ast/identifier-words';
|
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("./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
|
+
"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/spellings"),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}});
|