question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SCSS single-line comments are formatted incorrectly

See original GitHub issue

Important Note: Prettier has nice support for Grid-Template-Areas . See here

The example shows only how to reproduce the issue with single-line comments!

Prettier 1.15.3 Playground link

--parser scss

Input:

// This is SCSS. Prettier moves the area specification up behind the // comment
.grid {
        grid-template-areas: //
          "header header header" //
          "sidebar content content" //
          "footer footer footer";
 }

Output:

// This is SCSS. Prettier moves the area specification up behind the // comment
.grid {
  grid-template-areas: // "header header header"//
    "sidebar content content"//
    "footer footer footer";
}

Expected behavior:

// This is SCSS. Prettier moves the area specification up behind the // comment
.grid {
  grid-template-areas: // 
    "header header header" //
    "sidebar content content" //
    "footer footer footer";
}

There are related (closed) Issues for older Versions:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
jsnajdrcommented, Jan 7, 2019

Why this happens? SCSS code like this:

$a: // b
  c;

is parsed into AST node like this:

{
  type: 'css-decl',
  prop: '$a',
  value: 'c',
  raws: { between: ': // b\n  ' }
}

The inline comment is a part of the raw between string. It is not parsed or interpreted in any way, i.e., Prettier doesn’t know there is a comment. And when printing it, trim is called on the string. That’s how the critical newline gets lost. Result is:

$a: // b c;
1reaction
codepushrcommented, Dec 22, 2019

I’m experiencing the same issues:

$kt-media-breakpoints: (
	// Extra small screen / phone
		xs: 0,
	// Small screen / phone
		sm: 576px,
	// Medium screen / tablet
		md: 768px,
	// Large screen / desktop
		lg: 1024px,
	//1024px,
		// Extra large screen / wide desktop
		xl: 1399px
) !default;

It seems like comments are indenting the next line…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comments - CSS: Cascading Style Sheets - MDN Web Docs
A CSS comment is used to add explanatory notes to the code or to prevent the browser from interpreting specific parts of the...
Read more >
Comments in CSS - CSS-Tricks
Everything enclosed between /* and */ is treated as a comment regardless of how many lines they span, so any other apparent “syntax”...
Read more >
Single Line Comments ( // ) in CSS - Tab Atkins Jr.
However, CSS is missing the "line comment" syntax that those languages have, where everything from // to the end of the line is...
Read more >
wrong auto comments for scss in vscode - Stack Overflow
If you want to comment using the multi-line comment format, you can instead highlight what it is you want to comment, and perform...
Read more >
How to Add Comments in CSS for Yourself or Your Developer
Technically, there is another way to comment-out single lines in CSS in some browsers, by placing a double forward-slash (//) in front of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found