@kongyo2/ts-comment-scanner 1.8.0 → 1.9.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 +11 -8
- package/README.md +11 -8
- package/dist/directives.d.ts +27 -9
- package/dist/directives.d.ts.map +1 -1
- package/dist/directives.js +351 -153
- package/dist/directives.js.map +1 -1
- package/dist/remove.d.ts +6 -4
- package/dist/remove.d.ts.map +1 -1
- package/dist/remove.js +178 -25
- package/dist/remove.js.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +18 -5
- package/dist/scanner.js.map +1 -1
- package/package.json +1 -1
- package/src/directives.ts +379 -155
- package/src/remove.ts +190 -27
- package/src/scanner.ts +18 -5
package/dist/directives.js
CHANGED
|
@@ -21,60 +21,105 @@ function stylelintDirective(token) {
|
|
|
21
21
|
// `src/utilities/pragma/pragma.evaluate.js`): the docblock keys that
|
|
22
22
|
// --require-pragma looks for and --check-ignore-pragma stops on.
|
|
23
23
|
const FORMAT_PRAGMA_KEYS = new Set(["format", "prettier", "noformat", "noprettier"]);
|
|
24
|
+
// The canonical spelling of each JSX pragma, keyed by its lowercased name.
|
|
25
|
+
const JSX_PRAGMAS = new Map(["jsx", "jsxFrag", "jsxRuntime", "jsxImportSource", "jsxImportSourceTypes"].map((name) => [
|
|
26
|
+
name.toLowerCase(),
|
|
27
|
+
`@${name}`,
|
|
28
|
+
]));
|
|
29
|
+
// typescript-strict-plugin's two pragmas; the capture is the `-ignore` suffix.
|
|
30
|
+
const tsStrictName = (match) => (match[1] === undefined ? "@ts-strict" : "@ts-strict-ignore");
|
|
24
31
|
const RULES = [
|
|
25
|
-
// ESLint
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
// ESLint and oxlint. ESLint 10 takes the label from the trimmed comment value
|
|
33
|
+
// (`[a-z]+(?:-[a-z]+)*` followed by whitespace or the end) and honours only
|
|
34
|
+
// `eslint-disable-line`/`-next-line` in `//` comments; oxlint reads all four
|
|
35
|
+
// commands, and its own prefix, from comments of either kind, under the
|
|
36
|
+
// same boundary. A JSDoc star in front of the label defeats both, and so
|
|
37
|
+
// does a glued suffix (`eslint-disable-foo`, `eslint-disable:foo`).
|
|
38
|
+
{ pattern: /^(?:eslint|oxlint)-(?:disable(?:-next-line|-line)?|enable)(?=\s|$)/, keepStars: true },
|
|
39
|
+
// React Compiler (babel-plugin-react-compiler, and Bun's port of it) skips a
|
|
40
|
+
// component whose comments suppress its react-hooks rules: it searches each
|
|
41
|
+
// comment for `eslint-disable`/`-next-line`/`eslint-enable` followed by one
|
|
42
|
+
// of the rules, anywhere in the text — JSDoc blocks and mid-text mentions
|
|
43
|
+
// included.
|
|
44
|
+
{
|
|
45
|
+
pattern: /eslint-(disable(?:-next-line)?|enable)\s[^]*react-hooks\/(?:exhaustive-deps|rules-of-hooks)/,
|
|
46
|
+
rawText: true,
|
|
47
|
+
name: (match) => `eslint-${match[1]}`,
|
|
48
|
+
},
|
|
49
|
+
// ESLint 10 reports `/* eslint-env */` comments as no longer supported, and
|
|
50
|
+
// ESLint 9's eslintrc mode still applies them; both read block comments
|
|
51
|
+
// only, like the configuration comments below.
|
|
52
|
+
{ pattern: /^eslint-env(?=\s|$)/, blockOnly: true, keepStars: true },
|
|
53
|
+
{ pattern: /^eslint\s+\S/, name: "eslint", blockOnly: true, joinLines: true, keepStars: true },
|
|
29
54
|
{
|
|
30
55
|
pattern: /^(globals?|exported)\s+\S/,
|
|
31
56
|
name: (match) => match[1],
|
|
32
57
|
blockOnly: true,
|
|
33
58
|
joinLines: true,
|
|
59
|
+
keepStars: true,
|
|
34
60
|
},
|
|
35
|
-
// TSLint (legacy)
|
|
36
|
-
|
|
61
|
+
// TSLint (legacy): tslint:(enable|disable)(-line|-next-line)? ending at a
|
|
62
|
+
// colon, whitespace or the end of the comment value.
|
|
63
|
+
{ pattern: /^tslint:(?:enable|disable)(?:-line|-next-line)?(?=:|\s|$)/, keepStars: true },
|
|
37
64
|
// JSHint (legacy): `key: value` options and ignore markers (`jshint
|
|
38
65
|
// esversion: 6`, `jshint ignore:line`) plus `-W###`/`+W###` warning toggles.
|
|
39
66
|
// Requiring those shapes keeps prose like `jshint is unused` ordinary.
|
|
40
67
|
{ pattern: /^jshint\s+(?:[A-Za-z$_][\w$]*\s*:|[-+]W\d+\b)/, name: "jshint", joinLines: true },
|
|
41
|
-
// JSCS (legacy)
|
|
42
|
-
// so the name is normalised to the compact form.
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
// JSCS (legacy) allows whitespace on both sides of the colon (`jscs :
|
|
69
|
+
// enable`), so the name is normalised to the compact form.
|
|
70
|
+
{
|
|
71
|
+
pattern: /^jscs\s*:\s*(disable|enable|ignore)/,
|
|
72
|
+
name: (match) => `jscs:${match[1]}`,
|
|
73
|
+
joinLines: true,
|
|
74
|
+
keepStars: true,
|
|
75
|
+
},
|
|
76
|
+
// JSLint: the directive word must sit immediately after the comment marker
|
|
77
|
+
// with no space (`/*jslint devel*/` works, `/* jslint */` does not) and
|
|
78
|
+
// needs a body, so these match the raw text; `//global` counts too. The
|
|
79
|
+
// whole-line pragmas (`/*jslint-disable*/`, `//jslint-ignore-line`) are
|
|
80
|
+
// exact strings.
|
|
81
|
+
{ pattern: /^\/[/*](jslint|property|global)\s+\S/, rawText: true, name: (match) => match[1] },
|
|
49
82
|
{ pattern: /^\/\*jslint-(disable|enable)\*\/$/, rawText: true, name: (match) => `jslint-${match[1]}` },
|
|
50
83
|
{ pattern: /^\/\/jslint-(ignore-line|quiet)$/, rawText: true, name: (match) => `jslint-${match[1]}` },
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
//
|
|
54
|
-
{ pattern: /^biome-ignore(?:-all|-start|-end)?\b/ },
|
|
55
|
-
// Rome (Biome's predecessor). Case-insensitive keyword with `-` or `_`,
|
|
56
|
-
// then known categories and a mandatory colon — without the colon Rome
|
|
57
|
-
// reported a parse diagnostic and the suppression stayed inert.
|
|
84
|
+
// Biome parses every line of a comment (leading `*`s stripped) that opens
|
|
85
|
+
// with `biome-ignore`; `-all` applies only before the file's first token
|
|
86
|
+
// (anything later is rejected as a misplaced top-level suppression).
|
|
58
87
|
{
|
|
59
|
-
pattern: /^
|
|
88
|
+
pattern: /^biome-ignore(-all|-start|-end)?/,
|
|
89
|
+
name: (match) => `biome-ignore${match[1] ?? ""}`,
|
|
90
|
+
anyLine: true,
|
|
91
|
+
},
|
|
92
|
+
// Rome (Biome's predecessor) used the same line-by-line parser: a
|
|
93
|
+
// case-insensitive keyword with `-` or `_`, then categories (`lint`,
|
|
94
|
+
// `lint/<group>/<rule>`, `format`, `parse`, ...) and a mandatory colon —
|
|
95
|
+
// without the colon Rome reported a parse diagnostic and the suppression
|
|
96
|
+
// stayed inert.
|
|
97
|
+
{
|
|
98
|
+
pattern: /^rome[-_]ignore\s*(?:(?:lint(?:\/[A-Za-z0-9]+){0,2}|parse(?:\/[A-Za-z0-9]+)?|format|organizeImports)(?:\([^)]*\))?\s*)+:/i,
|
|
60
99
|
name: "rome-ignore",
|
|
61
100
|
anyLine: true,
|
|
62
101
|
},
|
|
63
|
-
// Deno
|
|
64
|
-
|
|
102
|
+
// Deno. deno_lint compares the first whitespace-delimited token of the
|
|
103
|
+
// trimmed comment text with the directive, so a JSDoc star in front defeats
|
|
104
|
+
// it; `deno-lint-ignore` may be a block comment (the only form inside JSX
|
|
105
|
+
// children), the file form only a line comment in the header. The coverage
|
|
106
|
+
// directives are line comments compared the same way, and
|
|
107
|
+
// `deno-coverage-ignore-file` only counts as the file's first comment.
|
|
108
|
+
{ pattern: /^deno-lint-ignore(?=\s|$)/, keepStars: true },
|
|
109
|
+
{ pattern: /^deno-(?:lint-ignore-file|coverage-ignore(?:-file|-start|-stop)?)(?=\s|$)/, lineOnly: true },
|
|
65
110
|
// Deno type directives. deno_graph matches them case-insensitively at the
|
|
66
|
-
// comment
|
|
67
|
-
// require quotes.
|
|
68
|
-
{ pattern: /^@deno-types\s*=\s*(?:"[^"
|
|
69
|
-
{ pattern: /^@ts-types\s*=\s*
|
|
70
|
-
{ pattern: /^@ts-self-types\s*=\s*
|
|
111
|
+
// start of the comment text; `@deno-types` accepts a bare specifier, the
|
|
112
|
+
// newer names require quotes. A JSDoc star in front defeats them.
|
|
113
|
+
{ pattern: /^@deno-types\s*=\s*(?:["'][^"']+["']|\S+)/i, keepStars: true, name: "@deno-types" },
|
|
114
|
+
{ pattern: /^@ts-types\s*=\s*["'][^"']+["']/i, keepStars: true, name: "@ts-types" },
|
|
115
|
+
{ pattern: /^@ts-self-types\s*=\s*["'][^"']+["']/i, keepStars: true, name: "@ts-self-types" },
|
|
71
116
|
// stylelint. A configuration comment is recognised from the first
|
|
72
117
|
// whitespace-delimited token of the trimmed comment body alone (see
|
|
73
118
|
// stylelintDirective), so a glued rule list, a suffix, prose before the
|
|
74
119
|
// marker or a different case leave the comment inert — as does a JSDoc star
|
|
75
120
|
// after `/**`, which postcss keeps as comment text (hence keepStars). `//`
|
|
76
121
|
// comments count too: postcss-scss and postcss-less hand stylelint the same
|
|
77
|
-
// trimmed text. Verified against stylelint 17.
|
|
122
|
+
// trimmed text. Verified against stylelint 17.16. A project-specific
|
|
78
123
|
// `configurationComment` prefix cannot be known here, so only the default
|
|
79
124
|
// marker is matched.
|
|
80
125
|
{ pattern: /^\S+/, keepStars: true, name: (match) => stylelintDirective(match[0]) },
|
|
@@ -88,14 +133,21 @@ const RULES = [
|
|
|
88
133
|
// the marker (`/** prettier-ignore */`) leaves the comment ordinary.
|
|
89
134
|
{ pattern: /^prettier-ignore$/, joinLines: true, keepStars: true },
|
|
90
135
|
{ pattern: /^oxfmt-ignore$/, joinLines: true, keepStars: true },
|
|
91
|
-
// dprint
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
//
|
|
95
|
-
|
|
136
|
+
// dprint, and `deno fmt`, which runs dprint's TypeScript plugin with
|
|
137
|
+
// `deno-fmt-ignore`/`deno-fmt-ignore-file` as its comment texts. The file
|
|
138
|
+
// pragma is a starts-with check on the file's leading comments, after only
|
|
139
|
+
// spaces in a `//` comment and any whitespace in a block one, so a tab or a
|
|
140
|
+
// `/**` docblock star defeats it. The node pragma is a substring bounded by
|
|
141
|
+
// non-alphanumerics anywhere in the comment, so a reason may follow — and
|
|
142
|
+
// below the header a stray file pragma still counts as one.
|
|
143
|
+
{
|
|
144
|
+
pattern: /^\/(?:\/ *|\*\s*)(dprint|deno-fmt)-ignore-file/,
|
|
145
|
+
rawText: true,
|
|
146
|
+
name: (match) => `${match[1]}-ignore-file`,
|
|
147
|
+
},
|
|
96
148
|
{
|
|
97
|
-
pattern: /(?:^|[^\p{L}\p{N}])dprint-ignore(?![\p{L}\p{N}])/u,
|
|
98
|
-
name:
|
|
149
|
+
pattern: /(?:^|[^\p{L}\p{N}])(dprint|deno-fmt)-ignore(?![\p{L}\p{N}])/u,
|
|
150
|
+
name: (match) => `${match[1]}-ignore`,
|
|
99
151
|
anyLine: true,
|
|
100
152
|
},
|
|
101
153
|
// Prettier pragma mode (--require-pragma / --check-ignore-pragma). Prettier
|
|
@@ -117,13 +169,24 @@ const RULES = [
|
|
|
117
169
|
// the expression that follows it (`/** @type {Foo} */ (bar)`), the cast
|
|
118
170
|
// tsc itself honours in JavaScript. A `/*` comment or `@typedef` is not one.
|
|
119
171
|
{ pattern: /^\/\*\*[^]*?@(type|satisfies)\b/, rawText: true, blockOnly: true, name: (match) => `@${match[1]}` },
|
|
120
|
-
// prettier-plugin-organize-imports
|
|
121
|
-
//
|
|
122
|
-
|
|
172
|
+
// Import sorting. prettier-plugin-organize-imports skips a file whose text
|
|
173
|
+
// contains `// organize-imports-ignore` or `// tslint:disable:ordered-imports`
|
|
174
|
+
// (single space included, so it matches the raw comment text);
|
|
175
|
+
// @trivago/prettier-plugin-sort-imports, and Bun's port of it, skip one
|
|
176
|
+
// whose leading or import comments start with `sort-imports-ignore` once
|
|
177
|
+
// leading whitespace is trimmed.
|
|
178
|
+
{
|
|
179
|
+
pattern: /\/\/ (?:organize-imports-ignore|tslint:disable:ordered-imports)/,
|
|
180
|
+
rawText: true,
|
|
181
|
+
name: "organize-imports-ignore",
|
|
182
|
+
},
|
|
183
|
+
{ pattern: /^sort-imports-ignore/, keepStars: true, name: "sort-imports-ignore" },
|
|
123
184
|
// js-beautify (legacy): exact-shape block comments with single spaces; only
|
|
124
|
-
// the ignore/preserve pairs have an effect.
|
|
185
|
+
// the ignore/preserve pairs have an effect. The comment ending an ignored
|
|
186
|
+
// range is searched with `\s` instead, so any one whitespace character
|
|
187
|
+
// separates its words.
|
|
125
188
|
{
|
|
126
|
-
pattern: /^\/\* beautify(?: (?:ignore|preserve):(?:start|end))+ \*\/$/,
|
|
189
|
+
pattern: /^\/\*(?: beautify(?: (?:ignore|preserve):(?:start|end))+ |\sbeautify\signore:end\s)\*\/$/,
|
|
127
190
|
rawText: true,
|
|
128
191
|
blockOnly: true,
|
|
129
192
|
name: "beautify",
|
|
@@ -139,9 +202,22 @@ const RULES = [
|
|
|
139
202
|
{ pattern: /^c8\s+ignore\b/, name: "c8-ignore" },
|
|
140
203
|
{ pattern: /^v8\s+ignore\s+([a-z]+)/, name: (match) => `v8-ignore-${match[1]}` },
|
|
141
204
|
{ pattern: /^v8\s+ignore\b/, name: "v8-ignore" },
|
|
205
|
+
// Node core reads `node:coverage` with `ignore next [N]`, `disable` and
|
|
206
|
+
// `enable`; Vitest's v8 provider also takes its `ignore` with `start`/`stop`
|
|
207
|
+
// as a range, which gets a range name like the other tools'
|
|
208
|
+
// (`node:coverage-ignore` stays the counted next-line pragma). Source text
|
|
209
|
+
// must never spell a range pragma out: the v8 provider finds one on any line
|
|
210
|
+
// of this file too, and would drop the rest of it from coverage.
|
|
211
|
+
{
|
|
212
|
+
pattern: /^node:coverage\s+(?:ignore\s+(start|stop)(?=\W|$)|(disable|enable|ignore)\b)/,
|
|
213
|
+
name: (match) => match[1] === undefined ? `node:coverage-${match[2]}` : `node:coverage-ignore-${match[1]}`,
|
|
214
|
+
},
|
|
215
|
+
// ast-v8-to-istanbul finds `ignore start`/`stop` ranges with a plain text
|
|
216
|
+
// search over every line, so those count after any other text as well.
|
|
142
217
|
{
|
|
143
|
-
pattern:
|
|
144
|
-
name: (match) =>
|
|
218
|
+
pattern: /(istanbul|[cv]8|node:coverage)\s+ignore\s+(start|stop)(?=\W|$)/,
|
|
219
|
+
name: (match) => `${match[1]}-ignore-${match[2]}`,
|
|
220
|
+
anyLine: true,
|
|
145
221
|
},
|
|
146
222
|
// type-coverage: substring match in any comment. There is no ignore-file
|
|
147
223
|
// comment — file-level ignores are a CLI option only.
|
|
@@ -151,32 +227,34 @@ const RULES = [
|
|
|
151
227
|
anyLine: true,
|
|
152
228
|
},
|
|
153
229
|
// StrykerJS mutation testing. The instrumenter runs
|
|
154
|
-
// /^\s?Stryker (disable|restore)( next-line)?
|
|
155
|
-
// comment value: at most one space before `Stryker`, single literal
|
|
156
|
-
// and a mandatory mutator list (`all` or names
|
|
230
|
+
// /^\s?Stryker (disable|restore)(?: (next-line))? ([a-zA-Z, ]+)/ against the
|
|
231
|
+
// raw comment value: at most one space before `Stryker`, single literal
|
|
232
|
+
// spaces, and a mandatory mutator list (`all` or names, which may itself
|
|
233
|
+
// open with blanks or a comma) — hence the rawText match.
|
|
157
234
|
{
|
|
158
|
-
pattern: /^\/[/*]\s?Stryker (disable|restore)( next-line)? [a-zA-Z]/,
|
|
235
|
+
pattern: /^\/[/*]\s?Stryker (disable|restore)( next-line)? [a-zA-Z, ]/,
|
|
159
236
|
rawText: true,
|
|
160
237
|
name: (match) => `stryker-${match[1]}${match[2] === undefined ? "" : "-next-line"}`,
|
|
161
238
|
},
|
|
162
239
|
// ts-prune: substring of the closest leading comment above an export.
|
|
163
240
|
{ pattern: /ts-prune-ignore-next/, name: "ts-prune-ignore-next", anyLine: true },
|
|
164
|
-
// typescript-strict-plugin
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
},
|
|
241
|
+
// typescript-strict-plugin. Its CLI splits `//` lines on spaces and compares
|
|
242
|
+
// the tokens, so the pragma may sit anywhere on such a line; its IDE plugin
|
|
243
|
+
// finds it with tsc's TODO-comment scan instead — case-insensitively, right
|
|
244
|
+
// after the comment opener or a line's leading stars, and followed by
|
|
245
|
+
// anything but an ASCII letter or digit (`@ts-strict-ignore: legacy`).
|
|
246
|
+
{ pattern: /(?:^|\s)@ts-strict(-ignore)?(?=\s|$)/, name: tsStrictName, anyLine: true },
|
|
247
|
+
{ pattern: /(?:^[\s*]*|\/\/+\s*|\/\*+\s*)@ts-strict(-ignore)?(?![A-Za-z0-9])/im, rawText: true, name: tsStrictName },
|
|
171
248
|
// Flow. The pragmas live in the file's leading comments. Prettier's babel
|
|
172
249
|
// parser switches to Flow syntax when /@(?:no)?flow\b/ matches anywhere in
|
|
173
250
|
// the text before the first token (isFlowFile in its parse/babel.js), so
|
|
174
251
|
// `foo@flow.com` or `@flow-strict` in a header comment is live to it; Flow's
|
|
175
252
|
// own tokenised pragma (`@flow` as a whole word) is a subset of that.
|
|
176
|
-
// Suppressions must open the comment and take an optional [error-code]
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
// rule:severity
|
|
253
|
+
// Suppressions must open the comment and take an optional [error-code]
|
|
254
|
+
// (Flow now requires one; older releases did not); all four historical
|
|
255
|
+
// suppressors are recognised ($FlowIssue/$FlowIgnore stopped working in
|
|
256
|
+
// Flow 0.281 but still gate older setups). flowlint takes rule:severity
|
|
257
|
+
// pairs.
|
|
180
258
|
{
|
|
181
259
|
pattern: /@(no)?flow\b/,
|
|
182
260
|
name: (match) => (match[1] === undefined ? "@flow" : "@noflow"),
|
|
@@ -186,6 +264,13 @@ const RULES = [
|
|
|
186
264
|
pattern: /^\$Flow(FixMe|ExpectedError|Issue|Ignore)(?:\[[a-z-]+\])?(?![\w-])/,
|
|
187
265
|
name: (match) => `$Flow${match[1]}`,
|
|
188
266
|
},
|
|
267
|
+
// React Compiler also skips a component under a Flow suppression of its
|
|
268
|
+
// `react-rule-*` errors, found anywhere in a comment.
|
|
269
|
+
{
|
|
270
|
+
pattern: /\$(?:(FlowFixMe)\w*|(FlowExpectedError|FlowIssue))\[react-rule/,
|
|
271
|
+
rawText: true,
|
|
272
|
+
name: (match) => `$${match[1] ?? match[2]}`,
|
|
273
|
+
},
|
|
189
274
|
{
|
|
190
275
|
pattern: /^flowlint(-line|-next-line)?\s+[a-z][a-z-]*\s*:\s*(?:off|warn|error)/,
|
|
191
276
|
name: (match) => `flowlint${match[1] ?? ""}`,
|
|
@@ -193,9 +278,15 @@ const RULES = [
|
|
|
193
278
|
},
|
|
194
279
|
// Bundlers. webpack's gate regex requires the colon to follow the key
|
|
195
280
|
// immediately and evaluates the body as an object literal, which JSDoc
|
|
196
|
-
// stars break
|
|
197
|
-
|
|
198
|
-
|
|
281
|
+
// stars break. Turbopack reads the whole trimmed comment as one `key:
|
|
282
|
+
// value` pair instead — blanks before the colon allowed — and honours
|
|
283
|
+
// webpackIgnore and webpackExports as well as its own keys.
|
|
284
|
+
{ pattern: /^webpack[A-Z][A-Za-z]+:/, name: "webpack-magic-comment", keepStars: true },
|
|
285
|
+
{
|
|
286
|
+
pattern: /^(?:turbopack[A-Z][A-Za-z]+|webpack(?:Ignore|Exports))\s*:/,
|
|
287
|
+
name: "turbopack-magic-comment",
|
|
288
|
+
keepStars: true,
|
|
289
|
+
},
|
|
199
290
|
// Vite matches the literal block comment (`/\/\*\s*@vite-ignore\s*\*\//` in
|
|
200
291
|
// importAnalysis), so line comments, suffixes and trailing words stay
|
|
201
292
|
// ordinary.
|
|
@@ -203,40 +294,73 @@ const RULES = [
|
|
|
203
294
|
// Terser/Rollup annotations: a bare substring search over any comment kind,
|
|
204
295
|
// so leading or trailing words keep the annotation active.
|
|
205
296
|
{ pattern: /[#@]__(?:PURE|NO_SIDE_EFFECTS|INLINE|NOINLINE|KEY|MANGLE_PROP)__/, anyLine: true },
|
|
206
|
-
// Million.js: substring of the leading comments of a component
|
|
297
|
+
// Million.js: substring of the leading comments of a component; the skip
|
|
298
|
+
// annotations are compared with the whole trimmed comment value.
|
|
207
299
|
{ pattern: /million-ignore/, name: "million-ignore", anyLine: true },
|
|
208
300
|
{
|
|
209
301
|
pattern: /^@million (jsx-)?skip$/,
|
|
210
302
|
joinLines: true,
|
|
303
|
+
keepStars: true,
|
|
211
304
|
name: (match) => (match[1] === undefined ? "@million-skip" : "@million-jsx-skip"),
|
|
212
305
|
},
|
|
213
306
|
// Nx project graph: substring; the comment has to end on the line right
|
|
214
307
|
// above the import it hides.
|
|
215
308
|
{ pattern: /nx-ignore-next-line/, name: "nx-ignore-next-line", anyLine: true },
|
|
216
|
-
// UnoCSS: include/ignore
|
|
217
|
-
// markers must be their own comment.
|
|
218
|
-
{
|
|
309
|
+
// UnoCSS: include/ignore (and the language server's ide-include) are raw
|
|
310
|
+
// whole-file substring checks; the skip markers must be their own comment.
|
|
311
|
+
{
|
|
312
|
+
pattern: /@unocss-(include|ignore|ide-include)/,
|
|
313
|
+
name: (match) => `@unocss-${match[1]}`,
|
|
314
|
+
anyLine: true,
|
|
315
|
+
},
|
|
219
316
|
{ pattern: /^@unocss-skip-(start|end)\b/, name: (match) => `@unocss-skip-${match[1]}` },
|
|
220
317
|
// Next.js codemod markers: `next build` fails while an unresolved
|
|
221
318
|
// @next-codemod-error comment is attached to the call.
|
|
222
319
|
{ pattern: /@next-codemod-(error|ignore)/, name: (match) => `@next-codemod-${match[1]}`, anyLine: true },
|
|
223
|
-
// Bun: the runtime treats a file
|
|
224
|
-
//
|
|
320
|
+
// Bun: the runtime treats a file whose first line, or whose line right after
|
|
321
|
+
// a `#!` line, starts with the literal bytes `// @bun` (optionally followed
|
|
322
|
+
// by flags like `@bytecode`) as already transpiled.
|
|
225
323
|
{ pattern: /^\/\/ @bun/, rawText: true, lineOnly: true, name: "@bun" },
|
|
226
324
|
// React Fast Refresh / solid-refresh. react-refresh looks for the
|
|
227
325
|
// substring `@refresh reset` in any comment; solid-refresh requires its
|
|
228
|
-
// pragma to be the entire comment
|
|
229
|
-
{
|
|
326
|
+
// pragma to be the entire trimmed comment value.
|
|
327
|
+
{
|
|
328
|
+
pattern: /^@refresh (skip|reload|jsx-skip)$/,
|
|
329
|
+
joinLines: true,
|
|
330
|
+
keepStars: true,
|
|
331
|
+
name: (match) => `@refresh-${match[1]}`,
|
|
332
|
+
},
|
|
230
333
|
{ pattern: /@refresh reset/, name: "@refresh-reset", anyLine: true },
|
|
231
334
|
// Embedded-language tag comments: prettier formats the following template
|
|
232
|
-
// literal when the whole comment is `GraphQL` (graphql-tag-pluck
|
|
233
|
-
// case-insensitively) or `HTML` (prettier's exact ` HTML `
|
|
234
|
-
|
|
335
|
+
// literal when the whole comment is `GraphQL` (graphql-tag-pluck compares
|
|
336
|
+
// the trimmed value case-insensitively) or `HTML` (prettier's exact ` HTML `
|
|
337
|
+
// value).
|
|
338
|
+
{ pattern: /^graphql$/i, joinLines: true, keepStars: true, name: "GraphQL" },
|
|
235
339
|
{ pattern: /^\/\* HTML \*\/$/, rawText: true, blockOnly: true, name: "HTML" },
|
|
236
|
-
// Source maps (`//# sourceMappingURL=`, legacy `//@`, and the block form)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
340
|
+
// Source maps (`//# sourceMappingURL=`, legacy `//@`, and the block form).
|
|
341
|
+
// deno_graph matches the name in any case and allows blanks around the `=`.
|
|
342
|
+
{
|
|
343
|
+
pattern: /^[#@]\s*(source(?:Mapping)?URL)\s*=/i,
|
|
344
|
+
name: (match) => (match[1].toLowerCase() === "sourceurl" ? "sourceURL" : "sourceMappingURL"),
|
|
345
|
+
},
|
|
346
|
+
// JSX pragmas. esbuild and Bun look at every `@` of every comment, Babel at
|
|
347
|
+
// every comment line (its TypeScript plugin anywhere in the text), and the
|
|
348
|
+
// oxc transformer at the leading comments — line comments included, all
|
|
349
|
+
// case-sensitive, all needing whitespace and an argument after the name.
|
|
350
|
+
// tsc lowercases the name of a block-comment pragma, and deno_graph matches
|
|
351
|
+
// `@jsxImportSource(Types)` block comments in any case, so block comments
|
|
352
|
+
// also match case-insensitively.
|
|
353
|
+
{
|
|
354
|
+
pattern: /@(jsx(?:Frag|Runtime|ImportSource)?)\s+\S/,
|
|
355
|
+
joinLines: true,
|
|
356
|
+
name: (match) => `@${match[1]}`,
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
pattern: /@(jsx(?:frag|runtime|importsource(?:types)?)?)\s+\S/i,
|
|
360
|
+
blockOnly: true,
|
|
361
|
+
joinLines: true,
|
|
362
|
+
name: (match) => JSX_PRAGMAS.get(match[1].toLowerCase()),
|
|
363
|
+
},
|
|
240
364
|
// Test runners. Jest reads these from the file's leading docblock, but
|
|
241
365
|
// Vitest (which also honours the @jest- spellings) matches the pragma with
|
|
242
366
|
// a bare regex over the whole file, so any comment kind and position can be
|
|
@@ -251,24 +375,27 @@ const RULES = [
|
|
|
251
375
|
name: (match) => `@${match[1]}`,
|
|
252
376
|
anyLine: true,
|
|
253
377
|
},
|
|
254
|
-
// Vitest module tags
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
//
|
|
259
|
-
|
|
378
|
+
// Vitest module tags: /(\/\/|\*)\s*@module-tag\s+([\w\-/]+)\b/ over the
|
|
379
|
+
// whole file, so the tag has to follow a `//` or a `*` — any of the
|
|
380
|
+
// comment's — with only whitespace between.
|
|
381
|
+
{ pattern: /(?:\/\/|\*)\s*@module-tag\s+[\w/-]*\w/, rawText: true, name: "@module-tag" },
|
|
382
|
+
// SonarQube/SonarCloud (SonarJS): the comment value, minus ONE leading `*`,
|
|
383
|
+
// trimmed, has to START with NOSONAR, case-insensitively; any suffix keeps
|
|
384
|
+
// it active. A star-prefixed line inside a block comment does not count.
|
|
385
|
+
{ pattern: /^\/[/*]\*?\s*NOSONAR/i, rawText: true, name: "NOSONAR" },
|
|
260
386
|
// Semgrep: ` nosemgrep`/` nosem` (case-insensitive) on the finding line or
|
|
261
387
|
// standalone above it, with optional `:`/`=` rule ids. Semgrep itself needs
|
|
262
388
|
// no trailing boundary; the lookahead just keeps words like `nosemantic`
|
|
263
389
|
// ordinary.
|
|
264
390
|
{ pattern: /(?:^|\s)nosem(?:grep)?(?![\w-])/i, name: "nosemgrep", anyLine: true },
|
|
265
|
-
// CodeQL / LGTM alert suppressions: the AlertSuppression
|
|
266
|
-
//
|
|
267
|
-
// `lgtm[...]` matches anywhere in the
|
|
268
|
-
// start or after a `;`; `codeql[...]` requires
|
|
269
|
-
|
|
270
|
-
{ pattern:
|
|
271
|
-
{ pattern:
|
|
391
|
+
// CodeQL / LGTM alert suppressions: the JavaScript AlertSuppression query
|
|
392
|
+
// reads every comment whose text holds no line feed — `//` comments and
|
|
393
|
+
// single-line block comments alike. `lgtm[...]` matches anywhere in the
|
|
394
|
+
// text; bare `lgtm` only at its start or after a `;`; `codeql[...]` requires
|
|
395
|
+
// the bracketed query id.
|
|
396
|
+
{ pattern: /\blgtm\s*\[[^\]]*\]/i, rawText: true, singleLine: true, name: "lgtm" },
|
|
397
|
+
{ pattern: /(?:^\/[/*]|;)\s*lgtm(?!\w)(?!\s*\[)/i, rawText: true, singleLine: true, name: "lgtm" },
|
|
398
|
+
{ pattern: /\bcodeql\s*\[[^\]]*\]/i, rawText: true, singleLine: true, name: "codeql" },
|
|
272
399
|
// DeepSource: bare `skipcq` or `skipcq: CODE1, CODE2`, on the flagged line
|
|
273
400
|
// or standalone above it (it may trail other comment text).
|
|
274
401
|
{ pattern: /\bskipcq(?![\w-])/, name: "skipcq", anyLine: true },
|
|
@@ -297,17 +424,18 @@ const RULES = [
|
|
|
297
424
|
// cspell's legacy emacs-style word list (case-sensitive, colon optional).
|
|
298
425
|
{ pattern: /\bLocalWords(?::|\s+\S)/, name: "LocalWords", anyLine: true },
|
|
299
426
|
// codespell: the tag must follow a punctuation character (the comment
|
|
300
|
-
// marker itself at line starts) with
|
|
427
|
+
// marker itself at line starts), with any whitespace between.
|
|
301
428
|
{
|
|
302
|
-
pattern: /(?:^|[^\w\s]\s
|
|
429
|
+
pattern: /(?:^|[^\w\s]\s*)codespell:ignore(?:(-next-line)\b|(?![\w-]))/,
|
|
303
430
|
name: (match) => `codespell:ignore${match[1] ?? ""}`,
|
|
304
431
|
anyLine: true,
|
|
305
432
|
},
|
|
306
433
|
// JetBrains IDEs. `noinspection` suppressions are line comments in JS/TS
|
|
434
|
+
// (`//\s*noinspection\s+ids`, or `//file:noinspection` for the whole file)
|
|
307
435
|
// and take comma-separated inspection ids; editor-fold markers are
|
|
308
436
|
// substring checks; a `language=` comment injects a language into the
|
|
309
437
|
// literal that follows.
|
|
310
|
-
{ pattern:
|
|
438
|
+
{ pattern: /^\/\/(?:file:)?\s*noinspection\s+[\w.-]+/, rawText: true, lineOnly: true, name: "noinspection" },
|
|
311
439
|
{
|
|
312
440
|
pattern: /<(\/?)editor-fold/,
|
|
313
441
|
name: (match) => (match[1] === "/" ? "editor-fold-end" : "editor-fold"),
|
|
@@ -316,40 +444,66 @@ const RULES = [
|
|
|
316
444
|
{ pattern: /^language=\S/, name: "language-injection" },
|
|
317
445
|
// ReSharper/Rider suppressions (`ReSharper disable once RuleName`, ...).
|
|
318
446
|
{ pattern: /^ReSharper (disable|restore)\b/, lineOnly: true, name: (match) => `resharper-${match[1]}` },
|
|
319
|
-
// Editor folding
|
|
320
|
-
|
|
447
|
+
// Editor folding regions: VS Code folds `// #region` and `// region`
|
|
448
|
+
// comments (`^\s*//\s*#?region\b`), IntelliJ any comment that opens with
|
|
449
|
+
// marker characters, blanks and `region` (`[/*#-]*\s*region.*`).
|
|
450
|
+
{ pattern: /^[/*#-]*\s*#?(region|endregion)\b/, rawText: true, name: (match) => `#${match[1]}` },
|
|
451
|
+
// ESLint's no-fallthrough (in eslint:recommended) accepts a case that falls
|
|
452
|
+
// through when the last comment before the next case matches
|
|
453
|
+
// /falls?\s?through/iu anywhere in its value; oxlint's port and JSHint's
|
|
454
|
+
// `/* falls through */` accept narrower forms of the same words. ESLint's and
|
|
455
|
+
// oxlint's default-case accept a final comment that is exactly `no default`,
|
|
456
|
+
// in any case. Both only count in front of the code those rules read them
|
|
457
|
+
// before (see SWITCH_CLAUSE_TARGETS), so the same words elsewhere are prose.
|
|
458
|
+
{ pattern: /falls?\s?through/iu, rawText: true, name: "fallthrough" },
|
|
459
|
+
{ pattern: /^\/(?:\/\s*no default\s*|\*\s*no default\s*\*\/)$/iu, rawText: true, name: "no-default" },
|
|
321
460
|
];
|
|
322
|
-
//
|
|
461
|
+
// tsc 6 (the JavaScript compiler) reads triple-slash directives with
|
|
462
|
+
// tripleSlashXMLCommentStartRegEx: the directive name (matched
|
|
323
463
|
// case-insensitively) must be followed by whitespace and the tag has to close
|
|
324
|
-
// with
|
|
325
|
-
//
|
|
326
|
-
//
|
|
464
|
+
// with `/>`, and the AMD directives additionally need their mandatory quoted
|
|
465
|
+
// argument, or the pragma is dropped altogether. tsc 7 (the Go port) has no
|
|
466
|
+
// AMD directives left and reads `reference` as a name of letters and hyphens
|
|
467
|
+
// that needs neither: `/// <reference types="node">` is a live type reference
|
|
468
|
+
// to it, and a bare `/// <reference>` a directive it rejects (TS1084).
|
|
327
469
|
const TRIPLE_SLASH = /^\/\/\/\s*<(reference|amd-dependency|amd-module)\s.*?\/>/i;
|
|
328
470
|
const TRIPLE_SLASH_REQUIRED_ARGUMENT = {
|
|
329
471
|
"amd-dependency": /\spath\s*=\s*(?:'[^']*'|"[^"]*")/i,
|
|
330
472
|
"amd-module": /\sname\s*=\s*(?:'[^']*'|"[^"]*")/i,
|
|
331
473
|
};
|
|
332
|
-
|
|
474
|
+
const TS7_TRIPLE_SLASH_REFERENCE = /^\/\/\/[ \t]*<reference(?![A-Za-z-])/i;
|
|
475
|
+
/** The canonical triple-slash directive name the line comment carries, if either tsc would honour it. */
|
|
333
476
|
function tripleSlashDirective(text) {
|
|
334
477
|
const match = TRIPLE_SLASH.exec(text);
|
|
335
|
-
if (
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
return
|
|
478
|
+
if (match) {
|
|
479
|
+
const name = match[1].toLowerCase();
|
|
480
|
+
const requiredArgument = TRIPLE_SLASH_REQUIRED_ARGUMENT[name];
|
|
481
|
+
if (requiredArgument === undefined || requiredArgument.test(text))
|
|
482
|
+
return `triple-slash-${name}`;
|
|
483
|
+
}
|
|
484
|
+
return TS7_TRIPLE_SLASH_REFERENCE.test(text) ? "triple-slash-reference" : undefined;
|
|
342
485
|
}
|
|
343
486
|
const ANY_PLACEMENT = { header: true, firstComment: true, fileStart: true };
|
|
487
|
+
/**
|
|
488
|
+
* The offset at which Bun reads its `// @bun` marker (`has_bun_pragma` in its
|
|
489
|
+
* parser): the start of the text, or, when the text opens with a `#!` line,
|
|
490
|
+
* the character after that line's first `\n` — -1 when the shebang line is
|
|
491
|
+
* the whole text, leaving no place for the marker.
|
|
492
|
+
*/
|
|
493
|
+
export function bunMarkerOffset(text) {
|
|
494
|
+
if (!text.startsWith("#!"))
|
|
495
|
+
return 0;
|
|
496
|
+
const lineFeed = text.indexOf("\n");
|
|
497
|
+
return lineFeed === -1 ? -1 : lineFeed + 1;
|
|
498
|
+
}
|
|
344
499
|
// File-wide pragmas (check pragmas, triple-slash directives, Flow/JSLint
|
|
345
|
-
// header pragmas,
|
|
346
|
-
//
|
|
347
|
-
//
|
|
348
|
-
//
|
|
349
|
-
//
|
|
350
|
-
//
|
|
351
|
-
//
|
|
352
|
-
// (ast-v8-to-istanbul) honour them on any comment in the file. Test
|
|
500
|
+
// header pragmas, Biome's top-level suppression, Deno's lint file pragma,
|
|
501
|
+
// dprint/deno fmt file pragmas and @ts-self-types) only count before the first
|
|
502
|
+
// token; anywhere later the tools treat them as ordinary text — or, for a
|
|
503
|
+
// stray dprint/deno fmt file pragma, as the node pragma it contains, which the
|
|
504
|
+
// next rule then reports. Coverage file pragmas (`istanbul ignore file`,
|
|
505
|
+
// `c8/v8 ignore file`) are NOT gated: istanbul-lib-instrument and Vitest's v8
|
|
506
|
+
// provider (ast-v8-to-istanbul) honour them on any comment in the file. Test
|
|
353
507
|
// environment pragmas are not gated either: Vitest matches them (including
|
|
354
508
|
// the @jest- spellings) with a regex over the whole file, and neither are
|
|
355
509
|
// @ts-strict pragmas (typescript-strict-plugin scans every line). @jsx
|
|
@@ -363,40 +517,73 @@ const HEADER_ONLY_DIRECTIVES = new Set([
|
|
|
363
517
|
"@ts-self-types",
|
|
364
518
|
"jslint",
|
|
365
519
|
"property",
|
|
520
|
+
"biome-ignore-all",
|
|
521
|
+
"deno-lint-ignore-file",
|
|
522
|
+
"dprint-ignore-file",
|
|
523
|
+
"deno-fmt-ignore-file",
|
|
366
524
|
]);
|
|
367
525
|
// Prettier's pragma mode reads the pragma through jest-docblock, which only
|
|
368
526
|
// ever extracts the file's FIRST comment (a shebang may precede it) — a
|
|
369
527
|
// docblock behind any other comment is ignored. Cross-checked against the
|
|
370
|
-
// real prettier in directives.prettier.test.ts.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
528
|
+
// real prettier in directives.prettier.test.ts. Deno's coverage reads its
|
|
529
|
+
// file pragma from the first comment alone, too.
|
|
530
|
+
const FIRST_COMMENT_ONLY_DIRECTIVES = new Set([
|
|
531
|
+
"@format",
|
|
532
|
+
"@noformat",
|
|
533
|
+
"@prettier",
|
|
534
|
+
"@noprettier",
|
|
535
|
+
"deno-coverage-ignore-file",
|
|
536
|
+
]);
|
|
537
|
+
// Bun treats a file as pre-transpiled only when `// @bun` opens it or the
|
|
538
|
+
// line after its shebang; anywhere else the marker is inert.
|
|
374
539
|
const FILE_START_ONLY_DIRECTIVES = new Set(["@bun"]);
|
|
540
|
+
// ESLint's no-fallthrough reads the last comment before the next `case` or
|
|
541
|
+
// `default` (or before a case block's closing brace), and default-case the
|
|
542
|
+
// last one before the switch's closing brace; in front of anything else the
|
|
543
|
+
// same words are prose.
|
|
544
|
+
const SWITCH_CLAUSE_TARGETS = new Map([
|
|
545
|
+
["fallthrough", new Set(["case", "default", "}"])],
|
|
546
|
+
["no-default", new Set(["}"])],
|
|
547
|
+
]);
|
|
375
548
|
function isActiveAt(name, placement) {
|
|
376
549
|
if (FILE_START_ONLY_DIRECTIVES.has(name))
|
|
377
550
|
return placement.fileStart;
|
|
378
551
|
if (FIRST_COMMENT_ONLY_DIRECTIVES.has(name))
|
|
379
552
|
return placement.firstComment;
|
|
380
|
-
if (HEADER_ONLY_DIRECTIVES.has(name) ||
|
|
381
|
-
(name.startsWith("deno-") && name.endsWith("-ignore-file")) ||
|
|
382
|
-
name.startsWith("triple-slash-")) {
|
|
553
|
+
if (HEADER_ONLY_DIRECTIVES.has(name) || name.startsWith("triple-slash-")) {
|
|
383
554
|
return placement.header;
|
|
384
555
|
}
|
|
556
|
+
const targets = SWITCH_CLAUSE_TARGETS.get(name);
|
|
557
|
+
if (targets !== undefined)
|
|
558
|
+
return placement.nextToken === undefined || targets.has(placement.nextToken);
|
|
385
559
|
return true;
|
|
386
560
|
}
|
|
387
|
-
// Mirrors the TypeScript
|
|
388
|
-
// against tsc
|
|
389
|
-
//
|
|
390
|
-
//
|
|
391
|
-
// whitespace
|
|
392
|
-
//
|
|
393
|
-
const TS_LINE_SUPPRESSION =
|
|
394
|
-
|
|
561
|
+
// Mirrors the TypeScript compilers' own comment-directive matching, verified
|
|
562
|
+
// against tsc 6.0 and 7.0 (a comment counts when either honours it). The
|
|
563
|
+
// suppression directives are case-sensitive PREFIX matches (`@ts-ignoreTODO`
|
|
564
|
+
// is active). In `//` comments tsc 6 allows one extra slash and any
|
|
565
|
+
// whitespace before the `@`, tsc 7 any number of extra slashes but only
|
|
566
|
+
// spaces and tabs — so `//// @ts-ignore` is live to tsc 7 alone.
|
|
567
|
+
const TS_LINE_SUPPRESSION = /^\/\/(?:\/?\s*|\/*[ \t]*)@ts-(ignore|expect-error)/;
|
|
568
|
+
// The file-wide check pragmas go through each compiler's case-insensitive
|
|
569
|
+
// pragma parser. tsc 6 reads the name up to the next whitespace or colon
|
|
570
|
+
// (`@ts-nocheck:reason` is active, `@ts-nocheckfoo` and `@ts-nocheck-foo` are
|
|
571
|
+
// not); tsc 7 reads it as a run of ASCII letters and hyphens after spaces and
|
|
572
|
+
// tabs only, so `@ts-nocheck.` and `@ts-nocheck1` are active to it.
|
|
573
|
+
const TS6_LINE_CHECK_PRAGMA = /^\/\/\/?\s*@ts-(nocheck|check)(?=[^\S\r\n]|:|$)/i;
|
|
574
|
+
const TS7_LINE_CHECK_PRAGMA = /^\/\/\/?[ \t]*@ts-(nocheck|check)(?![A-Za-z-])/i;
|
|
395
575
|
// Block comments: only the suppression directives, and only on the comment's
|
|
396
576
|
// literal last line (`*/` included), even when that line is otherwise blank.
|
|
397
577
|
// tsc trims the line and then allows one run of `/`/`*` characters before the
|
|
398
578
|
// directive, so `* @ts-ignore */` counts but `/ * @ts-ignore */` does not.
|
|
399
579
|
const TS_BLOCK_SUPPRESSION = /^\s*[/*]*\s*@ts-(ignore|expect-error)/;
|
|
580
|
+
// Flow, which also checks TypeScript files, honours the same suppressions
|
|
581
|
+
// there with its own matching: the directive must OPEN the comment value,
|
|
582
|
+
// after any spaces, tabs, line breaks and stars — in a block comment
|
|
583
|
+
// whatever its last line holds — and end where an identifier would
|
|
584
|
+
// (`@ts-ignore: reason` counts, `@ts-ignoree` does not).
|
|
585
|
+
const FLOW_LINE_SUPPRESSION = /^\/\/[ \t*]*@ts-(ignore|expect-error)(?![\w-])/;
|
|
586
|
+
const FLOW_BLOCK_SUPPRESSION = /^\/\*[ \t\r\n*]*@ts-(ignore|expect-error)(?![\w-])/;
|
|
400
587
|
/**
|
|
401
588
|
* Returns the canonical name of the compiler/linter/tooling directive the
|
|
402
589
|
* comment represents, or `undefined` when the comment is an ordinary comment.
|
|
@@ -413,11 +600,11 @@ export function detectDirective(kind, text, placement) {
|
|
|
413
600
|
const tripleSlash = tripleSlashDirective(text);
|
|
414
601
|
if (tripleSlash !== undefined && isActiveAt(tripleSlash, at))
|
|
415
602
|
return tripleSlash;
|
|
416
|
-
const suppression = TS_LINE_SUPPRESSION.exec(text);
|
|
603
|
+
const suppression = TS_LINE_SUPPRESSION.exec(text) ?? FLOW_LINE_SUPPRESSION.exec(text);
|
|
417
604
|
if (suppression) {
|
|
418
605
|
return `@ts-${suppression[1]}`;
|
|
419
606
|
}
|
|
420
|
-
const checkPragma =
|
|
607
|
+
const checkPragma = TS6_LINE_CHECK_PRAGMA.exec(text) ?? TS7_LINE_CHECK_PRAGMA.exec(text);
|
|
421
608
|
if (checkPragma) {
|
|
422
609
|
const name = `@ts-${checkPragma[1]?.toLowerCase()}`;
|
|
423
610
|
if (isActiveAt(name, at))
|
|
@@ -425,26 +612,38 @@ export function detectDirective(kind, text, placement) {
|
|
|
425
612
|
}
|
|
426
613
|
}
|
|
427
614
|
else {
|
|
428
|
-
const suppression = TS_BLOCK_SUPPRESSION.exec(lastLine(text));
|
|
615
|
+
const suppression = TS_BLOCK_SUPPRESSION.exec(lastLine(text)) ?? FLOW_BLOCK_SUPPRESSION.exec(text);
|
|
429
616
|
if (suppression) {
|
|
430
617
|
return `@ts-${suppression[1]}`;
|
|
431
618
|
}
|
|
432
619
|
}
|
|
433
|
-
|
|
434
|
-
|
|
620
|
+
// A directive that opens the comment names it, however the comment goes on
|
|
621
|
+
// to mention other tools' markers (`// nosemgrep: ... @jsx h` stays a
|
|
622
|
+
// Semgrep suppression, with the next-line shield that goes with it); only
|
|
623
|
+
// without one does a marker found after other text name the comment.
|
|
624
|
+
let mention;
|
|
625
|
+
for (const { name, opening } of ruleMatches(kind, text)) {
|
|
626
|
+
if (!isActiveAt(name, at))
|
|
627
|
+
continue;
|
|
628
|
+
if (opening)
|
|
435
629
|
return name;
|
|
630
|
+
mention ??= name;
|
|
436
631
|
}
|
|
437
|
-
return
|
|
632
|
+
return mention;
|
|
438
633
|
}
|
|
439
|
-
/** Directive names of every rule the comment matches, in rule order. */
|
|
440
634
|
function* ruleMatches(kind, text) {
|
|
441
635
|
const lines = contentLines(kind, text, false);
|
|
442
636
|
const literalLines = kind === "block" ? contentLines(kind, text, true) : lines;
|
|
637
|
+
// Where the raw text's content begins, past the comment opener, stars and
|
|
638
|
+
// blanks.
|
|
639
|
+
const contentStart = /^[/*\s]*/.exec(text)[0].length;
|
|
443
640
|
for (const rule of RULES) {
|
|
444
641
|
if (rule.blockOnly === true && kind !== "block")
|
|
445
642
|
continue;
|
|
446
643
|
if (rule.lineOnly === true && kind !== "line")
|
|
447
644
|
continue;
|
|
645
|
+
if (rule.singleLine === true && text.includes("\n"))
|
|
646
|
+
continue;
|
|
448
647
|
if (rule.notDocblock === true && kind === "block" && text.startsWith("/**"))
|
|
449
648
|
continue;
|
|
450
649
|
const ruleLines = rule.keepStars === true ? literalLines : lines;
|
|
@@ -455,33 +654,32 @@ function* ruleMatches(kind, text) {
|
|
|
455
654
|
: rule.joinLines === true
|
|
456
655
|
? [ruleLines.join(" ")]
|
|
457
656
|
: ruleLines.slice(0, 1);
|
|
458
|
-
for (const line of candidates) {
|
|
657
|
+
for (const [index, line] of candidates.entries()) {
|
|
459
658
|
const match = rule.pattern.exec(line);
|
|
460
659
|
if (!match)
|
|
461
660
|
continue;
|
|
661
|
+
const opening = rule.rawText === true ? match.index <= contentStart : index === 0 && match.index === 0;
|
|
462
662
|
const name = typeof rule.name === "string" ? rule.name : typeof rule.name === "function" ? rule.name(match) : match[0];
|
|
463
663
|
if (name === undefined)
|
|
464
664
|
continue;
|
|
465
|
-
|
|
466
|
-
yield name;
|
|
467
|
-
else
|
|
468
|
-
yield* name;
|
|
665
|
+
for (const each of typeof name === "string" ? [name] : name)
|
|
666
|
+
yield { name: each, opening };
|
|
469
667
|
}
|
|
470
668
|
}
|
|
471
669
|
}
|
|
472
670
|
/**
|
|
473
|
-
* The position-dependent directives (prettier's first-comment pragmas,
|
|
474
|
-
* file-start marker) the comment carries that are
|
|
475
|
-
* placement, sorted. Unlike detectDirective — which
|
|
476
|
-
* name — this sees through masking: an eslint config
|
|
477
|
-
* `@format` pragma, and whether that pragma is live
|
|
478
|
-
* name an earlier rule already claimed. Only
|
|
479
|
-
* gates are consulted; header-gated directives
|
|
480
|
-
* the comments around them change.
|
|
671
|
+
* The position-dependent directives (prettier's first-comment pragmas, Deno's
|
|
672
|
+
* coverage file pragma, Bun's file-start marker) the comment carries that are
|
|
673
|
+
* active at the given placement, sorted. Unlike detectDirective — which
|
|
674
|
+
* reports one canonical name — this sees through masking: an eslint config
|
|
675
|
+
* block can also hold a `@format` pragma, and whether that pragma is live
|
|
676
|
+
* must not hide behind the name an earlier rule already claimed. Only
|
|
677
|
+
* first-comment and file-start gates are consulted; header-gated directives
|
|
678
|
+
* cannot change activation when the comments around them change.
|
|
481
679
|
*/
|
|
482
680
|
export function activePositionalDirectives(kind, text, placement) {
|
|
483
681
|
const names = new Set();
|
|
484
|
-
for (const name of ruleMatches(kind, text)) {
|
|
682
|
+
for (const { name } of ruleMatches(kind, text)) {
|
|
485
683
|
if (!FIRST_COMMENT_ONLY_DIRECTIVES.has(name) && !FILE_START_ONLY_DIRECTIVES.has(name))
|
|
486
684
|
continue;
|
|
487
685
|
if (isActiveAt(name, placement))
|
|
@@ -505,8 +703,8 @@ export function isLegalComment(text) {
|
|
|
505
703
|
/**
|
|
506
704
|
* Non-empty content lines of the comment, with comment markers stripped.
|
|
507
705
|
* For line comments only the `//` marker itself is removed: extra slashes or
|
|
508
|
-
* stars are content, so
|
|
509
|
-
* ordinary. JSDoc-style `*` prefixes are stripped for block comments unless
|
|
706
|
+
* stars are content, so `/// eslint-disable-line` and `// * prettier-ignore`
|
|
707
|
+
* stay ordinary. JSDoc-style `*` prefixes are stripped for block comments unless
|
|
510
708
|
* `keepStars` asks for the literal lines (for tools that compare the raw
|
|
511
709
|
* comment value, where a leading `*` defeats the directive).
|
|
512
710
|
*/
|