Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/oxc_formatter/src/print/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ impl<'a> Format<'a> for FormatClassElementWithSemicolon<'a, '_> {
&& match f.options().semicolons {
Semicolons::Always => true,
Semicolons::AsNeeded => self.needs_semicolon(),
};
}
// Don't add semicolon if the element is suppressed (has `oxfmt-ignore`),
// because the suppressed source text already includes the original semicolon.
&& !f.comments().is_suppressed(self.element.span().start);

if needs_semi {
write!(f, [FormatNodeWithoutTrailingComments(self.element), ";"]);
Expand Down
30 changes: 30 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/ignore/issue-18595.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// prettier-ignore on class property should not add extra semicolon
export class Counter {
// prettier-ignore
'count' = $state(0);
constructor() {
this['count'] = $state(0);
}
}

export class Counter2 {
// prettier-ignore
'count' = $state(0)
constructor() {
this['count'] = $state(0);
}
}

export class Counter3 {
'count' = $state(0)
constructor() {
this['count'] = $state(0);
}
}

export class Counter4 {
'count' = $state(0);;
constructor() {
this['count'] = $state(0);
}
}
105 changes: 105 additions & 0 deletions crates/oxc_formatter/tests/fixtures/js/ignore/issue-18595.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
source: crates/oxc_formatter/tests/fixtures/mod.rs
---
==================== Input ====================
// prettier-ignore on class property should not add extra semicolon
export class Counter {
// prettier-ignore
'count' = $state(0);
constructor() {
this['count'] = $state(0);
}
}

export class Counter2 {
// prettier-ignore
'count' = $state(0)
constructor() {
this['count'] = $state(0);
}
}

export class Counter3 {
'count' = $state(0)
constructor() {
this['count'] = $state(0);
}
}

export class Counter4 {
'count' = $state(0);;
constructor() {
this['count'] = $state(0);
}
}

==================== Output ====================
------------------
{ printWidth: 80 }
------------------
// prettier-ignore on class property should not add extra semicolon
export class Counter {
// prettier-ignore
'count' = $state(0);
constructor() {
this["count"] = $state(0);
}
}

export class Counter2 {
// prettier-ignore
'count' = $state(0)
constructor() {
this["count"] = $state(0);
}
}

export class Counter3 {
count = $state(0);
constructor() {
this["count"] = $state(0);
}
}

export class Counter4 {
count = $state(0);
constructor() {
this["count"] = $state(0);
}
}

-------------------
{ printWidth: 100 }
-------------------
// prettier-ignore on class property should not add extra semicolon
export class Counter {
// prettier-ignore
'count' = $state(0);
constructor() {
this["count"] = $state(0);
}
}

export class Counter2 {
// prettier-ignore
'count' = $state(0)
constructor() {
this["count"] = $state(0);
}
}

export class Counter3 {
count = $state(0);
constructor() {
this["count"] = $state(0);
}
}

export class Counter4 {
count = $state(0);
constructor() {
this["count"] = $state(0);
}
}

===================== End =====================
Loading