eslint-plugin-traceability 1.11.1 → 1.11.2
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 +2 -2
- package/README.md +1 -1
- package/lib/src/index.d.ts +12 -1
- package/lib/src/index.js +43 -6
- package/lib/src/maintenance/commands.js +2 -3
- package/lib/src/maintenance/update.js +1 -14
- package/lib/src/rules/helpers/require-story-core.d.ts +12 -4
- package/lib/src/rules/helpers/require-story-core.js +59 -30
- package/lib/src/rules/helpers/require-story-helpers.d.ts +7 -41
- package/lib/src/rules/helpers/require-story-helpers.js +13 -70
- package/lib/src/rules/helpers/valid-annotation-format-internal.d.ts +12 -13
- package/lib/src/rules/helpers/valid-annotation-format-internal.js +21 -16
- package/lib/src/rules/helpers/valid-annotation-format-validators.d.ts +29 -3
- package/lib/src/rules/helpers/valid-annotation-format-validators.js +29 -3
- package/lib/src/rules/helpers/valid-annotation-utils.d.ts +3 -3
- package/lib/src/rules/helpers/valid-annotation-utils.js +10 -10
- package/lib/src/rules/helpers/valid-req-reference-helpers.d.ts +11 -0
- package/lib/src/rules/helpers/valid-req-reference-helpers.js +362 -0
- package/lib/src/rules/prefer-implements-annotation.js +7 -7
- package/lib/src/rules/require-story-annotation.d.ts +2 -0
- package/lib/src/rules/require-story-annotation.js +1 -1
- package/lib/src/rules/valid-req-reference.d.ts +4 -0
- package/lib/src/rules/valid-req-reference.js +5 -349
- package/lib/src/rules/valid-story-reference.d.ts +1 -1
- package/lib/src/rules/valid-story-reference.js +17 -10
- package/lib/src/utils/branch-annotation-helpers.d.ts +2 -2
- package/lib/src/utils/branch-annotation-helpers.js +4 -4
- package/lib/tests/cli-error-handling.test.js +1 -1
- package/lib/tests/config/eslint-config-validation.test.js +73 -0
- package/lib/tests/fixtures/stale/example.js +1 -1
- package/lib/tests/fixtures/update/example.js +1 -1
- package/lib/tests/integration/dogfooding-validation.test.d.ts +1 -0
- package/lib/tests/integration/dogfooding-validation.test.js +94 -0
- package/lib/tests/maintenance/cli.test.js +37 -0
- package/lib/tests/maintenance/detect-isolated.test.js +5 -5
- package/lib/tests/perf/maintenance-cli-large-workspace.test.js +18 -0
- package/lib/tests/perf/require-branch-annotation-large-file.test.d.ts +1 -0
- package/lib/tests/perf/require-branch-annotation-large-file.test.js +67 -0
- package/lib/tests/plugin-setup.test.js +12 -1
- package/lib/tests/rules/require-branch-annotation.test.js +33 -1
- package/lib/tests/rules/valid-annotation-format-internal.test.d.ts +8 -0
- package/lib/tests/rules/valid-annotation-format-internal.test.js +47 -0
- package/package.json +2 -2
- package/user-docs/api-reference.md +5 -5
- package/user-docs/examples.md +2 -1
- package/user-docs/migration-guide.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
## [1.11.
|
|
1
|
+
## [1.11.2](https://github.com/voder-ai/eslint-plugin-traceability/compare/v1.11.1...v1.11.2) (2025-12-06)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* ignore inline-code annotation references in comment normalization ([118d743](https://github.com/voder-ai/eslint-plugin-traceability/commit/118d743ff8c8bf1dcb0854b898480c641cc727c8))
|
|
7
7
|
|
|
8
8
|
# Changelog
|
|
9
9
|
|
package/README.md
CHANGED
|
@@ -242,4 +242,4 @@ For the canonical, user-facing security policy (including how to report vulnerab
|
|
|
242
242
|
- Contribution guide: <https://github.com/voder-ai/eslint-plugin-traceability/blob/main/CONTRIBUTING.md>
|
|
243
243
|
- Issue tracker: <https://github.com/voder-ai/eslint-plugin-traceability/issues>
|
|
244
244
|
- Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
245
|
-
- Versioning and Releases: This project uses semantic-release for automated versioning. The authoritative list of published versions and release notes is on GitHub Releases: <https://github.com/voder-ai/eslint-plugin-traceability/releases>
|
|
245
|
+
- Versioning and Releases: This project uses semantic-release for automated versioning. The authoritative list of published versions and release notes is on GitHub Releases: <https://github.com/voder-ai/eslint-plugin-traceability/releases>
|
package/lib/src/index.d.ts
CHANGED
|
@@ -11,16 +11,27 @@ import type { Rule } from "eslint";
|
|
|
11
11
|
*/
|
|
12
12
|
import { detectStaleAnnotations, updateAnnotationReferences, batchUpdateAnnotations, verifyAnnotations, generateMaintenanceReport } from "./maintenance";
|
|
13
13
|
/**
|
|
14
|
-
* @story docs/stories/002.0-
|
|
14
|
+
* @story docs/stories/002.0-DEV-ESLINT-CONFIG.story.md
|
|
15
15
|
* @req REQ-RULE-LIST - Enumerate supported rule file names for plugin discovery
|
|
16
16
|
*/
|
|
17
17
|
declare const RULE_NAMES: readonly ["require-story-annotation", "require-req-annotation", "require-branch-annotation", "valid-annotation-format", "valid-story-reference", "valid-req-reference", "prefer-implements-annotation", "require-test-traceability"];
|
|
18
18
|
type RuleName = (typeof RULE_NAMES)[number];
|
|
19
19
|
declare const rules: Record<RuleName, Rule.RuleModule>;
|
|
20
|
+
/**
|
|
21
|
+
* Plugin metadata used by ESLint for debugging and caching.
|
|
22
|
+
*
|
|
23
|
+
* @supports docs/stories/001.0-DEV-PLUGIN-SETUP.story.md REQ-PLUGIN-STRUCTURE REQ-NPM-PACKAGE
|
|
24
|
+
*/
|
|
25
|
+
declare const pluginMeta: {
|
|
26
|
+
readonly name: string;
|
|
27
|
+
readonly version: string;
|
|
28
|
+
readonly namespace: "traceability";
|
|
29
|
+
};
|
|
20
30
|
declare const plugin: {
|
|
21
31
|
rules: typeof rules;
|
|
22
32
|
configs?: unknown;
|
|
23
33
|
maintenance?: unknown;
|
|
34
|
+
meta?: typeof pluginMeta;
|
|
24
35
|
};
|
|
25
36
|
/**
|
|
26
37
|
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
package/lib/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.maintenance = exports.configs = exports.rules = void 0;
|
|
|
7
7
|
*/
|
|
8
8
|
const maintenance_1 = require("./maintenance");
|
|
9
9
|
/**
|
|
10
|
-
* @story docs/stories/002.0-
|
|
10
|
+
* @story docs/stories/002.0-DEV-ESLINT-CONFIG.story.md
|
|
11
11
|
* @req REQ-RULE-LIST - Enumerate supported rule file names for plugin discovery
|
|
12
12
|
*/
|
|
13
13
|
const RULE_NAMES = [
|
|
@@ -24,18 +24,18 @@ const rules = {};
|
|
|
24
24
|
exports.rules = rules;
|
|
25
25
|
RULE_NAMES.forEach(
|
|
26
26
|
/**
|
|
27
|
-
* @story docs/stories/002.0-
|
|
27
|
+
* @story docs/stories/002.0-DEV-ESLINT-CONFIG.story.md
|
|
28
28
|
* @req REQ-DYNAMIC-LOADING - Support dynamic rule loading by name at runtime
|
|
29
29
|
* @param {RuleName} name - Rule file base name used to discover and load rule module
|
|
30
30
|
*/
|
|
31
31
|
(name) => {
|
|
32
32
|
/**
|
|
33
|
-
* @story docs/stories/002.0-
|
|
33
|
+
* @story docs/stories/002.0-DEV-ESLINT-CONFIG.story.md
|
|
34
34
|
* @req REQ-DYNAMIC-LOADING - Support dynamic rule loading by name at runtime
|
|
35
35
|
*/
|
|
36
36
|
try {
|
|
37
37
|
/**
|
|
38
|
-
* @story docs/stories/002.0-
|
|
38
|
+
* @story docs/stories/002.0-DEV-ESLINT-CONFIG.story.md
|
|
39
39
|
* @req REQ-DYNAMIC-LOADING - Support dynamic rule loading by name at runtime
|
|
40
40
|
*/
|
|
41
41
|
// Dynamically require rule module
|
|
@@ -45,11 +45,11 @@ RULE_NAMES.forEach(
|
|
|
45
45
|
}
|
|
46
46
|
catch (error) {
|
|
47
47
|
/**
|
|
48
|
-
* @story docs/stories/
|
|
48
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
49
49
|
* @req REQ-ERROR-HANDLING - Provide fallback rule module and surface errors when rule loading fails
|
|
50
50
|
*/
|
|
51
51
|
/**
|
|
52
|
-
* @story docs/stories/
|
|
52
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
53
53
|
* @req REQ-ERROR-HANDLING - Provide fallback rule module and surface errors when rule loading fails
|
|
54
54
|
*/
|
|
55
55
|
console.error(`[eslint-plugin-traceability] Failed to load rule "${name}": ${error.message}`);
|
|
@@ -74,8 +74,45 @@ RULE_NAMES.forEach(
|
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
+
/**
|
|
78
|
+
* Plugin metadata used by ESLint for debugging and caching.
|
|
79
|
+
*
|
|
80
|
+
* @supports docs/stories/001.0-DEV-PLUGIN-SETUP.story.md REQ-PLUGIN-STRUCTURE REQ-NPM-PACKAGE
|
|
81
|
+
*/
|
|
82
|
+
const pluginMeta = (() => {
|
|
83
|
+
let pkg = {};
|
|
84
|
+
try {
|
|
85
|
+
// When running from built output (lib/src/index.js)
|
|
86
|
+
// this resolves to the package.json at the project root.
|
|
87
|
+
// @supports docs/stories/001.0-DEV-PLUGIN-SETUP.story.md REQ-NPM-PACKAGE
|
|
88
|
+
pkg = require("../../package.json");
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
try {
|
|
92
|
+
// When running via the TypeScript sources (src/index.ts) in this repo,
|
|
93
|
+
// fall back to resolving package.json one level up from src/.
|
|
94
|
+
// @supports docs/stories/001.0-DEV-PLUGIN-SETUP.story.md REQ-NPM-PACKAGE
|
|
95
|
+
pkg = require("../package.json");
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
// As a last resort (tests, unusual environments), provide sensible
|
|
99
|
+
// defaults so that plugin loading never fails just for metadata.
|
|
100
|
+
// @supports docs/stories/001.0-DEV-PLUGIN-SETUP.story.md REQ-PLUGIN-STRUCTURE
|
|
101
|
+
pkg = {
|
|
102
|
+
name: "eslint-plugin-traceability",
|
|
103
|
+
version: "0.0.0-development",
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
name: pkg.name ?? "eslint-plugin-traceability",
|
|
109
|
+
version: pkg.version ?? "0.0.0-development",
|
|
110
|
+
namespace: "traceability",
|
|
111
|
+
};
|
|
112
|
+
})();
|
|
77
113
|
const plugin = {
|
|
78
114
|
rules,
|
|
115
|
+
meta: pluginMeta,
|
|
79
116
|
};
|
|
80
117
|
/**
|
|
81
118
|
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
@@ -9,7 +9,7 @@ exports.handleUpdate = handleUpdate;
|
|
|
9
9
|
* Subcommand handlers for the traceability-maint CLI.
|
|
10
10
|
*
|
|
11
11
|
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
12
|
-
* @req REQ-MAINT-DETECT - CLI support for detection of stale annotations
|
|
12
|
+
* @req REQ-MAINT-DETECT - CLI support for detection of stale annotations.
|
|
13
13
|
* @req REQ-MAINT-VERIFY - CLI support for verification of annotations
|
|
14
14
|
* @req REQ-MAINT-REPORT - CLI support for human-readable reports
|
|
15
15
|
* @req REQ-MAINT-UPDATE - CLI support for updating annotation references
|
|
@@ -34,8 +34,7 @@ function handleDetect(normalized) {
|
|
|
34
34
|
const root = flags.root;
|
|
35
35
|
const stale = (0, detect_1.detectStaleAnnotations)(root);
|
|
36
36
|
if (flags.json) {
|
|
37
|
-
//
|
|
38
|
-
// @req REQ-MAINT-REPORT - JSON-friendly output for tooling integration
|
|
37
|
+
// Emit JSON output to support consumption by external tools and scripts.
|
|
39
38
|
console.log(JSON.stringify({ root, stale }));
|
|
40
39
|
}
|
|
41
40
|
else if (stale.length === 0) {
|
|
@@ -42,20 +42,7 @@ const utils_1 = require("./utils");
|
|
|
42
42
|
* @req REQ-MAINT-UPDATE
|
|
43
43
|
*/
|
|
44
44
|
function processFileForAnnotationUpdates(fullPath, regex, newPath, replacementCountRef) {
|
|
45
|
-
const
|
|
46
|
-
/**
|
|
47
|
-
* Skip non-files in iteration
|
|
48
|
-
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
49
|
-
* @req REQ-MAINT-UPDATE
|
|
50
|
-
*/
|
|
51
|
-
/**
|
|
52
|
-
* Skip entries that are not regular files (e.g., directories)
|
|
53
|
-
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
54
|
-
* @req REQ-MAINT-UPDATE
|
|
55
|
-
*/
|
|
56
|
-
if (!stat.isFile())
|
|
57
|
-
return;
|
|
58
|
-
const content = fs.readFileSync(fullPath, "utf8");
|
|
45
|
+
const content = fs.readFileSync(fullPath, "utf8"); // getAllFiles already returns regular files
|
|
59
46
|
const newContent = content.replace(regex,
|
|
60
47
|
/**
|
|
61
48
|
* Replacement callback to update annotation references
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Create a fixer function that inserts a @story annotation before the target node.
|
|
3
|
+
* This fixer is responsible for placing the annotation immediately before the
|
|
4
|
+
* resolved target node in the source code.
|
|
3
5
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
4
6
|
* @req REQ-AUTOFIX - Provide automatic fix function for missing @story annotations
|
|
5
7
|
*/
|
|
6
8
|
export declare function createAddStoryFix(target: any, annotationTemplate: string): (fixer: any) => any;
|
|
7
9
|
/**
|
|
8
10
|
* Create a fixer function for class method annotations.
|
|
11
|
+
* This helper ensures that the @story annotation is inserted with appropriate
|
|
12
|
+
* indentation and placement before a class method declaration.
|
|
9
13
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
10
14
|
* @req REQ-AUTOFIX - Provide automatic fix for class method annotations
|
|
11
15
|
*/
|
|
12
16
|
export declare function createMethodFix(node: any, annotationTemplate: string): (fixer: any) => any;
|
|
13
17
|
/**
|
|
14
18
|
* Default set of node types to check for missing @story annotations.
|
|
19
|
+
* This default scope covers common function-like declarations used in typical
|
|
20
|
+
* TypeScript and JavaScript codebases.
|
|
15
21
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
16
22
|
* @req REQ-ANNOTATION-REQUIRED - Provide sensible default scope for rule checks
|
|
17
23
|
*/
|
|
18
24
|
export declare const DEFAULT_SCOPE: string[];
|
|
19
25
|
/**
|
|
20
26
|
* Path to the story file for function-annotation helpers.
|
|
27
|
+
* This constant centralizes the reference to the canonical documentation story
|
|
28
|
+
* used by these helpers.
|
|
21
29
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
22
30
|
* @req REQ-ANNOTATION-REQUIRED - Provide a single source of truth for the canonical story path used by helper modules
|
|
23
31
|
*/
|
|
@@ -48,8 +56,8 @@ type ReportDeps = {
|
|
|
48
56
|
};
|
|
49
57
|
/**
|
|
50
58
|
* Core helper to report a missing @story annotation for a function-like node.
|
|
51
|
-
*
|
|
52
|
-
* can
|
|
59
|
+
* This reporting utility delegates behavior to injected dependencies so that
|
|
60
|
+
* higher-level helpers can stay small while sharing error-reporting logic.
|
|
53
61
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
54
62
|
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
55
63
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
@@ -64,8 +72,8 @@ export declare function coreReportMissing(deps: ReportDeps, context: Rule.RuleCo
|
|
|
64
72
|
}): void;
|
|
65
73
|
/**
|
|
66
74
|
* Core helper to report a missing @story annotation for a method-like node.
|
|
67
|
-
*
|
|
68
|
-
* module
|
|
75
|
+
* This method-focused reporting utility uses injected dependencies while
|
|
76
|
+
* keeping this module centered on core error-reporting behavior.
|
|
69
77
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
70
78
|
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
71
79
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
@@ -5,62 +5,77 @@ exports.createAddStoryFix = createAddStoryFix;
|
|
|
5
5
|
exports.createMethodFix = createMethodFix;
|
|
6
6
|
exports.coreReportMissing = coreReportMissing;
|
|
7
7
|
exports.coreReportMethod = coreReportMethod;
|
|
8
|
+
/**
|
|
9
|
+
* Compute the insertion start offset for inserting annotations before a node.
|
|
10
|
+
* This helper ensures we insert before any export wrapper when present, while
|
|
11
|
+
* remaining resilient to malformed or unexpected AST structures.
|
|
12
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
13
|
+
* @req REQ-AUTOFIX
|
|
14
|
+
* @req REQ-AUTOFIX-SAFE
|
|
15
|
+
*/
|
|
16
|
+
function getInsertionStart(candidate) {
|
|
17
|
+
if (!candidate || typeof candidate !== "object") {
|
|
18
|
+
return 0;
|
|
19
|
+
}
|
|
20
|
+
const parent = candidate.parent;
|
|
21
|
+
if (parent &&
|
|
22
|
+
(parent.type === "ExportNamedDeclaration" ||
|
|
23
|
+
parent.type === "ExportDefaultDeclaration") &&
|
|
24
|
+
Array.isArray(parent.range) &&
|
|
25
|
+
typeof parent.range[0] === "number") {
|
|
26
|
+
return parent.range[0];
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(candidate.range) &&
|
|
29
|
+
typeof candidate.range[0] === "number") {
|
|
30
|
+
return candidate.range[0];
|
|
31
|
+
}
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
8
34
|
/**
|
|
9
35
|
* Create a fixer function that inserts a @story annotation before the target node.
|
|
36
|
+
* This fixer is responsible for placing the annotation immediately before the
|
|
37
|
+
* resolved target node in the source code.
|
|
10
38
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
11
39
|
* @req REQ-AUTOFIX - Provide automatic fix function for missing @story annotations
|
|
12
40
|
*/
|
|
13
41
|
function createAddStoryFix(target, annotationTemplate) {
|
|
14
42
|
/**
|
|
15
43
|
* Fixer that inserts a @story annotation before the target node.
|
|
44
|
+
* This inner fixer is used by ESLint to apply the actual code modification.
|
|
16
45
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
17
46
|
* @req REQ-AUTOFIX - Provide automatic fix function for missing @story annotations
|
|
18
47
|
*/
|
|
19
48
|
function addStoryFixer(fixer) {
|
|
20
|
-
const start = target
|
|
21
|
-
? target.parent &&
|
|
22
|
-
(target.parent.type === "ExportNamedDeclaration" ||
|
|
23
|
-
target.parent.type === "ExportDefaultDeclaration") &&
|
|
24
|
-
Array.isArray(target.parent.range) &&
|
|
25
|
-
typeof target.parent.range[0] === "number"
|
|
26
|
-
? target.parent.range[0]
|
|
27
|
-
: Array.isArray(target.range) && typeof target.range[0] === "number"
|
|
28
|
-
? target.range[0]
|
|
29
|
-
: 0
|
|
30
|
-
: 0;
|
|
49
|
+
const start = getInsertionStart(target);
|
|
31
50
|
return fixer.insertTextBeforeRange([start, start], `${annotationTemplate}\n`);
|
|
32
51
|
}
|
|
33
52
|
return addStoryFixer;
|
|
34
53
|
}
|
|
35
54
|
/**
|
|
36
55
|
* Create a fixer function for class method annotations.
|
|
56
|
+
* This helper ensures that the @story annotation is inserted with appropriate
|
|
57
|
+
* indentation and placement before a class method declaration.
|
|
37
58
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
38
59
|
* @req REQ-AUTOFIX - Provide automatic fix for class method annotations
|
|
39
60
|
*/
|
|
40
61
|
function createMethodFix(node, annotationTemplate) {
|
|
41
62
|
/**
|
|
42
63
|
* Fixer that inserts a @story annotation before a method node.
|
|
64
|
+
* This inner fixer handles inserting the annotation with method-friendly
|
|
65
|
+
* formatting and spacing.
|
|
43
66
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
44
67
|
* @req REQ-AUTOFIX - Provide automatic fix for class method annotations
|
|
45
68
|
*/
|
|
46
69
|
function methodFixer(fixer) {
|
|
47
|
-
const start = node
|
|
48
|
-
? node.parent &&
|
|
49
|
-
(node.parent.type === "ExportNamedDeclaration" ||
|
|
50
|
-
node.parent.type === "ExportDefaultDeclaration") &&
|
|
51
|
-
Array.isArray(node.parent.range) &&
|
|
52
|
-
typeof node.parent.range[0] === "number"
|
|
53
|
-
? node.parent.range[0]
|
|
54
|
-
: Array.isArray(node.range) && typeof node.range[0] === "number"
|
|
55
|
-
? node.range[0]
|
|
56
|
-
: 0
|
|
57
|
-
: 0;
|
|
70
|
+
const start = getInsertionStart(node);
|
|
58
71
|
return fixer.insertTextBeforeRange([start, start], `${annotationTemplate}\n `);
|
|
59
72
|
}
|
|
60
73
|
return methodFixer;
|
|
61
74
|
}
|
|
62
75
|
/**
|
|
63
76
|
* Default set of node types to check for missing @story annotations.
|
|
77
|
+
* This default scope covers common function-like declarations used in typical
|
|
78
|
+
* TypeScript and JavaScript codebases.
|
|
64
79
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
65
80
|
* @req REQ-ANNOTATION-REQUIRED - Provide sensible default scope for rule checks
|
|
66
81
|
*/
|
|
@@ -73,6 +88,8 @@ exports.DEFAULT_SCOPE = [
|
|
|
73
88
|
];
|
|
74
89
|
/**
|
|
75
90
|
* Path to the story file for function-annotation helpers.
|
|
91
|
+
* This constant centralizes the reference to the canonical documentation story
|
|
92
|
+
* used by these helpers.
|
|
76
93
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
77
94
|
* @req REQ-ANNOTATION-REQUIRED - Provide a single source of truth for the canonical story path used by helper modules
|
|
78
95
|
*/
|
|
@@ -83,8 +100,8 @@ exports.STORY_PATH = "docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md";
|
|
|
83
100
|
exports.EXPORT_PRIORITY_VALUES = ["all", "exported", "non-exported"];
|
|
84
101
|
/**
|
|
85
102
|
* Core helper to report a missing @story annotation for a function-like node.
|
|
86
|
-
*
|
|
87
|
-
* can
|
|
103
|
+
* This reporting utility delegates behavior to injected dependencies so that
|
|
104
|
+
* higher-level helpers can stay small while sharing error-reporting logic.
|
|
88
105
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
89
106
|
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
90
107
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
@@ -118,14 +135,20 @@ function coreReportMissing(deps, context, sourceCode, config) {
|
|
|
118
135
|
],
|
|
119
136
|
});
|
|
120
137
|
}
|
|
121
|
-
catch {
|
|
122
|
-
|
|
138
|
+
catch (error) {
|
|
139
|
+
// Intentionally swallow unexpected helper errors so traceability checks never
|
|
140
|
+
// break lint runs. When TRACEABILITY_DEBUG=1 is set, log a debug message to
|
|
141
|
+
// help diagnose misbehaving helpers in local development without affecting
|
|
142
|
+
// normal CI or production usage.
|
|
143
|
+
if (process.env.TRACEABILITY_DEBUG === "1") {
|
|
144
|
+
console.error("[traceability] coreReportMissing failed for node", error?.message ?? error);
|
|
145
|
+
}
|
|
123
146
|
}
|
|
124
147
|
}
|
|
125
148
|
/**
|
|
126
149
|
* Core helper to report a missing @story annotation for a method-like node.
|
|
127
|
-
*
|
|
128
|
-
* module
|
|
150
|
+
* This method-focused reporting utility uses injected dependencies while
|
|
151
|
+
* keeping this module centered on core error-reporting behavior.
|
|
129
152
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
130
153
|
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
131
154
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
@@ -159,7 +182,13 @@ function coreReportMethod(deps, context, sourceCode, config) {
|
|
|
159
182
|
],
|
|
160
183
|
});
|
|
161
184
|
}
|
|
162
|
-
catch {
|
|
163
|
-
|
|
185
|
+
catch (error) {
|
|
186
|
+
// Intentionally swallow unexpected helper errors so traceability checks never
|
|
187
|
+
// break lint runs. When TRACEABILITY_DEBUG=1 is set, log a debug message to
|
|
188
|
+
// help diagnose misbehaving helpers in local development without affecting
|
|
189
|
+
// normal CI or production usage.
|
|
190
|
+
if (process.env.TRACEABILITY_DEBUG === "1") {
|
|
191
|
+
console.error("[traceability] coreReportMethod failed for node", error?.message ?? error);
|
|
192
|
+
}
|
|
164
193
|
}
|
|
165
194
|
}
|
|
@@ -12,48 +12,36 @@ import { linesBeforeHasStory, parentChainHasStory, fallbackTextBeforeHasStory }
|
|
|
12
12
|
import { getNodeName } from "./require-story-utils";
|
|
13
13
|
import { DEFAULT_SCOPE, EXPORT_PRIORITY_VALUES, STORY_PATH } from "./require-story-core";
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
16
|
-
* When override is a non-empty string, its trimmed value is used.
|
|
17
|
-
* Otherwise, the default template is returned.
|
|
15
|
+
* Shared configuration helpers
|
|
18
16
|
*/
|
|
17
|
+
interface ReportOptions {
|
|
18
|
+
annotationTemplateOverride?: string;
|
|
19
|
+
autoFixToggle?: boolean;
|
|
20
|
+
}
|
|
19
21
|
declare function getAnnotationTemplate(override?: string): string;
|
|
20
|
-
/**
|
|
21
|
-
* Determine whether auto-fix should be applied.
|
|
22
|
-
* Explicit false disables auto-fix; all other values enable it.
|
|
23
|
-
*/
|
|
24
22
|
declare function shouldApplyAutoFix(autoFix: boolean | undefined): boolean;
|
|
25
23
|
/**
|
|
26
24
|
* Determine if a node is in an export declaration
|
|
27
25
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
28
26
|
* @req REQ-ANNOTATION-REQUIRED - Check node ancestry to find export declarations
|
|
29
|
-
* @param {any} node - AST node to check for export ancestry
|
|
30
|
-
* @returns {boolean} true if node is within an export declaration
|
|
31
27
|
*/
|
|
32
28
|
declare function isExportedNode(node: any): boolean;
|
|
33
29
|
/**
|
|
34
30
|
* Check whether the JSDoc associated with node contains @story
|
|
35
31
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
36
32
|
* @req REQ-ANNOTATION-REQUIRED - Extract JSDoc based detection into helper
|
|
37
|
-
* @param {any} sourceCode - ESLint sourceCode object
|
|
38
|
-
* @param {any} node - AST node to inspect
|
|
39
|
-
* @returns {boolean} true if JSDoc contains @story
|
|
40
33
|
*/
|
|
41
34
|
declare function jsdocHasStory(sourceCode: any, node: any): boolean;
|
|
42
35
|
/**
|
|
43
36
|
* Check whether comments returned by sourceCode.getCommentsBefore contain @story
|
|
44
37
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
45
38
|
* @req REQ-ANNOTATION-REQUIRED - Extract comment-before detection into helper
|
|
46
|
-
* @param {any} sourceCode - ESLint sourceCode object
|
|
47
|
-
* @param {any} node - AST node to inspect
|
|
48
|
-
* @returns {boolean} true if any preceding comment contains @story
|
|
49
39
|
*/
|
|
50
40
|
declare function commentsBeforeHasStory(sourceCode: any, node: any): boolean;
|
|
51
41
|
/**
|
|
52
42
|
* Check whether leadingComments attached to the node contain @story
|
|
53
43
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
54
44
|
* @req REQ-ANNOTATION-REQUIRED - Extract leadingComments detection into helper
|
|
55
|
-
* @param {any} node - AST node to inspect
|
|
56
|
-
* @returns {boolean} true if any leading comment contains @story
|
|
57
45
|
*/
|
|
58
46
|
declare function leadingCommentsHasStory(node: any): boolean;
|
|
59
47
|
/**
|
|
@@ -61,43 +49,21 @@ declare function leadingCommentsHasStory(node: any): boolean;
|
|
|
61
49
|
* Consolidates a variety of heuristics through smaller helpers.
|
|
62
50
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
63
51
|
* @req REQ-ANNOTATION-REQUIRED - Detect existing story annotations in JSDoc or comments
|
|
64
|
-
* @param {any} sourceCode - ESLint sourceCode object
|
|
65
|
-
* @param {any} node - AST node to inspect for existing annotations
|
|
66
|
-
* @returns {boolean} true if @story annotation already present
|
|
67
52
|
*/
|
|
68
53
|
declare function hasStoryAnnotation(sourceCode: any, node: any): boolean;
|
|
69
54
|
/**
|
|
70
55
|
* Determine AST node where annotation should be inserted
|
|
71
56
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
72
57
|
* @req REQ-ANNOTATION-REQUIRED - Determine correct insertion target for annotation
|
|
73
|
-
* @param {any} sourceCode - ESLint sourceCode object (unused but kept for parity)
|
|
74
|
-
* @param {any} node - function-like AST node to resolve target for
|
|
75
|
-
* @returns {any} AST node that should receive the annotation
|
|
76
58
|
*/
|
|
77
59
|
declare function resolveTargetNode(sourceCode: any, node: any): any;
|
|
78
60
|
/**
|
|
79
61
|
* Small utility to walk the node and its parents to extract an Identifier or key name.
|
|
80
|
-
* Walks up the parent chain and inspects common properties (id, key, name, Identifier nodes).
|
|
81
62
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
82
63
|
* @req REQ-ANNOTATION-REQUIRED - Walk node and parents to find Identifier/Key name
|
|
83
|
-
* @param {any} node - AST node to extract a name from
|
|
84
|
-
* @returns {string} extracted name or "(anonymous)" when no name found
|
|
85
64
|
*/
|
|
86
65
|
declare function extractName(node: any): string;
|
|
87
|
-
/**
|
|
88
|
-
* Check if this node is within scope and matches exportPriority
|
|
89
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
90
|
-
* @req REQ-ANNOTATION-REQUIRED - Determine whether a node should be processed by rule
|
|
91
|
-
* @param {any} node - AST node to evaluate
|
|
92
|
-
* @param {string[]} scope - allowed node types
|
|
93
|
-
* @param {string} [exportPriority='all'] - 'all' | 'exported' | 'non-exported' (default: 'all')
|
|
94
|
-
* @returns {boolean} whether node should be processed
|
|
95
|
-
*/
|
|
96
66
|
declare function shouldProcessNode(node: any, scope: string[], exportPriority?: string): boolean;
|
|
97
|
-
interface ReportOptions {
|
|
98
|
-
annotationTemplateOverride?: string;
|
|
99
|
-
autoFixToggle?: boolean;
|
|
100
|
-
}
|
|
101
67
|
declare function reportMissing(context: Rule.RuleContext, sourceCode: any, config: {
|
|
102
68
|
node: any;
|
|
103
69
|
target?: any;
|
|
@@ -109,8 +75,8 @@ declare function reportMethod(context: Rule.RuleContext, sourceCode: any, config
|
|
|
109
75
|
options?: ReportOptions;
|
|
110
76
|
}): void;
|
|
111
77
|
/**
|
|
112
|
-
* Explicit exports for require-story-annotation
|
|
78
|
+
* Explicit exports for require-story-annotation helpers.
|
|
113
79
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
114
|
-
* @req REQ-ANNOTATION-REQUIRED
|
|
80
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
115
81
|
*/
|
|
116
82
|
export { STORY_PATH, getAnnotationTemplate, shouldApplyAutoFix, isExportedNode, jsdocHasStory, commentsBeforeHasStory, leadingCommentsHasStory, hasStoryAnnotation, getNodeName, extractName, resolveTargetNode, shouldProcessNode, DEFAULT_SCOPE, EXPORT_PRIORITY_VALUES, linesBeforeHasStory, parentChainHasStory, fallbackTextBeforeHasStory, reportMissing, reportMethod, };
|