Skip to content

// comments in SASS selectors break formatting. #3647

Closed

Description

@ryanpcmcquen

Prettier 1.9.2
Playground link

--parser scss
--tab-width 4

Input:

// This is SCSS. Prettier moves `.bar` up to the the same line as 'Comment.'.
.foo,
// Comment.
.bar {
  display: block;
}

Output:

// This is SCSS. Prettier moves `.bar` up to the the same line as 'Comment.'.
.foo,
// Comment. .bar {
    display: block;
}

Expected behavior:

When running prettier on this code inside of Atom, it bumps .bar up to the comment line. It should keep it on a separate line. This completely breaks the file.

example updated by @j-f1 to use the correct parser

Activity

  1. added
    lang:css/scss/less
    on Jan 4, 2018
  2. added
    priority:high
    on Jan 5, 2018
  3. vjeux commented on Jan 5, 2018

    @vjeux
    Contributor

    The parser doesn't consider it a comment and parses it as a lot of garbage :(

       [ Tag {
           value: '//',
           type: 'selector-tag' },
         Combinator {
           value: ' ',
           type: 'selector-combinator' },
         Tag {
           value: 'Comment',
           type: 'selector-tag' },
         ClassName {
           value: '',
           type: 'selector-class' },
         Combinator {
           value: '\n',
           type: 'selector-combinator' },
         ClassName {
           value: 'bar',
           type: 'selector-class' } ],
  4. added a commit that references this issue on Jan 5, 2018
    85a4618
  5. vjeux commented on Jan 5, 2018

    @vjeux
    Contributor

    Let's not pretend that the selector parser handles comments and print the selector as is when there are comments: #3649

  6. added 2 commits that reference this issue on Jan 5, 2018
    5680bb5
    284d640
  7. added a commit that references this issue on Jan 5, 2018
    a4dd864
  8. ryanpcmcquen commented on Jan 5, 2018

    @ryanpcmcquen
    Author

    Thanks for the quick work!

  9. azz commented on Jan 5, 2018

    @azz
    Member

    Also closing #2468 (duplicate)

  10. added this to the 1.10 milestone on Jan 7, 2018
  11. ekfuhrmann commented on Mar 1, 2018

    @ekfuhrmann

    I'm still having issues with this, even after updating to v1.11. I have the following color map:

    Input

    $colors: (
        // Neutral Tints/Shades
        black: (
            primary: #242629,
            lighten-1: #333437,
            lighten-2: #4a4c51,
            lighten-3: #5a5e65
        ),
        white: (
            primary: #fafafa,
            darken-1: #efefef,
            darken-2: #c7cad0,
            darken-3: #979aa0
        )
    )

    Output

    $colors: (
        / / Neutral Tints/Shades black:
            (
                primary: #242629,
                lighten-1: #333437,
                lighten-2: #4a4c51,
                lighten-3: #5a5e65
            ),
        white:
            (
                primary: #fafafa,
                darken-1: #efefef,
                darken-2: #c7cad0,
                darken-3: #979aa0
            )
    );

    As you can see, the comment is getting merged into the actual color map.

  12. alexander-akait commented on Mar 1, 2018

    @alexander-akait
    Member

    @eablokker already wip, bug in parser

  13. alexander-akait commented on Mar 1, 2018

    @alexander-akait
    Member

    But we should add tests when list inside maps 👍

  14. j-f1 commented on Mar 1, 2018

    @j-f1
    Member

    That’s a different issue; see #4074.

  15. changed the title [-]`//` comments in SASS break formatting.[/-] [+]`//` comments in SASS selectors break formatting.[/+] on Mar 1, 2018
  16. ekfuhrmann commented on Mar 1, 2018

    @ekfuhrmann

    Thanks @evilebottnawi and @j-f1 for forwarding it on

  17. lukaszewczak commented on Jun 12, 2018

    @lukaszewczak

    Hi, unfortunelty, this issue is still active. I'm using version 1.13.5 on Windows,

    For my input

    $colors: (
        // Primary
        blue-black: hsl(211, 79%, 5%),
        blue-darkest: hsl(208, 34%, 27%),
        blue-darker: hsl(209, 33%, 31%),
        blue-dark: #3b5772,
        blue-medium: hsl(209, 36%, 45%),
        // Secodary
        green-darkest: hsl(160, 62%, 30%),
        green-darker: hsl(160, 69%, 38%),
        green-dark: hsl(160, 66%, 43%),
        green-medium: hsl(160, 67%, 45%)
    )

    I got output:

    $colors: (
        // Primary
            blue-black: hsl(211, 79%, 5%),
        blue-darkest: hsl(208, 34%, 27%),
        blue-darker: hsl(209, 33%, 31%),
        blue-dark: #3b5772,
        blue-medium: hsl(209, 36%, 45%),
        // Secodary green-darkest: hsl(160, 62%, 30%),
        green-darker: hsl(160, 69%, 38%),
        green-dark: hsl(160, 66%, 43%),
        green-medium: hsl(160, 67%, 45%)
    )
  18. added
    locked-due-to-inactivity
    on Sep 10, 2018
  19. locked as resolved and limited conversation to collaborators on Sep 10, 2018
  20. added theissue type on Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:css/scss/lesslocked-due-to-inactivitypriority:high

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions