Skip to content

Commit 7da5c22

Browse files
committed
refactor(ast): change capitalization of CommentKind variants (#16640)
Pure refactor. "multiline" is OK, but "singleline" is ungrammatical - it should be hyphenated ("single-line"). So rename the `CommentKind` variant to `SingleLineBlock`. Also rename `MultilineBlock` -> `MultiLineBlock` for consistency. Obviously, this is not important. But as changing the variants of `CommentKind` is already a breaking change, it seems like the right moment to nitpick - and avoid getting stuck with it, or having to make another breaking change later.
1 parent 62caae6 commit 7da5c22

File tree

10 files changed

+28
-28
lines changed

10 files changed

+28
-28
lines changed

crates/oxc_ast/src/ast/comment.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ pub enum CommentKind {
1515
/// Line comment
1616
#[default]
1717
Line = 0,
18-
/// Singleline comment
18+
/// Single-line comment
1919
#[estree(rename = "Block")]
20-
SinglelineBlock = 1,
21-
/// Multiline block comment (contains line breaks)
20+
SingleLineBlock = 1,
21+
/// Multi-line block comment (contains line breaks)
2222
#[estree(rename = "Block")]
23-
MultilineBlock = 2,
23+
MultiLineBlock = 2,
2424
}
2525

2626
/// Information about a comment's position relative to a token.
@@ -176,7 +176,7 @@ impl Comment {
176176
pub fn content_span(&self) -> Span {
177177
match self.kind {
178178
CommentKind::Line => Span::new(self.span.start + 2, self.span.end),
179-
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
179+
CommentKind::SingleLineBlock | CommentKind::MultiLineBlock => {
180180
Span::new(self.span.start + 2, self.span.end - 2)
181181
}
182182
}
@@ -188,16 +188,16 @@ impl Comment {
188188
self.kind == CommentKind::Line
189189
}
190190

191-
/// Returns `true` if this is a singleline or multiline block comment.
191+
/// Returns `true` if this is a block comment (either single-line or multi-line).
192192
#[inline]
193193
pub fn is_block(self) -> bool {
194-
matches!(self.kind, CommentKind::SinglelineBlock | CommentKind::MultilineBlock)
194+
matches!(self.kind, CommentKind::SingleLineBlock | CommentKind::MultiLineBlock)
195195
}
196196

197197
/// Returns `true` if this is a multi-line block comment.
198198
#[inline]
199199
pub fn is_multiline_block(self) -> bool {
200-
self.kind == CommentKind::MultilineBlock
200+
self.kind == CommentKind::MultiLineBlock
201201
}
202202

203203
/// Returns `true` if this comment is before a token.

crates/oxc_ast/src/generated/derive_estree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,8 +3233,8 @@ impl ESTree for CommentKind {
32333233
fn serialize<S: Serializer>(&self, serializer: S) {
32343234
match self {
32353235
Self::Line => JsonSafeString("Line").serialize(serializer),
3236-
Self::SinglelineBlock => JsonSafeString("Block").serialize(serializer),
3237-
Self::MultilineBlock => JsonSafeString("Block").serialize(serializer),
3236+
Self::SingleLineBlock => JsonSafeString("Block").serialize(serializer),
3237+
Self::MultiLineBlock => JsonSafeString("Block").serialize(serializer),
32383238
}
32393239
}
32403240
}

crates/oxc_ast/src/trivia.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ mod test {
227227
fn test_is_inside_comment() {
228228
let comments = vec![
229229
Comment::new(0, 4, CommentKind::Line),
230-
Comment::new(10, 20, CommentKind::SinglelineBlock),
230+
Comment::new(10, 20, CommentKind::SingleLineBlock),
231231
]
232232
.into_boxed_slice();
233233

@@ -241,7 +241,7 @@ mod test {
241241
fn test_get_comment_at() {
242242
let comments = vec![
243243
Comment::new(0, 4, CommentKind::Line),
244-
Comment::new(10, 20, CommentKind::SinglelineBlock),
244+
Comment::new(10, 20, CommentKind::SingleLineBlock),
245245
]
246246
.into_boxed_slice();
247247

crates/oxc_codegen/src/comment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ impl Codegen<'_> {
128128
};
129129
let comment_source = comment.span.source_text(source_text);
130130
match comment.kind {
131-
CommentKind::Line | CommentKind::SinglelineBlock => {
131+
CommentKind::Line | CommentKind::SingleLineBlock => {
132132
self.print_str_escaping_script_close_tag(comment_source);
133133
}
134-
CommentKind::MultilineBlock => {
134+
CommentKind::MultiLineBlock => {
135135
for line in LineTerminatorSplitter::new(comment_source) {
136136
if !line.starts_with("/*") {
137137
self.print_indent();

crates/oxc_formatter/src/formatter/trivia.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl<'a> Format<'a> for FormatLeadingComments<'a> {
111111
write!(f, comment);
112112

113113
match comment.kind {
114-
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
114+
CommentKind::SingleLineBlock | CommentKind::MultiLineBlock => {
115115
match f.source_text().lines_after(comment.span.end) {
116116
0 => {
117117
let should_nestle =

crates/oxc_linter/src/rules/typescript/prefer_function_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn check_member(member: &TSSignature, node: &AstNode<'_>, ctx: &LintContext<'_>)
174174
let single_line_comment: String = format!("//{comment}\n");
175175
comments_vec.push(single_line_comment);
176176
}
177-
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
177+
CommentKind::SingleLineBlock | CommentKind::MultiLineBlock => {
178178
let multi_line_comment: String = format!("/*{comment}*/\n");
179179
comments_vec.push(multi_line_comment);
180180
}

crates/oxc_napi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn convert_utf8_to_utf16(
3333
Comment {
3434
r#type: match comment.kind {
3535
CommentKind::Line => String::from("Line"),
36-
CommentKind::SinglelineBlock | CommentKind::MultilineBlock => {
36+
CommentKind::SingleLineBlock | CommentKind::MultiLineBlock => {
3737
String::from("Block")
3838
}
3939
},

crates/oxc_parser/src/lexer/comment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl<'a> Lexer<'a> {
154154
self.trivia_builder.add_block_comment(
155155
self.token.start(),
156156
self.offset(),
157-
CommentKind::SinglelineBlock,
157+
CommentKind::SingleLineBlock,
158158
self.source.whole(),
159159
);
160160
Kind::Skip
@@ -176,7 +176,7 @@ impl<'a> Lexer<'a> {
176176
self.trivia_builder.add_block_comment(
177177
self.token.start(),
178178
self.offset(),
179-
CommentKind::MultilineBlock,
179+
CommentKind::MultiLineBlock,
180180
self.source.whole(),
181181
);
182182
Kind::Skip

crates/oxc_parser/src/lexer/trivia_builder.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ mod test {
334334
let expected = [
335335
Comment {
336336
span: Span::new(9, 24),
337-
kind: CommentKind::SinglelineBlock,
337+
kind: CommentKind::SingleLineBlock,
338338
position: CommentPosition::Leading,
339339
attached_to: 70,
340340
newlines: CommentNewlines::Leading | CommentNewlines::Trailing,
@@ -350,15 +350,15 @@ mod test {
350350
},
351351
Comment {
352352
span: Span::new(54, 69),
353-
kind: CommentKind::SinglelineBlock,
353+
kind: CommentKind::SingleLineBlock,
354354
position: CommentPosition::Leading,
355355
attached_to: 70,
356356
newlines: CommentNewlines::Leading,
357357
content: CommentContent::None,
358358
},
359359
Comment {
360360
span: Span::new(76, 92),
361-
kind: CommentKind::SinglelineBlock,
361+
kind: CommentKind::SingleLineBlock,
362362
position: CommentPosition::Trailing,
363363
attached_to: 0,
364364
newlines: CommentNewlines::None,
@@ -398,15 +398,15 @@ token /* Trailing 1 */
398398
let expected = vec![
399399
Comment {
400400
span: Span::new(20, 35),
401-
kind: CommentKind::SinglelineBlock,
401+
kind: CommentKind::SingleLineBlock,
402402
position: CommentPosition::Leading,
403403
attached_to: 36,
404404
newlines: CommentNewlines::Leading | CommentNewlines::Trailing,
405405
content: CommentContent::None,
406406
},
407407
Comment {
408408
span: Span::new(42, 58),
409-
kind: CommentKind::SinglelineBlock,
409+
kind: CommentKind::SingleLineBlock,
410410
position: CommentPosition::Trailing,
411411
attached_to: 0,
412412
newlines: CommentNewlines::Trailing,
@@ -431,15 +431,15 @@ token /* Trailing 1 */
431431
let expected = vec![
432432
Comment {
433433
span: Span::new(1, 13),
434-
kind: CommentKind::MultilineBlock,
434+
kind: CommentKind::MultiLineBlock,
435435
position: CommentPosition::Leading,
436436
attached_to: 28,
437437
newlines: CommentNewlines::Leading | CommentNewlines::Trailing,
438438
content: CommentContent::None,
439439
},
440440
Comment {
441441
span: Span::new(14, 26),
442-
kind: CommentKind::MultilineBlock,
442+
kind: CommentKind::MultiLineBlock,
443443
position: CommentPosition::Leading,
444444
attached_to: 28,
445445
newlines: CommentNewlines::Leading | CommentNewlines::Trailing,

crates/oxc_parser/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,10 +717,10 @@ mod test {
717717
let source_type = SourceType::default().with_typescript(true);
718718
let sources = [
719719
("// line comment", CommentKind::Line),
720-
("/* line comment */", CommentKind::SinglelineBlock),
720+
("/* line comment */", CommentKind::SingleLineBlock),
721721
(
722722
"type Foo = ( /* Require properties which are not generated automatically. */ 'bar')",
723-
CommentKind::SinglelineBlock,
723+
CommentKind::SingleLineBlock,
724724
),
725725
];
726726
for (source, kind) in sources {

0 commit comments

Comments
 (0)