Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Spacing around block comments #2447

Closed
MichaReiser opened this issue Apr 14, 2022 · 1 comment · Fixed by #2701
Closed

Spacing around block comments #2447

MichaReiser opened this issue Apr 14, 2022 · 1 comment · Fixed by #2701
Assignees
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness

Comments

@MichaReiser
Copy link
Contributor

MichaReiser commented Apr 14, 2022

Rome always inserts a whitespace character before and after a block comment. Prettier doesn't do so:

  • Leading whitespace: if the comment is directly following a ( token
  • Trailing whitespace: if the comment is immediately followed by a ( or ) token.

Playground

Input

// Prettier doesn't insert a whitespace before a block comment if it is after a `(` token
// Prettier doesn't insert a whitespace character after a block comment if it is immediately followed by a `(` or `)` token

class C {
  name/*comment*/() {
  }
};


({
  name/*comment*/() {
  }
});

class Foo {
  f(/* ... */) {}
  f() /* ... */ {}
  f = (/* ... */) => {};
  static f(/* ... */) {};
  static f = (/* ... */) => {};
  static f = function(/* ... */) {};
  static f = function f(/* ... */) {};
}

let f1 = (/* ... */) => {}
(function (/* ... */) {})(/* ... */)
function f2(/* ... */) {}

const obj = {
  f(/* ... */) {},
  f: (/* ... */) => {},
  f: function(/* ... */) {},
  f: function f(/* ... */) {}
}

f(/* ... */);
f(a, /* ... */);
f(a, /* ... */ b);
f(/* ... */ a, b);

let f3 = () => import(a /* ... */);
let f4 = () => doThing(a, /* ... */ b);

if (code === 92 /* '\' */) {}
if (code === 92 /* '\' */ /* '\' */) {}

if (code === 92) /* '\' */ {}
if (code === 92) { /* '\' */ }

if (
  1
  // Comment
) {
  a;
}

Prettier

// Prettier doesn't insert a whitespace before a block comment if it is after a `(` token
// Prettier doesn't insert a whitespace character after a block comment if it is immediately followed by a `(` or `)` token

class C {
  name /*comment*/() {}
}

({
  name /*comment*/() {},
});

class Foo {
  f(/* ... */) {}
  f() /* ... */ {}
  f = (/* ... */) => {};
  static f(/* ... */) {}
  static f = (/* ... */) => {};
  static f = function (/* ... */) {};
  static f = function f(/* ... */) {};
}

let f1 = (/* ... */) => {};
(function (/* ... */) {})(/* ... */);
function f2(/* ... */) {}

const obj = {
  f(/* ... */) {},
  f: (/* ... */) => {},
  f: function (/* ... */) {},
  f: function f(/* ... */) {},
};

f(/* ... */);
f(a /* ... */);
f(a, /* ... */ b);
f(/* ... */ a, b);

let f3 = () => import(a /* ... */);
let f4 = () => doThing(a, /* ... */ b);

if (code === 92 /* '\' */) {
}
if (code === 92 /* '\' */ /* '\' */) {
}

if (code === 92) {
  /* '\' */
}
if (code === 92) {
  /* '\' */
}

if (
  1
  // Comment
) {
  a;
}

Rome

// Prettier doesn't insert a whitespace before a block comment if it is after a `(` token
// Prettier doesn't insert a whitespace character after a block comment if it is immediately followed by a `(` or `)` token

class C {
  name /*comment*/ () {}
}

({ name /*comment*/ () {} });

class Foo {
  f( /* ... */ ) {}
  f() /* ... */ {}
  f = ( /* ... */ ) => {};
  static f( /* ... */ ) {}
  static f = ( /* ... */ ) => {};
  static f = function ( /* ... */ ) {};
  static f = function f( /* ... */ ) {};
}

let f1 = ( /* ... */ ) => {};
(function ( /* ... */ ) {})( /* ... */ );
function f2( /* ... */ ) {}

const obj = {
  f( /* ... */ ) {},
  f: ( /* ... */ ) => {},
  f: function ( /* ... */ ) {},
  f: function f( /* ... */ ) {},
};

f( /* ... */ );
f(a /* ... */ );
f(a, /* ... */ b);
f( /* ... */ a, b);

let f3 = () => import(a /* ... */ );
let f4 = () => doThing(a, /* ... */ b);

if (code === 92 /* '\' */ ) {
}
if (code === 92 /* '\' */ /* '\' */ ) {
}

if (code === 92) /* '\' */ {
}
if (code === 92) {
  /* '\' */
}

if (
  1
  // Comment
) {
  a;
}

Expected

Rome's formatting to match Prettier's

@MichaReiser MichaReiser changed the title Spacing around inline comments Spacing around block comments Apr 14, 2022
@MichaReiser MichaReiser added the A-Formatter Area: formatter label Apr 14, 2022
@ematipico ematipico self-assigned this Apr 28, 2022
@ematipico ematipico added the I-Normal Implementation: normal understanding of the tool and awareness label May 5, 2022
@MichaReiser
Copy link
Contributor Author

Prettier's rule is more generic than this and overall, uses very different rules for formatting comments than Rome. I'm currently looking into this as part of making our comment formatting more predictable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter I-Normal Implementation: normal understanding of the tool and awareness
Projects
Status: Done
2 participants