@kongyo2/ts-comment-scanner 0.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +208 -0
- package/README.md +130 -17
- package/dist/args.d.ts +16 -1
- package/dist/args.d.ts.map +1 -1
- package/dist/args.js +156 -6
- package/dist/args.js.map +1 -1
- package/dist/directives.d.ts +12 -0
- package/dist/directives.d.ts.map +1 -0
- package/dist/directives.js +133 -0
- package/dist/directives.js.map +1 -0
- package/dist/files.d.ts +12 -0
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +84 -20
- package/dist/files.js.map +1 -1
- package/dist/git.d.ts +10 -0
- package/dist/git.d.ts.map +1 -0
- package/dist/git.js +67 -0
- package/dist/git.js.map +1 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/remove.d.ts +38 -0
- package/dist/remove.d.ts.map +1 -0
- package/dist/remove.js +223 -0
- package/dist/remove.js.map +1 -0
- package/dist/report.d.ts +8 -0
- package/dist/report.d.ts.map +1 -1
- package/dist/report.js +46 -12
- package/dist/report.js.map +1 -1
- package/dist/run.d.ts +1 -1
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +185 -20
- package/dist/run.js.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +31 -7
- package/dist/scanner.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -2
package/dist/scanner.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import ts from "typescript";
|
|
2
|
+
import { detectDirective } from "./directives.js";
|
|
2
3
|
export function scanComments(source, options = {}) {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
4
|
+
const jsx = options.jsx === true;
|
|
5
|
+
const fileName = jsx ? "module.tsx" : "module.ts";
|
|
6
|
+
const scriptKind = jsx ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
|
|
7
|
+
const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true, scriptKind);
|
|
5
8
|
const jsxTextSpans = [];
|
|
6
9
|
const ranges = [];
|
|
7
10
|
const seen = new Set();
|
|
@@ -16,7 +19,10 @@ export function scanComments(source, options = {}) {
|
|
|
16
19
|
}
|
|
17
20
|
};
|
|
18
21
|
const visit = (node) => {
|
|
19
|
-
|
|
22
|
+
// JSDoc nodes start inside the comment text itself; descending into them
|
|
23
|
+
// would hide the comment (e.g. a trailing JSDoc attached to the
|
|
24
|
+
// end-of-file token). Treat them as trivia like any other comment.
|
|
25
|
+
const children = node.getChildren(sourceFile).filter((child) => !ts.isJSDoc(child));
|
|
20
26
|
if (children.length === 0) {
|
|
21
27
|
if (node.kind === ts.SyntaxKind.JsxText) {
|
|
22
28
|
jsxTextSpans.push([node.getFullStart(), node.getEnd()]);
|
|
@@ -31,19 +37,37 @@ export function scanComments(source, options = {}) {
|
|
|
31
37
|
};
|
|
32
38
|
visit(sourceFile);
|
|
33
39
|
const insideJsxText = (pos) => jsxTextSpans.some(([start, end]) => pos >= start && pos < end);
|
|
40
|
+
// File-wide pragmas (check pragmas, triple-slash directives, docblock
|
|
41
|
+
// test-environment pragmas, Deno's *-ignore-file forms) only count before
|
|
42
|
+
// the first token; anywhere later the tools treat them as ordinary text.
|
|
43
|
+
const firstTokenStart = sourceFile.getStart(sourceFile);
|
|
44
|
+
const isHeaderOnlyDirective = (directive) => directive === "@ts-nocheck" ||
|
|
45
|
+
directive === "@ts-check" ||
|
|
46
|
+
directive === "@jest-environment" ||
|
|
47
|
+
directive === "@vitest-environment" ||
|
|
48
|
+
directive.endsWith("-ignore-file") ||
|
|
49
|
+
directive.startsWith("triple-slash-");
|
|
50
|
+
const isActiveDirective = (directive, pos) => !isHeaderOnlyDirective(directive) || pos < firstTokenStart;
|
|
34
51
|
return ranges
|
|
35
52
|
.filter((range) => !insideJsxText(range.pos))
|
|
36
53
|
.sort((a, b) => a.pos - b.pos)
|
|
37
54
|
.map((range) => {
|
|
38
55
|
const kind = range.kind === ts.SyntaxKind.SingleLineCommentTrivia ? "line" : "block";
|
|
39
|
-
const
|
|
56
|
+
const text = source.slice(range.pos, range.end);
|
|
57
|
+
const startPosition = sourceFile.getLineAndCharacterOfPosition(range.pos);
|
|
58
|
+
const endPosition = sourceFile.getLineAndCharacterOfPosition(range.end);
|
|
59
|
+
const detected = detectDirective(kind, text);
|
|
60
|
+
const directive = detected !== undefined && isActiveDirective(detected, range.pos) ? detected : undefined;
|
|
40
61
|
return {
|
|
41
62
|
kind,
|
|
42
|
-
text
|
|
63
|
+
text,
|
|
43
64
|
start: range.pos,
|
|
44
65
|
end: range.end,
|
|
45
|
-
line:
|
|
46
|
-
column:
|
|
66
|
+
line: startPosition.line + 1,
|
|
67
|
+
column: startPosition.character + 1,
|
|
68
|
+
endLine: endPosition.line + 1,
|
|
69
|
+
endColumn: endPosition.character + 1,
|
|
70
|
+
...(directive === undefined ? {} : { directive }),
|
|
47
71
|
};
|
|
48
72
|
});
|
|
49
73
|
}
|
package/dist/scanner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"scanner.js","sourceRoot":"","sources":["../src/scanner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAOlD,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,UAAuB,EAAE;IACpE,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,KAAK,IAAI,CAAC;IACjC,MAAM,QAAQ,GAAG,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC;IAClD,MAAM,UAAU,GAAG,GAAG,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;
|
|
7
7
|
line: number;
|
|
8
8
|
column: number;
|
|
9
|
+
endLine: number;
|
|
10
|
+
endColumn: number;
|
|
11
|
+
/** Canonical name of the compiler/linter directive this comment represents, if any. */
|
|
12
|
+
directive?: string;
|
|
9
13
|
}
|
|
10
14
|
export interface FileScanResult {
|
|
11
15
|
file: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3C,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kongyo2/ts-comment-scanner",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "CLI to detect and
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "CLI to detect, report and safely remove comments across a TypeScript project.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
7
7
|
"comments",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"scanner",
|
|
11
11
|
"ast",
|
|
12
12
|
"code-analysis",
|
|
13
|
+
"comment-removal",
|
|
14
|
+
"code-cleanup",
|
|
15
|
+
"github-actions",
|
|
13
16
|
"kongyo2"
|
|
14
17
|
],
|
|
15
18
|
"license": "MIT",
|
|
@@ -57,10 +60,12 @@
|
|
|
57
60
|
"access": "public"
|
|
58
61
|
},
|
|
59
62
|
"dependencies": {
|
|
63
|
+
"picomatch": "^4.0.4",
|
|
60
64
|
"typescript": "^6.0.3"
|
|
61
65
|
},
|
|
62
66
|
"devDependencies": {
|
|
63
67
|
"@types/node": "^25.9.3",
|
|
68
|
+
"@types/picomatch": "^4.0.3",
|
|
64
69
|
"oxlint": "^1.70.0",
|
|
65
70
|
"prettier": "^3.8.4",
|
|
66
71
|
"vitest": "^4.1.9"
|