5

Is there a VS Code built-in shortcut or extension that will insert and correctly format starred-block comments, as described in ESLint's rule "multiline-comment-style"?

I am using TypeScript, but this should apply to vanilla JavaScript and other languages as well.

Example

I should be able to highlight multiple uncommented lines as below:

interface CatInfo {
  age: number;
  breed: string;
}
 
type CatName = "miffy" | "boris" | "mordred";
 
~~~~START HIGHLIGHT~~~~
const cats: Record<CatName, CatInfo> = {
  miffy: { age: 10, breed: "Persian" },
  boris: { age: 5, breed: "Maine Coon" },
  mordred: { age: 16, breed: "British Shorthair" },
};
 
cats.boris;
~~~~END HIGHLIGHT~~~~

And use a shortcut to comment all highlighted lines, so they look like this:

/* 
 * const cats: Record<CatName, CatInfo> = {
 *   miffy: { age: 10, breed: "Persian" },
 *   boris: { age: 5, breed: "Maine Coon" },
 *   mordred: { age: 16, breed: "British Shorthair" },
 * };
 *
 * cats.boris;
 */

Anti-examples

I am not looking for Ctrl+/ aka ⌘+/, which would yield:

// const cats: Record<CatName, CatInfo> = {
//   miffy: { age: 10, breed: "Persian" },
//   boris: { age: 5, breed: "Maine Coon" },
//   mordred: { age: 16, breed: "British Shorthair" },
// };

// cats.boris;

I am not looking for Shift+Alt+A aka Shift+⌥+A, which would yield:

/* 
const cats: Record<CatName, CatInfo> = {
  miffy: { age: 10, breed: "Persian" },
  boris: { age: 5, breed: "Maine Coon" },
  mordred: { age: 16, breed: "British Shorthair" },
};

cats.boris;
 */
Mathilda
  • 437
  • 3
  • 11
  • Looks like this has been asked before https://stackoverflow.com/questions/63545917/multiline-comments-in-vs-code to which the answers were only your anti-examples. Seems like its not possible to configure. – Timothy G. Aug 06 '21 at 15:53
  • @timothy If it is not possible with built in features, I am certain it is possible for an extension to do what I am describing. I am hopeful one exists that I am just not seeing – Mathilda Aug 06 '21 at 16:04
  • I have not been successful in finding one that does what you want so far. – Timothy G. Aug 06 '21 at 16:18
  • Is it okay if the starred-block comment characters are flush left? – Mark May 21 '23 at 02:22
  • I just added an answer using your code examples to a similar question at https://stackoverflow.com/a/76384378/836330. See if it works for you. – Mark Jun 01 '23 at 17:36

0 Answers0