@kongyo2/ts-comment-scanner 1.18.0 → 1.20.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.md CHANGED
@@ -129,7 +129,7 @@ ts-comment-scanner --remove --diff main...HEAD
129
129
 
130
130
  削除した後のコードは次のように整えます。
131
131
 
132
- - コメントだけの行は行ごと、行末のコメントは手前の空白ごと削除します。空行に挟まれたコメント行を消したときは空行を 1 行にまとめ、ファイルやブロックの先頭・末尾でコメントとコードを隔てていた空行は一緒に削除します。
132
+ - コメントだけの行は行ごと、行末のコメントは手前の空白ごと削除します。空行に挟まれたコメント行を消したときは空行を 1 行にまとめ、ファイルやブロックの先頭・末尾でコメントとコードを隔てていた空行は一緒に削除します。import・export のグループの間や、import・require とその次の文の間にあるコメントを消すと間の空行がなくなるときは、空行に置き換えて organizeImports や dprint のグループと、newline-after-import が求める空行を保ちます。
133
133
  - トークンがつながる位置には空白を入れます(`a/* x */b` → `a b`)。コードに挟まれた、改行を含むブロックコメントは改行に置き換え、自動セミコロン挿入による文の区切りを保ちます。
134
134
  - JSX の `{/* … */}` は波かっこごと削除します。波かっこを外すと表示されるテキストが変わる位置では、`{" "}` か `{}` を残します。
135
135
 
@@ -374,7 +374,7 @@ Files deleted within the range are skipped, and renamed files are handled at the
374
374
 
375
375
  The code left behind is tidied up:
376
376
 
377
- - Comment-only lines go entirely, and trailing comments go with the whitespace before them. Removing a comment line between two blank lines leaves one blank line, and at the start or end of the file or of a block, the blank lines that only separated the comment from the code go with it.
377
+ - Comment-only lines go entirely, and trailing comments go with the whitespace before them. Removing a comment line between two blank lines leaves one blank line, and at the start or end of the file or of a block, the blank lines that only separated the comment from the code go with it. Where removing the comments between two groups of imports or exports, or between an import or require and the statement after it, would leave no empty line between them, an empty line takes their place, so organizeImports and dprint keep the groups apart and newline-after-import keeps its empty line.
378
378
  - A space is inserted where tokens would otherwise join (`a/* x */b` → `a b`). A multi-line block comment with code on both sides is replaced with a line break, so automatic semicolon insertion still splits the statements the same way.
379
379
  - A JSX `{/* … */}` goes with its braces. Where dropping the braces would change the rendered text, `{" "}` or `{}` takes their place.
380
380
 
package/dist/imports.d.ts CHANGED
@@ -1,20 +1,33 @@
1
1
  import ts from "typescript";
2
2
  import { type Range } from "./ranges.js";
3
- type ImportSorter = "typescript" | "dprint" | "biome";
3
+ type ImportSorter = "typescript" | "dprint";
4
+ /**
5
+ * The linters whose newline-after-import rule wants an empty line between
6
+ * the imports and the code after them: eslint-plugin-import ("eslint"),
7
+ * whose rule eslint-plugin-import-x and eslint-plugin-import-lite carry
8
+ * over, and oxlint, which ports it ("oxlint").
9
+ */
10
+ type ImportLinter = "eslint" | "oxlint";
4
11
  /**
5
12
  * The gap in front of an import or export declaration that an import sorter
6
13
  * reads to tell whether the declaration starts a new group, which it sorts
7
- * and merges apart from the group before it: the declaration's leading
8
- * trivia, from the end of the token before it to its first token.
14
+ * and merges apart from the group before it, or in front of the statement
15
+ * after an import that a linter reads to tell whether an empty line ends the
16
+ * imports: the statement's leading trivia, from the end of the token before
17
+ * it to its first token — for a class, to its first decorator, which the
18
+ * linters measure from, past an `export` in front of it.
9
19
  */
10
20
  export interface ImportGroupGap extends Range {
11
21
  /** The sorters that start a new group at the declaration after the gap. */
12
22
  splits: ImportSorter[];
23
+ /** The linters that find the empty line they want in the gap. */
24
+ spaced: ImportLinter[];
13
25
  }
14
26
  /**
15
- * The gaps the import sorters read, in document order — one for every
16
- * declaration past the first of a run a sorter sorts, so that the same
17
- * declarations have gaps however the comments around them change:
27
+ * The gaps the import sorters and linters read, in document order — one for
28
+ * every declaration past the first of a run a sorter sorts, and one for every
29
+ * statement a linter measures from the import before it, so that the same
30
+ * statements have gaps however the comments around them change:
18
31
  *
19
32
  * - TypeScript's organizeImports (`groupByNewlineContiguous` in tsc 6 and in
20
33
  * tsc 7's port; tsserver and VS Code, prettier-plugin-organize-imports)
@@ -32,24 +45,24 @@ export interface ImportGroupGap extends Range {
32
45
  * A declaration a `dprint-ignore` comment exempts ends dprint's run, and
33
46
  * stays in it here, which only reads more gaps. `deno fmt`, which runs the
34
47
  * plugin, keeps the order.
35
- * - Biome's organizeImports (`assist/source/organizeImports`, on by default,
36
- * and enforced by `biome check` and `biome ci`) sorts chunks of adjacent
37
- * imports, and of adjacent `export … from`s and local `export { … }`s, in
38
- * the file and in each ambient module, and starts a new chunk at a
39
- * declaration whose leading trivia holds a detached comment (see
40
- * detachedComments); a blank line alone starts none. Bare imports end its
41
- * chunks unless its `sortBareImports` option sorts them too, and are read
42
- * here either way.
48
+ * - The newline-after-import rules (see ImportLinter), with their default
49
+ * options, want the statement after an import declaration, or after an
50
+ * `import x = …` that is not exported, to start two or more lines below
51
+ * the import's end, unless it is one of those itself — so a comment line
52
+ * in between holds one of the lines. In the file's own statements they
53
+ * want the same after a statement holding a require (see holdsRequire),
54
+ * unless the next one holds one too. eslint-plugin-import counts the line
55
+ * breaks its parsers number lines by, U+2028 and U+2029 included, and reads
56
+ * the imports in the bodies of modules and namespaces as well (see
57
+ * moduleBodies); oxlint counts line feeds alone, in the file's own
58
+ * statements.
59
+ *
60
+ * The sorters start a group at an empty line, and the linters find theirs
61
+ * there, which is what removal leaves where it deletes the comments that held
62
+ * a gap open. Biome's organizeImports starts a chunk only at a comment that
63
+ * an empty line follows, never at the empty line alone, so no layout without
64
+ * the comment keeps its chunks apart, and they are not read.
43
65
  */
44
66
  export declare function importGroupGaps(source: string, sourceFile: ts.SourceFile, comments: readonly Range[]): ImportGroupGap[];
45
- /**
46
- * The comments that Biome's organizeImports reads as detached in front of the
47
- * declaration after the gap, and that start a new chunk there
48
- * (`has_detached_leading_comment`): those of the declaration's leading
49
- * trivia that an empty line comes after, outside comments. The leading trivia
50
- * starts at the first line break outside comments; the comments in front of
51
- * it trail the token before the gap.
52
- */
53
- export declare function detachedComments<T extends Range>(source: string, gap: Range, comments: readonly T[]): T[];
54
67
  export {};
55
68
  //# sourceMappingURL=imports.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9D,KAAK,YAAY,GAAG,YAAY,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,KAAK;IAC3C,2EAA2E;IAC3E,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,QAAQ,EAAE,SAAS,KAAK,EAAE,GACzB,cAAc,EAAE,CAwBlB;AAyFD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE,CAmBzG"}
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,aAAa,CAAC;AAE9D,KAAK,YAAY,GAAG,YAAY,GAAG,QAAQ,CAAC;AAE5C;;;;;GAKG;AACH,KAAK,YAAY,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAExC;;;;;;;;GAQG;AACH,MAAM,WAAW,cAAe,SAAQ,KAAK;IAC3C,2EAA2E;IAC3E,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,iEAAiE;IACjE,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,QAAQ,EAAE,SAAS,KAAK,EAAE,GACzB,cAAc,EAAE,CA+BlB"}
package/dist/imports.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import ts from "typescript";
2
- import { LINE_TERMINATOR } from "./lines.js";
2
+ import { LINE_BREAK } from "./lines.js";
3
3
  import { firstIndexAtOrAfter } from "./ranges.js";
4
4
  /**
5
- * The gaps the import sorters read, in document order — one for every
6
- * declaration past the first of a run a sorter sorts, so that the same
7
- * declarations have gaps however the comments around them change:
5
+ * The gaps the import sorters and linters read, in document order — one for
6
+ * every declaration past the first of a run a sorter sorts, and one for every
7
+ * statement a linter measures from the import before it, so that the same
8
+ * statements have gaps however the comments around them change:
8
9
  *
9
10
  * - TypeScript's organizeImports (`groupByNewlineContiguous` in tsc 6 and in
10
11
  * tsc 7's port; tsserver and VS Code, prettier-plugin-organize-imports)
@@ -22,50 +23,209 @@ import { firstIndexAtOrAfter } from "./ranges.js";
22
23
  * A declaration a `dprint-ignore` comment exempts ends dprint's run, and
23
24
  * stays in it here, which only reads more gaps. `deno fmt`, which runs the
24
25
  * plugin, keeps the order.
25
- * - Biome's organizeImports (`assist/source/organizeImports`, on by default,
26
- * and enforced by `biome check` and `biome ci`) sorts chunks of adjacent
27
- * imports, and of adjacent `export … from`s and local `export { … }`s, in
28
- * the file and in each ambient module, and starts a new chunk at a
29
- * declaration whose leading trivia holds a detached comment (see
30
- * detachedComments); a blank line alone starts none. Bare imports end its
31
- * chunks unless its `sortBareImports` option sorts them too, and are read
32
- * here either way.
26
+ * - The newline-after-import rules (see ImportLinter), with their default
27
+ * options, want the statement after an import declaration, or after an
28
+ * `import x = …` that is not exported, to start two or more lines below
29
+ * the import's end, unless it is one of those itself — so a comment line
30
+ * in between holds one of the lines. In the file's own statements they
31
+ * want the same after a statement holding a require (see holdsRequire),
32
+ * unless the next one holds one too. eslint-plugin-import counts the line
33
+ * breaks its parsers number lines by, U+2028 and U+2029 included, and reads
34
+ * the imports in the bodies of modules and namespaces as well (see
35
+ * moduleBodies); oxlint counts line feeds alone, in the file's own
36
+ * statements.
37
+ *
38
+ * The sorters start a group at an empty line, and the linters find theirs
39
+ * there, which is what removal leaves where it deletes the comments that held
40
+ * a gap open. Biome's organizeImports starts a chunk only at a comment that
41
+ * an empty line follows, never at the empty line alone, so no layout without
42
+ * the comment keeps its chunks apart, and they are not read.
33
43
  */
34
44
  export function importGroupGaps(source, sourceFile, comments) {
35
- const readers = new Map();
36
- const read = (declaration, sorter) => {
37
- const sorters = readers.get(declaration) ?? new Set();
38
- sorters.add(sorter);
39
- readers.set(declaration, sorters);
40
- };
45
+ const sorters = new Map();
46
+ const linters = new Map();
41
47
  for (const statements of [sourceFile.statements, ...ambientModuleBodies(sourceFile)]) {
42
- for (const declaration of statements.filter(ts.isImportDeclaration).slice(1))
43
- read(declaration, "typescript");
48
+ for (const declaration of statements.filter(ts.isImportDeclaration).slice(1)) {
49
+ addReader(sorters, declaration, "typescript");
50
+ }
44
51
  }
45
52
  for (const run of exportRuns(sourceFile.statements)) {
46
53
  for (const declaration of run.slice(1))
47
- read(declaration, "typescript");
54
+ addReader(sorters, declaration, "typescript");
48
55
  }
49
- for (const declaration of adjacentOfOneKind(sourceFile.statements, dprintKind))
50
- read(declaration, "dprint");
51
- for (const statements of [sourceFile.statements, ...ambientModuleBodies(sourceFile)]) {
52
- for (const declaration of adjacentOfOneKind(statements, biomeKind))
53
- read(declaration, "biome");
56
+ for (const declaration of adjacentOfOneKind(sourceFile.statements, dprintKind)) {
57
+ addReader(sorters, declaration, "dprint");
54
58
  }
55
- return [...readers]
56
- .sort(([a], [b]) => a.pos - b.pos)
57
- .map(([declaration, sorters]) => {
58
- const gap = { start: declaration.pos, end: declaration.getStart(sourceFile) };
59
- const splits = [...sorters].filter((sorter) => STARTS_GROUP[sorter](source, gap, comments));
60
- return { ...gap, splits };
59
+ for (const statement of statementsAfterImports(sourceFile.statements, true)) {
60
+ addReader(linters, statement, "eslint");
61
+ addReader(linters, statement, "oxlint");
62
+ }
63
+ for (const statements of moduleBodies(sourceFile.statements)) {
64
+ for (const statement of statementsAfterImports(statements, false))
65
+ addReader(linters, statement, "eslint");
66
+ }
67
+ return [...new Set([...sorters.keys(), ...linters.keys()])]
68
+ .sort((a, b) => a.pos - b.pos)
69
+ .map((statement) => {
70
+ const gap = { start: statement.pos, end: gapEnd(statement, sourceFile) };
71
+ const splits = [...(sorters.get(statement) ?? [])].filter((sorter) => STARTS_GROUP[sorter](source, gap, comments));
72
+ const spaced = [...(linters.get(statement) ?? [])].filter((linter) => FINDS_EMPTY_LINE[linter](source, gap));
73
+ return { ...gap, splits, spaced };
61
74
  });
62
75
  }
76
+ /** Records that the tool reads the gap in front of the statement. */
77
+ function addReader(readers, statement, reader) {
78
+ const statementReaders = readers.get(statement) ?? new Set();
79
+ statementReaders.add(reader);
80
+ readers.set(statement, statementReaders);
81
+ }
63
82
  // Whether the sorter starts a new group at the declaration after the gap.
64
83
  const STARTS_GROUP = {
65
84
  typescript: (source, gap, comments) => newLineTrivia(source, gap, comments) >= 2,
66
85
  dprint: (source, gap) => source.slice(gap.start, gap.end).split("\n").length > 2,
67
- biome: (source, gap, comments) => detachedComments(source, gap, comments).length > 0,
68
86
  };
87
+ // Whether the linter finds its empty line in the gap: two line breaks or
88
+ // more, those inside comments included.
89
+ const FINDS_EMPTY_LINE = {
90
+ eslint: (source, gap) => source.slice(gap.start, gap.end).split(LINE_BREAK).length > 2,
91
+ oxlint: (source, gap) => source.slice(gap.start, gap.end).split("\n").length > 2,
92
+ };
93
+ /**
94
+ * Where the gap in front of the statement ends: at its first token, or at the
95
+ * first decorator of a class, which the linters measure the class from —
96
+ * past an `export` in front of it, too.
97
+ */
98
+ function gapEnd(statement, sourceFile) {
99
+ const decorator = ts.isClassDeclaration(statement) ? ts.getDecorators(statement)?.[0] : undefined;
100
+ return (decorator ?? statement).getStart(sourceFile);
101
+ }
102
+ /**
103
+ * The statements the newline-after-import rules measure from the statement
104
+ * before them: the ones after an import that are none (see isImport), and,
105
+ * where `requires` asks, the ones after a statement holding a require that
106
+ * hold none (see holdsRequire).
107
+ */
108
+ function statementsAfterImports(statements, requires) {
109
+ const holding = statements.map((statement) => requires && holdsRequire(statement));
110
+ return statements.filter((statement, index) => index > 0 &&
111
+ ((isImport(statements[index - 1]) && !isImport(statement)) ||
112
+ (holding[index - 1] === true && !holding[index])));
113
+ }
114
+ /** Whether the linters read the statement as an import: an import declaration, or an `import x = …` not exported. */
115
+ function isImport(statement) {
116
+ return (ts.isImportDeclaration(statement) ||
117
+ (ts.isImportEqualsDeclaration(statement) &&
118
+ statement.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ExportKeyword) !== true));
119
+ }
120
+ /**
121
+ * Whether the statement holds a call eslint-plugin-import reads as a require
122
+ * (see isRequireCall) outside the nodes it looks for none in: functions with
123
+ * a body, blocks, object literals and decorators, which it counts as levels.
124
+ * A class static block is no block to it, a method's computed name lies
125
+ * outside its function, an object literal that an assignment destructures
126
+ * into is a pattern, no object (see isAssignmentTarget), and overloads and
127
+ * the other function-likes without a body are no functions, so the defaults
128
+ * of their parameters count, though tsc rejects them. oxlint stops at the
129
+ * same nodes among a call's ancestors and at functions without a body, and
130
+ * takes only the global `require`, called without parentheses around it or
131
+ * its string; the requires it leaves out are read for it all the same, as
132
+ * eslint-plugin-import reads the gaps after them anyway. Walked without
133
+ * recursion, as the deeply nested expressions of generated code need, and
134
+ * over the syntax tree alone, so that removing comments never changes which
135
+ * statements hold one.
136
+ */
137
+ function holdsRequire(statement) {
138
+ const pending = [statement];
139
+ for (let node = pending.pop(); node !== undefined; node = pending.pop()) {
140
+ if (ts.isCallExpression(node) && isRequireCall(node))
141
+ return true;
142
+ if (ts.isFunctionLike(node) && "body" in node && node.body !== undefined) {
143
+ if (node.name !== undefined && ts.isComputedPropertyName(node.name))
144
+ pending.push(node.name);
145
+ continue;
146
+ }
147
+ if ((ts.isBlock(node) && !ts.isClassStaticBlockDeclaration(node.parent)) ||
148
+ (ts.isObjectLiteralExpression(node) && !isAssignmentTarget(node)) ||
149
+ ts.isDecorator(node)) {
150
+ continue;
151
+ }
152
+ // forEachChild stops at a callback that returns a value, so this one returns none.
153
+ ts.forEachChild(node, (child) => {
154
+ pending.push(child);
155
+ });
156
+ }
157
+ return false;
158
+ }
159
+ /**
160
+ * Whether the object literal is what an assignment destructures into — the
161
+ * left of an `=`, the target of a `for … of` or `for … in`, or an element, a
162
+ * rest or a property's value in one — which ESTree reads as a pattern.
163
+ */
164
+ function isAssignmentTarget(literal) {
165
+ let node = literal;
166
+ for (;;) {
167
+ const parent = node.parent;
168
+ if (ts.isBinaryExpression(parent)) {
169
+ return parent.operatorToken.kind === ts.SyntaxKind.EqualsToken && parent.left === node;
170
+ }
171
+ if (ts.isForOfStatement(parent) || ts.isForInStatement(parent))
172
+ return parent.initializer === node;
173
+ if (ts.isArrayLiteralExpression(parent) || ts.isSpreadElement(parent)) {
174
+ node = parent;
175
+ }
176
+ else if (ts.isPropertyAssignment(parent) && parent.initializer === node) {
177
+ node = parent.parent;
178
+ }
179
+ else {
180
+ return false;
181
+ }
182
+ }
183
+ }
184
+ /**
185
+ * Whether the call is a require to eslint-plugin-import: `require` with a
186
+ * single string literal, the parentheses around either part aside, as
187
+ * ESLint's parsers drop them.
188
+ */
189
+ function isRequireCall(call) {
190
+ const callee = unparenthesized(call.expression);
191
+ const [argument] = call.arguments;
192
+ return (ts.isIdentifier(callee) &&
193
+ callee.text === "require" &&
194
+ call.arguments.length === 1 &&
195
+ ts.isStringLiteral(unparenthesized(argument)));
196
+ }
197
+ function unparenthesized(expression) {
198
+ let inner = expression;
199
+ while (ts.isParenthesizedExpression(inner))
200
+ inner = inner.expression;
201
+ return inner;
202
+ }
203
+ /**
204
+ * The statements of every module and namespace body in the file (`declare
205
+ * module "m" { … }`, `declare global { … }`, `namespace N { … }`, the ones
206
+ * nested in them included), whose imports eslint-plugin-import reads too:
207
+ * an `import x = N.y` is at home in a namespace.
208
+ */
209
+ function moduleBodies(statements) {
210
+ const bodies = [];
211
+ const pending = [statements];
212
+ for (let list = pending.pop(); list !== undefined; list = pending.pop()) {
213
+ for (const statement of list) {
214
+ if (!ts.isModuleDeclaration(statement))
215
+ continue;
216
+ // `namespace A.B { … }` nests the declaration of B in A's.
217
+ let body = statement.body;
218
+ while (body !== undefined && ts.isModuleDeclaration(body))
219
+ body = body.body;
220
+ if (body === undefined)
221
+ continue;
222
+ const inner = body.statements;
223
+ bodies.push(inner);
224
+ pending.push(inner);
225
+ }
226
+ }
227
+ return bodies;
228
+ }
69
229
  /** The statements past the first of each run of adjacent ones that `kindOf` puts in one kind. */
70
230
  function adjacentOfOneKind(statements, kindOf) {
71
231
  return statements.filter((statement, index) => {
@@ -76,9 +236,7 @@ function adjacentOfOneKind(statements, kindOf) {
76
236
  /**
77
237
  * The statements of the ambient modules (`declare module "m" { … }`,
78
238
  * `declare global { … }`) at the top of the file, whose imports
79
- * organizeImports sorts too (it leaves their exports in one run), and whose
80
- * imports and exports Biome sorts. Biome sorts those of a `namespace` too,
81
- * where no import or export declaration is valid TypeScript.
239
+ * organizeImports sorts too (it leaves their exports in one run).
82
240
  */
83
241
  function ambientModuleBodies(sourceFile) {
84
242
  return sourceFile.statements.flatMap((statement) => ts.isModuleDeclaration(statement) &&
@@ -124,43 +282,6 @@ function dprintKind(statement) {
124
282
  }
125
283
  return ts.isExportDeclaration(statement) && statement.moduleSpecifier !== undefined ? "exports" : undefined;
126
284
  }
127
- /** What Biome sorts the statement among: imports, exports (`export … from`s and local `export { … }`s), or neither. */
128
- function biomeKind(statement) {
129
- if (ts.isImportDeclaration(statement))
130
- return "imports";
131
- return ts.isExportDeclaration(statement) ? "exports" : undefined;
132
- }
133
- // An empty line as Biome reads one: a line break right after another, of its
134
- // `\r\n`, `\n`, `\r`, U+2028 and U+2029 each, so the CR of a CRLF is never one
135
- // on its own. A line holding spaces or tabs is no empty line to it.
136
- const EMPTY_LINE = /(?:\r\n|\r(?!\n)|[\n\u2028\u2029])[\n\r\u2028\u2029]/;
137
- /**
138
- * The comments that Biome's organizeImports reads as detached in front of the
139
- * declaration after the gap, and that start a new chunk there
140
- * (`has_detached_leading_comment`): those of the declaration's leading
141
- * trivia that an empty line comes after, outside comments. The leading trivia
142
- * starts at the first line break outside comments; the comments in front of
143
- * it trail the token before the gap.
144
- */
145
- export function detachedComments(source, gap, comments) {
146
- const leading = [];
147
- let detached = 0;
148
- let inLeadingTrivia = false;
149
- let from = gap.start;
150
- for (let index = firstIndexAtOrAfter(comments, gap.start, (comment) => comment.start); (comments[index]?.start ?? gap.end) < gap.end; index += 1) {
151
- const comment = comments[index];
152
- const text = source.slice(from, comment.start);
153
- if (EMPTY_LINE.test(text))
154
- detached = leading.length;
155
- inLeadingTrivia ||= LINE_TERMINATOR.test(text);
156
- if (inLeadingTrivia)
157
- leading.push(comment);
158
- from = comment.end;
159
- }
160
- if (EMPTY_LINE.test(source.slice(from, gap.end)))
161
- detached = leading.length;
162
- return leading.slice(0, detached);
163
- }
164
285
  /** The line breaks TypeScript's scanner reads as NewLineTrivia in the gap, past its (sorted) comments. */
165
286
  function newLineTrivia(source, gap, comments) {
166
287
  let count = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"imports.js","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAc,MAAM,aAAa,CAAC;AAe9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,UAAyB,EACzB,QAA0B;IAE1B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAmC,CAAC;IAC3D,MAAM,IAAI,GAAG,CAAC,WAAyB,EAAE,MAAoB,EAAQ,EAAE;QACrE,MAAM,OAAO,GAAG,OAAO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,CAAC,KAAK,CAAC,EAChF,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,EAC7C,KAAK,IAAI,CAAC,EACV,CAAC;QACD,MAAM,OAAO,GAAG,QAAQ,CAAC,KAAK,CAAU,CAAC;QACzC,KAAK,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QACvD,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;AAC9C,CAAC"}
package/dist/remove.d.ts CHANGED
@@ -26,12 +26,10 @@ export interface RemoveResult {
26
26
  * its row decide which node it trails), comments whose removal would shift
27
27
  * code under a next-line directive or join another line to one a directive
28
28
  * covers, or that sit between a directive and the code it reaches past
29
- * them for (or the JSX sibling it applies to), comments whose removal
29
+ * them for (or the JSX sibling it applies to), and comments whose removal
30
30
  * would move a position-dependent directive
31
31
  * (prettier's first-comment pragma, Deno's coverage file pragma, Bun's
32
- * file-start marker) into effect, and comments whose removal would join
33
- * two groups of imports or exports that TypeScript's organizeImports,
34
- * dprint or Biome sorts apart, or split one.
32
+ * file-start marker) into effect.
35
33
  */
36
34
  kept: Comment[];
37
35
  /** Comments excluded from removal by the `shouldRemove` predicate. */
@@ -63,10 +61,12 @@ export interface RemoveResult {
63
61
  * go with it: no pile-up of blank lines where a comment stood between two
64
62
  * of them, and at the start or end of the file or of a block only the blank
65
63
  * lines already against that edge stay.
66
- * - Imports and exports stay in the groups the import sorters read: where
67
- * deleting a comment would join two groups that TypeScript's
68
- * organizeImports, dprint or Biome sorts apart, or split one, the comment
69
- * stays.
64
+ * - Imports and exports stay in the groups TypeScript's organizeImports and
65
+ * dprint sort apart: where deleting the comments between two groups would
66
+ * leave no empty line between them, an empty line takes their place. So it
67
+ * does where deleting the comments after an import or a require would
68
+ * bring the code after it up to the line below, keeping the empty line the
69
+ * newline-after-import rules of eslint-plugin-import and oxlint want.
70
70
  * - A leading byte-order mark is preserved. Reported positions index into the
71
71
  * `source` string exactly as `scanComments(source)` reports them (a BOM
72
72
  * counts as its first character).
@@ -1 +1 @@
1
- {"version":3,"file":"remove.d.ts","sourceRoot":"","sources":["../src/remove.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,wFAAwF;IACxF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,4EAA4E;IAC5E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;IACrC,oFAAoF;IACpF,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CAC9C;AAED,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB;;;;;;;;;;;;;OAaG;IACH,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,sEAAsE;IACtE,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,CA2FxF"}
1
+ {"version":3,"file":"remove.d.ts","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