Skip to content

Commit c4864e8

Browse files
authored
fix(migrate): transfer comments to the separator (#7014)
1 parent 01c0ab4 commit c4864e8

File tree

4 files changed

+414
-4
lines changed

4 files changed

+414
-4
lines changed

.changeset/grumpy-crews-sneeze.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed [#6516](https://github.com/biomejs/biome/issues/6516): The `biome migrate` command no longer break the member list with trailing comments.

crates/biome_analyze/src/utils.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use biome_rowan::{
22
AstNode, AstSeparatedElement, AstSeparatedList, Language, SyntaxError, SyntaxNode, SyntaxToken,
3-
chain_trivia_pieces,
3+
chain_trivia_pieces, trim_trailing_trivia_pieces,
44
};
55

66
/// Returns `true` if `list` is sorted by `get_key`.
@@ -139,11 +139,17 @@ pub fn fix_separators<'a, L: Language + 'a, N: AstNode<Language = L> + 'a>(
139139
}
140140
} else if i != last_index || needs_last_separator {
141141
// The last node is moved and has no trailing separator.
142-
// Thus we build a new separator and remove its trailing whitespaces.
143-
if let Some(new_node) = node.clone().trim_trailing_trivia() {
142+
// Thus we build a new separator and remove its trailing trivia.
143+
*optional_separator = Some(match node.syntax().last_trailing_trivia() {
144+
// Transfer the trailing trivia to the separator
145+
Some(trivia) => make_separator()
146+
.append_trivia_pieces(trim_trailing_trivia_pieces(trivia.pieces())),
147+
_ => make_separator(),
148+
});
149+
150+
if let Some(new_node) = node.clone().with_trailing_trivia_pieces([]) {
144151
*node = new_node;
145152
}
146-
*optional_separator = Some(make_separator());
147153
}
148154
}
149155
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
3+
"vcs": {
4+
"enabled": false,
5+
"clientKind": "git",
6+
"useIgnoreFile": true,
7+
"defaultBranch": "beta"
8+
},
9+
"formatter": {
10+
"enabled": false, // TODO: enable when https://github.com/biomejs/biome/issues/5879 is implemented
11+
"useEditorconfig": true,
12+
"indentStyle": "space",
13+
"lineWidth": 120
14+
},
15+
"files": {
16+
"ignoreUnknown": true,
17+
// Adding folders to the ignore list is GREAT for performance because it prevents biome from descending into them
18+
// and having to verify whether each individual file is ignored
19+
"ignore": [
20+
"**/*.d.ts",
21+
".github/*",
22+
".vscode/*",
23+
"build/*",
24+
"coverage/*",
25+
"dist/*",
26+
"docs/*",
27+
"node_modules/*",
28+
"public/*",
29+
"typedoc/*",
30+
"src/data/tms.ts" // this file is just too big
31+
]
32+
},
33+
34+
"organizeImports": { "enabled": false }, // TODO: Enable in Biome 2.0
35+
"linter": {
36+
"enabled": true,
37+
"rules": {
38+
"recommended": true, // see https://biomejs.dev/linter/rules/#recommended-rules
39+
"correctness": {
40+
"noUndeclaredVariables": "off", // handled by TypeScript
41+
"noUnusedVariables": "error",
42+
"noSwitchDeclarations": "error",
43+
"noVoidTypeReturn": "warn", // TODO: Refactor and make this an error
44+
"noUnusedImports": "off" // Handled by ESLint until multi-line disable is added (in Biome 2.0)
45+
},
46+
"style": {
47+
"noVar": "error",
48+
"useEnumInitializers": "off", // large enums like Moves/Species would make this cumbersome
49+
"useBlockStatements": "error",
50+
"useConst": "error",
51+
"useImportType": "error",
52+
"noNonNullAssertion": "off", // TODO: fix all non-null assertions in non-test files and turn this on
53+
"noParameterAssign": "off", // TODO: add this?
54+
"useExponentiationOperator": "off", // Too typo-prone and easy to mixup with standard multiplication (* vs **)
55+
"useDefaultParameterLast": "error",
56+
"useSingleVarDeclarator": "off",
57+
"useNodejsImportProtocol": "error",
58+
"useTemplate": "off", // string concatenation is faster: https://stackoverflow.com/questions/29055518/are-es6-template-literals-faster-than-string-concatenation
59+
"noNamespaceImport": "error",
60+
"noInferrableTypes": "off", // Explicit > Implicit
61+
"useConsistentArrayType": "error", // Standardize on `T[]`
62+
"useFilenamingConvention": {
63+
"level": "error",
64+
"options": {
65+
"filenameCases": ["kebab-case"],
66+
"requireAscii": true,
67+
"strictCase": false
68+
}
69+
}
70+
},
71+
"suspicious": {
72+
"noDoubleEquals": "error",
73+
"noExplicitAny": "off", // TODO: Refactor and make this an error
74+
"noAssignInExpressions": "warn",
75+
"noPrototypeBuiltins": "error",
76+
"noFallthroughSwitchClause": "error", // Prevents accidental automatic fallthroughs in switch cases (use disable comment if needed)
77+
"noImplicitAnyLet": "warn", // TODO: Refactor and make this an error
78+
"noRedeclare": "error",
79+
"noGlobalIsNan": "error",
80+
"noAsyncPromiseExecutor": "warn", // TODO: Refactor and make this an error
81+
"useDefaultSwitchClauseLast": "warn" // TODO: make error?
82+
},
83+
"complexity": {
84+
"noExcessiveCognitiveComplexity": "info", // TODO: Refactor and make this an error
85+
"useLiteralKeys": "off",
86+
"noForEach": "off", // Foreach vs for of is not that simple.
87+
"noUselessSwitchCase": "off", // Explicit > Implicit
88+
"noUselessConstructor": "error",
89+
"noBannedTypes": "warn", // TODO: refactor and make an error
90+
"useRegexLiterals": "off" // Was broken for some reason; TODO: re-enable
91+
},
92+
"nursery": {
93+
"noCommonJs": "error"
94+
}
95+
}
96+
},
97+
"javascript": {
98+
"formatter": { "quoteStyle": "double", "arrowParentheses": "always" }
99+
},
100+
"overrides": [
101+
{
102+
"include": ["test/**"],
103+
"javascript": { "globals": [] },
104+
"linter": {
105+
"rules": {
106+
"performance": {
107+
"noDelete": "off" // TODO: evaluate if this is necessary for the test(s) to function
108+
},
109+
"style": {
110+
"noNamespaceImport": "off", // this is required for `vi.spyOn` to work in some tests
111+
"noNonNullAssertion": "off" // tests are able to make assumptions about the game state that normally can't be made
112+
}
113+
}
114+
}
115+
},
116+
{
117+
// This section is to improve the bug tester workflow
118+
"include": ["src/overrides.ts"],
119+
"linter": {
120+
"rules": {
121+
"correctness": {
122+
"noUnusedImports": "off"
123+
},
124+
"style": {
125+
"useImportType": "off"
126+
}
127+
}
128+
}
129+
}
130+
]
131+
}

0 commit comments

Comments
 (0)