@interlace/eslint-devkit 1.4.1 → 1.4.3
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/CHANGELOG.md +30 -0
- package/README.md +6 -2
- package/package.json +14 -7
- package/src/resolver/dependency-analysis.js +22 -13
- package/src/resolver/resolver-detection.d.ts +8 -0
- package/src/resolver/resolver-detection.js +15 -6
- package/src/resolver/resolver.js +0 -6
- package/src/rule-creation/index.d.ts +1 -0
- package/src/rule-creation/index.js +1 -0
- package/src/rule-creation/mock-context.d.ts +40 -0
- package/src/rule-creation/mock-context.js +47 -0
- package/src/security/security-utils.d.ts +0 -2
- package/src/security/security-utils.js +5 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
## [1.4.0] - 2026-05-03
|
|
2
2
|
|
|
3
|
+
## 1.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#304](https://github.com/ofri-peretz/eslint/pull/304) [`e1cdf83`](https://github.com/ofri-peretz/eslint/commit/e1cdf83e3db761907f0ab06f7fc6c1f1da7513a5) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - README: call the plugin family "the Interlace eslint-plugins" instead of
|
|
8
|
+
`@interlace/eslint-plugin-*`.
|
|
9
|
+
|
|
10
|
+
The plugins publish unscoped — `eslint-plugin-jwt`, not
|
|
11
|
+
`@interlace/eslint-plugin-jwt` — so the scoped form named packages that do not
|
|
12
|
+
exist on npm. This is a docs-only change; no runtime behaviour is affected. It
|
|
13
|
+
ships as a patch so the corrected text reaches the package page on npm.
|
|
14
|
+
|
|
15
|
+
- [#294](https://github.com/ofri-peretz/eslint/pull/294) [`659f6dc`](https://github.com/ofri-peretz/eslint/commit/659f6dc0181b03b675f72b5949fcf123dd066358) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - Rewrite `description` and `keywords` on every published package for npm search discovery. npm ranks on name, description, and keywords, and the registry only picks up these fields at publish — so this is metadata-only and takes effect for each package on its next release.
|
|
16
|
+
|
|
17
|
+
**Descriptions now lead with the search phrase.** Every one starts `ESLint plugin for <the thing you'd search>` instead of a brand-first or category-first framing, and names the concrete vulnerabilities the plugin actually detects. Three were corrected while doing so:
|
|
18
|
+
|
|
19
|
+
- `eslint-plugin-import-next` claimed "100x faster no-cycle detection". No 100x measurement exists: `CLAIMS.md` records **3.1x end-to-end** (8x in pure rule execution) on a 5,483-file React codebase, and the highest number in any benchmark result is 54.9x on the synthetic corpus. The description now states the real-codebase figure.
|
|
20
|
+
- `eslint-plugin-secure-coding` claimed SQL injection, XSS and CSRF coverage — none of which are its rules. It now names what it does detect: LDAP, XPath, XXE, GraphQL and template injection, unsafe deserialization, ReDoS, missing authentication, and PII in logs.
|
|
21
|
+
- `eslint-plugin-secure-coding` ("89 rules") and `eslint-plugin-react-a11y` ("37 rules") hard-coded rule counts that had drifted from reality. Counts are generated into `interlace-numbers.json`; hand-typed copies are removed rather than corrected.
|
|
22
|
+
|
|
23
|
+
**Keywords now match the vocabulary of the plugins that rank.** `eslint-plugin-security`, `eslint-plugin-jsx-a11y`, `eslint-plugin-n` and `eslint-plugin-import` all carry the `eslint` / `eslintplugin` / `eslint-plugin` trio — six of our packages were missing `eslintplugin`, and every one now carries all three plus `static-analysis`, `linting` and `code-quality`. Security plugins add `sast`, `appsec` and `vulnerability`; `node-security` and `secure-coding` also carry `nodesecurity`, the exact keyword `eslint-plugin-security` ranks on. Each plugin gained the CWE identifiers and attack names for what it detects (`cwe-78` command injection, `cwe-22` path traversal, `cwe-89` SQL injection, `cwe-79` XSS, `cwe-347` JWT algorithm confusion, `cwe-352` CSRF, `cwe-943` NoSQL injection), and `node-security` gained the crypto vocabulary it had been missing entirely despite absorbing the crypto rule set (`crypto`, `cryptography`, `weak-hash`, `md5`, `sha1`, `timing-attack`).
|
|
24
|
+
|
|
25
|
+
No rule behavior, exports, or configuration changes.
|
|
26
|
+
|
|
27
|
+
## 1.4.2
|
|
28
|
+
|
|
29
|
+
### Patch Changes
|
|
30
|
+
|
|
31
|
+
- [#269](https://github.com/ofri-peretz/eslint/pull/269) [`7028fe2`](https://github.com/ofri-peretz/eslint/commit/7028fe2668a42266d831014184dcef70e73101ad) Thanks [@ofri-peretz](https://github.com/ofri-peretz)! - docs: dual-logo README header (Interlace mark + ESLint mark side by side) and closing Interlace footer — refreshes the README rendered on npmjs.com. No runtime changes.
|
|
32
|
+
|
|
3
33
|
## 1.4.1
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@interlace/eslint-devkit)
|
|
6
6
|
[](https://www.npmjs.com/package/@interlace/eslint-devkit)
|
|
7
|
-
[](https://app.codecov.io/gh/ofri-peretz/eslint/tree/main)
|
|
8
8
|
|
|
9
9
|
> **Keywords:** ESLint utilities, LLM-optimized, AI assistant, auto-fix, TypeScript ESLint, AST utilities, type checking, rule creation, GitHub Copilot, Cursor AI, Claude AI, structured error messages, deterministic fixes
|
|
10
10
|
|
|
@@ -508,7 +508,7 @@ See the [ESLint Version Support Policy](../../docs/ESLINT_VERSION_SUPPORT.md) fo
|
|
|
508
508
|
|
|
509
509
|
## Related Packages
|
|
510
510
|
|
|
511
|
-
- **The
|
|
511
|
+
- **The Interlace eslint-plugins** — Ready-to-use LLM-optimized rules built with this package. See the [root README](https://github.com/ofri-peretz/eslint#-available-packages) for the full list.
|
|
512
512
|
- **[@typescript-eslint/utils](https://www.npmjs.com/package/@typescript-eslint/utils)** - Official TypeScript ESLint utilities
|
|
513
513
|
- **[eslint-plugin-import](https://www.npmjs.com/package/eslint-plugin-import)** - Import/export validation
|
|
514
514
|
|
|
@@ -538,3 +538,7 @@ If the devkit saved you time, **[star the repo](https://github.com/ofri-peretz/e
|
|
|
538
538
|
## Changelog
|
|
539
539
|
|
|
540
540
|
See [CHANGELOG.md](./CHANGELOG.md) for a list of changes and version history.
|
|
541
|
+
|
|
542
|
+
<p align="center">
|
|
543
|
+
<a href="https://eslint.interlace.tools/?utm_source=github&utm_medium=referral&utm_campaign=eslint-devkit" target="blank"><img src="https://eslint.interlace.tools/icon-light.svg" alt="Interlace" height="70" /></a>
|
|
544
|
+
</p>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interlace/eslint-devkit",
|
|
3
|
-
"version": "1.4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.4.3",
|
|
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",
|
|
7
7
|
"types": "./src/index.d.ts",
|
|
@@ -44,18 +44,25 @@
|
|
|
44
44
|
"eslint",
|
|
45
45
|
"eslint-devkit",
|
|
46
46
|
"eslint-toolkit",
|
|
47
|
+
"eslint-plugin-development",
|
|
48
|
+
"custom-rules",
|
|
49
|
+
"rule-authoring",
|
|
47
50
|
"typescript",
|
|
51
|
+
"typescript-eslint",
|
|
48
52
|
"utilities",
|
|
49
53
|
"ast",
|
|
54
|
+
"ast-utils",
|
|
50
55
|
"type-checking",
|
|
51
56
|
"plugin-development",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"auto-fix",
|
|
57
|
+
"static-analysis",
|
|
58
|
+
"linting",
|
|
55
59
|
"sarif",
|
|
56
60
|
"owasp",
|
|
57
61
|
"cwe",
|
|
58
|
-
"security"
|
|
62
|
+
"security",
|
|
63
|
+
"llm-optimized",
|
|
64
|
+
"ai-assistant",
|
|
65
|
+
"auto-fix"
|
|
59
66
|
],
|
|
60
67
|
"engines": {
|
|
61
68
|
"node": ">=18.0.0"
|
|
@@ -77,7 +84,7 @@
|
|
|
77
84
|
},
|
|
78
85
|
"dependencies": {
|
|
79
86
|
"@typescript-eslint/utils": "^7.0.0 || ^8.0.0",
|
|
80
|
-
"oxc-resolver": "^11.
|
|
87
|
+
"oxc-resolver": "^11.24.2"
|
|
81
88
|
},
|
|
82
89
|
"devDependencies": {
|
|
83
90
|
"@typescript-eslint/parser": "^8.46.2",
|
|
@@ -580,9 +580,9 @@ function computeSCCsFromFile(startFile, options) {
|
|
|
580
580
|
const filesToProcess = [startFile];
|
|
581
581
|
// First pass: discover all reachable files (breadth-first for efficiency)
|
|
582
582
|
while (filesToProcess.length > 0) {
|
|
583
|
+
// pop() cannot return undefined here: the loop guard ensures the stack
|
|
584
|
+
// is non-empty and every pushed path is a non-empty string.
|
|
583
585
|
const file = filesToProcess.pop();
|
|
584
|
-
if (!file)
|
|
585
|
-
continue;
|
|
586
586
|
if (visited.has(file))
|
|
587
587
|
continue;
|
|
588
588
|
visited.add(file);
|
|
@@ -679,11 +679,18 @@ function tarjanStrongConnect(file, state, options, depth) {
|
|
|
679
679
|
if (!state.indices.has(successor)) {
|
|
680
680
|
// Successor has not yet been visited; recurse on it
|
|
681
681
|
tarjanStrongConnect(successor, state, options, depth + 1);
|
|
682
|
-
state.lowlinks.set(file, Math.min(
|
|
682
|
+
state.lowlinks.set(file, Math.min(
|
|
683
|
+
// `file`'s lowlink is always set at function entry above.
|
|
684
|
+
state.lowlinks.get(file),
|
|
685
|
+
// The successor's lowlink can be missing when the recursive call
|
|
686
|
+
// returned early on the depth limit before initializing it.
|
|
687
|
+
state.lowlinks.get(successor) ?? 0));
|
|
683
688
|
}
|
|
684
689
|
else if (state.onStack.has(successor)) {
|
|
685
|
-
// Successor is in stack and hence in the current SCC
|
|
686
|
-
|
|
690
|
+
// Successor is in stack and hence in the current SCC.
|
|
691
|
+
// Both values are guaranteed: `file` got a lowlink at function entry,
|
|
692
|
+
// and an on-stack successor always received an index before pushing.
|
|
693
|
+
state.lowlinks.set(file, Math.min(state.lowlinks.get(file), state.indices.get(successor)));
|
|
687
694
|
}
|
|
688
695
|
}
|
|
689
696
|
const lowlink = state.lowlinks.get(file);
|
|
@@ -693,12 +700,13 @@ function tarjanStrongConnect(file, state, options, depth) {
|
|
|
693
700
|
const scc = [];
|
|
694
701
|
let w;
|
|
695
702
|
do {
|
|
703
|
+
// The stack always contains `file` at this point (it was pushed at
|
|
704
|
+
// function entry), so pop() cannot return undefined before the loop
|
|
705
|
+
// terminates at `w === file`.
|
|
696
706
|
w = state.stack.pop();
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
}
|
|
701
|
-
} while (w && w !== file);
|
|
707
|
+
state.onStack.delete(w);
|
|
708
|
+
scc.push(w);
|
|
709
|
+
} while (w !== file);
|
|
702
710
|
// Only store SCCs (single nodes aren't cycles, but we track them for completeness)
|
|
703
711
|
state.sccs.push(scc);
|
|
704
712
|
}
|
|
@@ -852,9 +860,10 @@ function detectCycleFromImport(sourceFile, targetFile, options) {
|
|
|
852
860
|
// Known non-cyclic from previous lint file visits
|
|
853
861
|
if (cache.nonCyclicFiles.has(file))
|
|
854
862
|
return;
|
|
855
|
-
//
|
|
856
|
-
|
|
857
|
-
|
|
863
|
+
// NOTE: no `!reportAllCycles && allCycles.length > 0` early-exit here —
|
|
864
|
+
// it would be unreachable: the import loop below performs the identical
|
|
865
|
+
// check (and breaks) before every recursive dfs() call, and the root
|
|
866
|
+
// call always happens before any cycle can have been recorded.
|
|
858
867
|
visited.add(file);
|
|
859
868
|
pathStack.push(file);
|
|
860
869
|
const imports = getFileImports(file, {
|
|
@@ -16,6 +16,14 @@ export interface ResolverDetectionResult {
|
|
|
16
16
|
* Detect available resolvers based on project structure
|
|
17
17
|
*/
|
|
18
18
|
export declare function detectResolvers(workspaceRoot: string): ResolverDetectionResult[];
|
|
19
|
+
/**
|
|
20
|
+
* Comparator for resolver priority ordering. Known resolver names sort by
|
|
21
|
+
* their position in the priority list; unknown names sort last (999).
|
|
22
|
+
*
|
|
23
|
+
* Extracted from `generateRecommendedConfig` so the unknown-name fallback is
|
|
24
|
+
* directly unit-testable (detectResolvers only ever emits known names).
|
|
25
|
+
*/
|
|
26
|
+
export declare function compareResolverPriority(aName: string, bName: string): number;
|
|
19
27
|
/**
|
|
20
28
|
* Generate recommended ESLint resolver configuration
|
|
21
29
|
*/
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
8
|
exports.detectResolvers = detectResolvers;
|
|
9
|
+
exports.compareResolverPriority = compareResolverPriority;
|
|
9
10
|
exports.generateRecommendedConfig = generateRecommendedConfig;
|
|
10
11
|
exports.migrateFromEslintImport = migrateFromEslintImport;
|
|
11
12
|
exports.validateResolverConfig = validateResolverConfig;
|
|
@@ -77,6 +78,19 @@ function detectResolvers(workspaceRoot) {
|
|
|
77
78
|
});
|
|
78
79
|
return results;
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Comparator for resolver priority ordering. Known resolver names sort by
|
|
83
|
+
* their position in the priority list; unknown names sort last (999).
|
|
84
|
+
*
|
|
85
|
+
* Extracted from `generateRecommendedConfig` so the unknown-name fallback is
|
|
86
|
+
* directly unit-testable (detectResolvers only ever emits known names).
|
|
87
|
+
*/
|
|
88
|
+
function compareResolverPriority(aName, bName) {
|
|
89
|
+
const priorityOrder = ['typescript', 'webpack', 'vite', 'rollup', 'css'];
|
|
90
|
+
const aIndex = priorityOrder.indexOf(aName);
|
|
91
|
+
const bIndex = priorityOrder.indexOf(bName);
|
|
92
|
+
return (aIndex === -1 ? 999 : aIndex) - (bIndex === -1 ? 999 : bIndex);
|
|
93
|
+
}
|
|
80
94
|
/**
|
|
81
95
|
* Generate recommended ESLint resolver configuration
|
|
82
96
|
*/
|
|
@@ -93,12 +107,7 @@ function generateRecommendedConfig(workspaceRoot) {
|
|
|
93
107
|
}
|
|
94
108
|
// Prioritize resolvers
|
|
95
109
|
// oxlint-disable-next-line no-array-sort
|
|
96
|
-
const prioritized = availableResolvers.sort((a, b) =>
|
|
97
|
-
const priorityOrder = ['typescript', 'webpack', 'vite', 'rollup', 'css'];
|
|
98
|
-
const aIndex = priorityOrder.indexOf(a.name);
|
|
99
|
-
const bIndex = priorityOrder.indexOf(b.name);
|
|
100
|
-
return (aIndex === -1 ? 999 : aIndex) - (bIndex === -1 ? 999 : bIndex);
|
|
101
|
-
});
|
|
110
|
+
const prioritized = availableResolvers.sort((a, b) => compareResolverPriority(a.name, b.name));
|
|
102
111
|
// Create prioritized resolver configuration
|
|
103
112
|
const resolverConfig = {};
|
|
104
113
|
prioritized.forEach((resolver, index) => {
|
package/src/resolver/resolver.js
CHANGED
|
@@ -267,9 +267,3 @@ function clearResolverCache() {
|
|
|
267
267
|
oxcResolverCache.clear();
|
|
268
268
|
tsconfigPathCache.clear();
|
|
269
269
|
}
|
|
270
|
-
// Lines 322-324: Defensive error handling for truly exceptional cases
|
|
271
|
-
// These lines handle unexpected exceptions from resolution logic that are:
|
|
272
|
-
// 1. Difficult to reproduce in tests (would require mocking library functions to throw)
|
|
273
|
-
// 2. Represent proper defensive programming practices
|
|
274
|
-
// 3. Ensure the resolver never crashes with unhandled exceptions
|
|
275
|
-
// Coverage: Intentionally uncovered as these are edge case error paths
|
|
@@ -8,3 +8,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
// Rule creation utilities for building ESLint rules
|
|
10
10
|
tslib_1.__exportStar(require("./rule-creator"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./mock-context"), exports);
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
* Test helper: run a rule's `create()` against a minimal mock context.
|
|
8
|
+
*
|
|
9
|
+
* Layer-2 testing utility for branches that a real parser can never produce
|
|
10
|
+
* (synthetic AST nodes with `parent: null`, inverted ranges, missing tokens).
|
|
11
|
+
* Call the returned `listeners` directly with synthetic nodes and assert on
|
|
12
|
+
* the recorded `reports`.
|
|
13
|
+
*/
|
|
14
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
15
|
+
/** Anything shaped like an ESLint rule module (`{ create(context) }`). */
|
|
16
|
+
export interface RuleLike {
|
|
17
|
+
create(context: never): Record<string, unknown>;
|
|
18
|
+
defaultOptions?: readonly unknown[];
|
|
19
|
+
}
|
|
20
|
+
/** Optional overrides for the mock context. */
|
|
21
|
+
export interface MockContextOptions {
|
|
22
|
+
options?: readonly unknown[];
|
|
23
|
+
settings?: TSESLint.SharedConfigurationSettings;
|
|
24
|
+
filename?: string;
|
|
25
|
+
/** Text returned by the `sourceCode.getText()` stub. */
|
|
26
|
+
sourceText?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface MockContextResult {
|
|
29
|
+
/** Visitor listeners returned by `rule.create(context)`. */
|
|
30
|
+
listeners: Record<string, unknown>;
|
|
31
|
+
/** Every descriptor passed to `context.report`, in call order. */
|
|
32
|
+
reports: TSESLint.ReportDescriptor<string>[];
|
|
33
|
+
/** The mock context handed to `create()` (report recorder attached). */
|
|
34
|
+
context: TSESLint.RuleContext<string, readonly unknown[]>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Build a minimal rule context, call `rule.create(context)`, and return the
|
|
38
|
+
* listeners plus a recorder of every `context.report(...)` descriptor.
|
|
39
|
+
*/
|
|
40
|
+
export declare function createWithMockContext(rule: RuleLike, opts?: MockContextOptions): MockContextResult;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2025 Ofri Peretz
|
|
4
|
+
* Licensed under the MIT License. Use of this source code is governed by the
|
|
5
|
+
* MIT license that can be found in the LICENSE file.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createWithMockContext = createWithMockContext;
|
|
9
|
+
/**
|
|
10
|
+
* Build a minimal rule context, call `rule.create(context)`, and return the
|
|
11
|
+
* listeners plus a recorder of every `context.report(...)` descriptor.
|
|
12
|
+
*/
|
|
13
|
+
function createWithMockContext(rule, opts = {}) {
|
|
14
|
+
const reports = [];
|
|
15
|
+
const filename = opts.filename ?? 'mock.ts';
|
|
16
|
+
const emptyScope = { variables: [], references: [], childScopes: [] };
|
|
17
|
+
const sourceCode = {
|
|
18
|
+
text: opts.sourceText ?? '',
|
|
19
|
+
getText: () => opts.sourceText ?? '',
|
|
20
|
+
getScope: () => emptyScope,
|
|
21
|
+
getAncestors: () => [],
|
|
22
|
+
getCommentsBefore: () => [],
|
|
23
|
+
getDeclaredVariables: () => [],
|
|
24
|
+
};
|
|
25
|
+
const context = {
|
|
26
|
+
id: 'mock-rule',
|
|
27
|
+
filename,
|
|
28
|
+
physicalFilename: filename,
|
|
29
|
+
cwd: '/',
|
|
30
|
+
options: opts.options ?? rule.defaultOptions ?? [],
|
|
31
|
+
settings: opts.settings ?? {},
|
|
32
|
+
parserOptions: {},
|
|
33
|
+
languageOptions: {},
|
|
34
|
+
sourceCode,
|
|
35
|
+
getFilename: () => filename,
|
|
36
|
+
getPhysicalFilename: () => filename,
|
|
37
|
+
getCwd: () => '/',
|
|
38
|
+
getSourceCode: () => sourceCode,
|
|
39
|
+
getScope: () => emptyScope,
|
|
40
|
+
getAncestors: () => [],
|
|
41
|
+
report: (descriptor) => {
|
|
42
|
+
reports.push(descriptor);
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
const listeners = rule.create(context);
|
|
46
|
+
return { listeners, reports, context };
|
|
47
|
+
}
|
|
@@ -266,11 +266,9 @@ export type SafetyChecker = ReturnType<typeof createSafetyChecker>;
|
|
|
266
266
|
*
|
|
267
267
|
* ```typescript
|
|
268
268
|
* // Instead of this (3-5 lines each, 75+ occurrences):
|
|
269
|
-
* /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester *\/
|
|
270
269
|
* if (safetyChecker.isSafe(node, context)) {
|
|
271
270
|
* return;
|
|
272
271
|
* }
|
|
273
|
-
* /* c8 ignore stop *\/
|
|
274
272
|
*
|
|
275
273
|
* // Use this (1 line):
|
|
276
274
|
* if (shouldSkipForSafety(safetyChecker, node, context)) return;
|
|
@@ -336,36 +336,11 @@ function hasSafeAnnotation(node, context, customAnnotations = []) {
|
|
|
336
336
|
}
|
|
337
337
|
current = current.parent;
|
|
338
338
|
}
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
current.type === 'ArrowFunctionExpression' ||
|
|
345
|
-
current.type === 'MethodDefinition') {
|
|
346
|
-
// Check for JSDoc comments
|
|
347
|
-
const comments = sourceCode.getCommentsBefore(current);
|
|
348
|
-
for (const comment of comments) {
|
|
349
|
-
if (comment.type === 'Block' && comment.value.startsWith('*')) {
|
|
350
|
-
// JSDoc comment
|
|
351
|
-
const commentText = comment.value.toLowerCase();
|
|
352
|
-
if (allAnnotations.some((ann) => commentText.includes(ann.toLowerCase()))) {
|
|
353
|
-
return true;
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
// Also check inline comments
|
|
358
|
-
const leadingComments = sourceCode.getCommentsBefore(current);
|
|
359
|
-
for (const comment of leadingComments) {
|
|
360
|
-
const commentText = comment.value.toLowerCase();
|
|
361
|
-
if (allAnnotations.some((ann) => commentText.includes(ann.toLowerCase()))) {
|
|
362
|
-
return true;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
break; // Only check the innermost function
|
|
366
|
-
}
|
|
367
|
-
current = current.parent;
|
|
368
|
-
}
|
|
339
|
+
// NOTE: a second pass that re-checked the innermost function's JSDoc was
|
|
340
|
+
// removed as provably redundant: the walk above already inspects the
|
|
341
|
+
// comments before every ancestor on the same parent chain — including the
|
|
342
|
+
// containing function/method — before breaking at the function boundary,
|
|
343
|
+
// and with the same annotation predicate.
|
|
369
344
|
return false;
|
|
370
345
|
}
|
|
371
346
|
/**
|
|
@@ -515,11 +490,9 @@ function createSafetyChecker(options = {}) {
|
|
|
515
490
|
*
|
|
516
491
|
* ```typescript
|
|
517
492
|
* // Instead of this (3-5 lines each, 75+ occurrences):
|
|
518
|
-
* /* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester *\/
|
|
519
493
|
* if (safetyChecker.isSafe(node, context)) {
|
|
520
494
|
* return;
|
|
521
495
|
* }
|
|
522
|
-
* /* c8 ignore stop *\/
|
|
523
496
|
*
|
|
524
497
|
* // Use this (1 line):
|
|
525
498
|
* if (shouldSkipForSafety(safetyChecker, node, context)) return;
|
|
@@ -537,11 +510,9 @@ function createSafetyChecker(options = {}) {
|
|
|
537
510
|
* }
|
|
538
511
|
* ```
|
|
539
512
|
*/
|
|
540
|
-
/* c8 ignore start -- safetyChecker requires JSDoc annotations not testable via RuleTester */
|
|
541
513
|
function shouldSkipForSafety(safetyChecker, node, context) {
|
|
542
514
|
return safetyChecker.isSafe(node, context);
|
|
543
515
|
}
|
|
544
|
-
/* c8 ignore stop */
|
|
545
516
|
// ============================================================================
|
|
546
517
|
// AST TRAVERSAL UTILITIES
|
|
547
518
|
// ============================================================================
|