@yuu1111/comment-check 2.1.0 → 2.2.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/README.ja.md +7 -8
- package/README.md +8 -15
- package/bin/cli.js +4 -0
- package/dist/cli.js +35 -2
- package/dist/scan.js +29 -1
- package/package.json +3 -2
package/README.ja.md
CHANGED
|
@@ -30,11 +30,18 @@ Checked 42 files: 1 new, 0 resolved, 3 baselined
|
|
|
30
30
|
comment-check --enable japanese-period .
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
+
複数行のcommentを直前の行へ続けず空行で区切るProjectは、もう一つのopt-inのruleを指定する
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
comment-check --enable cramped-comment .
|
|
37
|
+
```
|
|
38
|
+
|
|
33
39
|
## Rules
|
|
34
40
|
|
|
35
41
|
| Rule | 検出対象 |
|
|
36
42
|
|------|---------|
|
|
37
43
|
| `broad-suppression` | `biome-ignore-all`、`@ts-nocheck`、ruleを書いていない `eslint-disable` |
|
|
44
|
+
| `cramped-comment` | 直前の行へ空行なしで続く複数行comment(opt-in) |
|
|
38
45
|
| `undocumented-directive` | 説明の無い `@ts-ignore` と `@ts-expect-error` |
|
|
39
46
|
| `placeholder-comment` | `TODO`、`FIXME`、`XXX`、`HACK` |
|
|
40
47
|
| `separator-comment` | 記号だけで作った装飾comment |
|
|
@@ -49,11 +56,3 @@ comment-check --enable japanese-period .
|
|
|
49
56
|
| `--ignore <path>` | 検査から外すpath 複数指定できる |
|
|
50
57
|
| `--update-baseline` | baselineを現在の検出で置き換える |
|
|
51
58
|
| `--json` | 新規と解消済みの検出をJSONで出力する |
|
|
52
|
-
|
|
53
|
-
## Notes
|
|
54
|
-
|
|
55
|
-
生成物のディレクトリなどProjectが持つpathは `--ignore` で検査から外す 例えば `--ignore src/generated`
|
|
56
|
-
|
|
57
|
-
baselineはrule、file、comment本文をキーにするため、行が動いてもそのcommentを新規とは報告しない Biomeは `biome-ignore` の理由と未使用の抑制を既に扱うため、このcheckerはBiomeが読まないcommentの細部だけを担当する
|
|
58
|
-
|
|
59
|
-
`japanese-period` は `--enable` で指定するまで動かないため、既存Projectの検出結果は変わらない 最初の `。` の位置を行と桁で報告し、句点が複数あっても1 commentにつき1件にまとめ、comment本文は書き換えない
|
package/README.md
CHANGED
|
@@ -32,11 +32,19 @@ opt-in rule:
|
|
|
32
32
|
comment-check --enable japanese-period .
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
A project that keeps a blank line before every multi-line comment names the
|
|
36
|
+
other opt-in rule:
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
comment-check --enable cramped-comment .
|
|
40
|
+
```
|
|
41
|
+
|
|
35
42
|
## Rules
|
|
36
43
|
|
|
37
44
|
| Rule | Detects |
|
|
38
45
|
|------|---------|
|
|
39
46
|
| `broad-suppression` | `biome-ignore-all`, `@ts-nocheck`, and rule-less `eslint-disable` |
|
|
47
|
+
| `cramped-comment` | a multi-line block comment written directly under the previous line (opt-in) |
|
|
40
48
|
| `undocumented-directive` | `@ts-ignore` or `@ts-expect-error` without a description |
|
|
41
49
|
| `placeholder-comment` | `TODO`, `FIXME`, `XXX`, `HACK` |
|
|
42
50
|
| `separator-comment` | decorative comments made only of punctuation |
|
|
@@ -51,18 +59,3 @@ comment-check --enable japanese-period .
|
|
|
51
59
|
| `--ignore <path>` | Path to leave out, repeatable |
|
|
52
60
|
| `--update-baseline` | Replace the baseline with the current findings |
|
|
53
61
|
| `--json` | Print new and resolved findings as JSON |
|
|
54
|
-
|
|
55
|
-
## Notes
|
|
56
|
-
|
|
57
|
-
Generated directories and other paths that the project owns stay out of the
|
|
58
|
-
check through `--ignore`, for example `--ignore src/generated`.
|
|
59
|
-
|
|
60
|
-
The baseline keys on the rule, the file, and the comment text, so moving a line
|
|
61
|
-
does not report the comment as new. Biome already requires a reason on
|
|
62
|
-
`biome-ignore` and reports unused suppressions, so this checker only covers the
|
|
63
|
-
comment trivia that Biome does not read.
|
|
64
|
-
|
|
65
|
-
`japanese-period` stays off until `--enable` names it, so an existing project
|
|
66
|
-
keeps the findings it had. The rule reports the first `。` of a comment at its
|
|
67
|
-
own line and column, reports one finding per comment however many periods it
|
|
68
|
-
holds, and never rewrites the comment.
|
package/bin/cli.js
ADDED
package/dist/cli.js
CHANGED
|
@@ -286,11 +286,13 @@ function extractComments(source) {
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
// src/rules.ts
|
|
289
|
-
var OPT_IN_RULE_IDS = ["japanese-period"];
|
|
289
|
+
var OPT_IN_RULE_IDS = ["cramped-comment", "japanese-period"];
|
|
290
290
|
var PLACEHOLDER_PATTERN = /\b(TODO|FIXME|XXX|HACK)\b/;
|
|
291
291
|
var SEPARATOR_PATTERN = /^[-=*_#~+./\\|]{4,}$/;
|
|
292
292
|
var DIRECTIVE_PATTERN = /^@ts-(?:ignore|expect-error)\b([\s\S]*)$/;
|
|
293
293
|
var JAPANESE_PERIOD = "\u3002";
|
|
294
|
+
var BLOCK_OPENER = /(?:=>|[{(,[])\s*$/;
|
|
295
|
+
var COMMENT_CONTINUATION = /^(?:\/\/|\*|\/\*)/;
|
|
294
296
|
function parseEnabledRules(values) {
|
|
295
297
|
const enabled = [];
|
|
296
298
|
for (const value of values) {
|
|
@@ -307,6 +309,21 @@ function parseEnabledRules(values) {
|
|
|
307
309
|
function findJapanesePeriod(text) {
|
|
308
310
|
return text.indexOf(JAPANESE_PERIOD);
|
|
309
311
|
}
|
|
312
|
+
function isCrampedComment(source, start) {
|
|
313
|
+
const lineStart = source.lastIndexOf(`
|
|
314
|
+
`, start - 1) + 1;
|
|
315
|
+
if (lineStart === 0 || source.slice(lineStart, start).trim() !== "") {
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
const previousEnd = lineStart - 1;
|
|
319
|
+
const previousStart = source.lastIndexOf(`
|
|
320
|
+
`, previousEnd - 1) + 1;
|
|
321
|
+
const previous = source.slice(previousStart, previousEnd).trim();
|
|
322
|
+
if (previous === "" || previous.endsWith("*/")) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
return !(COMMENT_CONTINUATION.test(previous) || BLOCK_OPENER.test(previous));
|
|
326
|
+
}
|
|
310
327
|
function normalizeComment(body) {
|
|
311
328
|
return body.split(`
|
|
312
329
|
`).map((line) => line.replace(/^\s*\*+\s?/, "")).join(" ").replace(/\s+/g, " ").trim();
|
|
@@ -370,6 +387,17 @@ function scanSource(source, file, enabled = []) {
|
|
|
370
387
|
text
|
|
371
388
|
});
|
|
372
389
|
}
|
|
390
|
+
if (enabled.includes("cramped-comment") && comment.kind === "block" && source.slice(comment.start, comment.end).includes(`
|
|
391
|
+
`) && isCrampedComment(source, comment.start)) {
|
|
392
|
+
const position2 = positionAt(source, comment.start);
|
|
393
|
+
findings.push({
|
|
394
|
+
column: position2.column,
|
|
395
|
+
file,
|
|
396
|
+
line: position2.line,
|
|
397
|
+
rule: "cramped-comment",
|
|
398
|
+
text
|
|
399
|
+
});
|
|
400
|
+
}
|
|
373
401
|
if (!enabled.includes("japanese-period")) {
|
|
374
402
|
continue;
|
|
375
403
|
}
|
|
@@ -564,6 +592,7 @@ function runCli(main) {
|
|
|
564
592
|
var DEFAULT_BASELINE = "comment-baseline.json";
|
|
565
593
|
var RULE_MESSAGES = {
|
|
566
594
|
"broad-suppression": "file-wide suppression hides too much",
|
|
595
|
+
"cramped-comment": "a multi-line comment needs a blank line before it",
|
|
567
596
|
"japanese-period": "a Japanese sentence in a comment does not end with a period",
|
|
568
597
|
"placeholder-comment": "placeholder comment should be resolved or tracked",
|
|
569
598
|
"separator-comment": "decorative separator comment adds no information",
|
|
@@ -618,10 +647,14 @@ function main(argv) {
|
|
|
618
647
|
}
|
|
619
648
|
return comparison.added.length > 0 ? 1 : 0;
|
|
620
649
|
}
|
|
621
|
-
|
|
650
|
+
function run() {
|
|
622
651
|
runCli(main);
|
|
623
652
|
}
|
|
653
|
+
if (import.meta.main) {
|
|
654
|
+
run();
|
|
655
|
+
}
|
|
624
656
|
export {
|
|
657
|
+
run,
|
|
625
658
|
parseArguments,
|
|
626
659
|
main
|
|
627
660
|
};
|
package/dist/scan.js
CHANGED
|
@@ -284,11 +284,13 @@ function extractComments(source) {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
// src/rules.ts
|
|
287
|
-
var OPT_IN_RULE_IDS = ["japanese-period"];
|
|
287
|
+
var OPT_IN_RULE_IDS = ["cramped-comment", "japanese-period"];
|
|
288
288
|
var PLACEHOLDER_PATTERN = /\b(TODO|FIXME|XXX|HACK)\b/;
|
|
289
289
|
var SEPARATOR_PATTERN = /^[-=*_#~+./\\|]{4,}$/;
|
|
290
290
|
var DIRECTIVE_PATTERN = /^@ts-(?:ignore|expect-error)\b([\s\S]*)$/;
|
|
291
291
|
var JAPANESE_PERIOD = "\u3002";
|
|
292
|
+
var BLOCK_OPENER = /(?:=>|[{(,[])\s*$/;
|
|
293
|
+
var COMMENT_CONTINUATION = /^(?:\/\/|\*|\/\*)/;
|
|
292
294
|
function parseEnabledRules(values) {
|
|
293
295
|
const enabled = [];
|
|
294
296
|
for (const value of values) {
|
|
@@ -305,6 +307,21 @@ function parseEnabledRules(values) {
|
|
|
305
307
|
function findJapanesePeriod(text) {
|
|
306
308
|
return text.indexOf(JAPANESE_PERIOD);
|
|
307
309
|
}
|
|
310
|
+
function isCrampedComment(source, start) {
|
|
311
|
+
const lineStart = source.lastIndexOf(`
|
|
312
|
+
`, start - 1) + 1;
|
|
313
|
+
if (lineStart === 0 || source.slice(lineStart, start).trim() !== "") {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
const previousEnd = lineStart - 1;
|
|
317
|
+
const previousStart = source.lastIndexOf(`
|
|
318
|
+
`, previousEnd - 1) + 1;
|
|
319
|
+
const previous = source.slice(previousStart, previousEnd).trim();
|
|
320
|
+
if (previous === "" || previous.endsWith("*/")) {
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
return !(COMMENT_CONTINUATION.test(previous) || BLOCK_OPENER.test(previous));
|
|
324
|
+
}
|
|
308
325
|
function normalizeComment(body) {
|
|
309
326
|
return body.split(`
|
|
310
327
|
`).map((line) => line.replace(/^\s*\*+\s?/, "")).join(" ").replace(/\s+/g, " ").trim();
|
|
@@ -368,6 +385,17 @@ function scanSource(source, file, enabled = []) {
|
|
|
368
385
|
text
|
|
369
386
|
});
|
|
370
387
|
}
|
|
388
|
+
if (enabled.includes("cramped-comment") && comment.kind === "block" && source.slice(comment.start, comment.end).includes(`
|
|
389
|
+
`) && isCrampedComment(source, comment.start)) {
|
|
390
|
+
const position2 = positionAt(source, comment.start);
|
|
391
|
+
findings.push({
|
|
392
|
+
column: position2.column,
|
|
393
|
+
file,
|
|
394
|
+
line: position2.line,
|
|
395
|
+
rule: "cramped-comment",
|
|
396
|
+
text
|
|
397
|
+
});
|
|
398
|
+
}
|
|
371
399
|
if (!enabled.includes("japanese-period")) {
|
|
372
400
|
continue;
|
|
373
401
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuu1111/comment-check",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"description": "Shared comment and suppression checker",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,13 +9,14 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"bin": {
|
|
12
|
-
"comment-check": "
|
|
12
|
+
"comment-check": "bin/cli.js"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./dist/scan.js"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"README.ja.md",
|
|
19
|
+
"bin",
|
|
19
20
|
"dist"
|
|
20
21
|
],
|
|
21
22
|
"scripts": {
|