Skip to content

SCSS code is different with single line comments inside mixins using CRLF line endings #4143

Closed

Description

@aholtkamp

Prettier 1.11.1

Using prettier on our SCSS files we experience different behaviour under linux than under windows. Further investigation revealed that the line endings make the difference. It seems when using CRLF as line endings prettier produces different output than with normal LF as line endings.

Input (CRLF line endings):

@mixin create-rules($padding) {
  //
  // single line comment
  //
  .abc {
    padding: $padding;
  }

  /**
   * multi line comment
   */
  .def {
    padding: $padding;
  }
}

Output:

@mixin create-rules($padding) {
  $p // single line comment
  //
  .abc {
    padding: $padding;
  }
  /* *
   * multi line comment */
  .def {
    padding: $padding;
  }
}

Expected behavior:
The file should not be changed as it already is properly formatted.

Issues:

  • single line comments produce invalid code after formatting
  • multi line comments are formatted incorrectly
  • a line break between the two code blocks gets stripped

Activity

  1. added
    lang:css/scss/less
    status:awaiting response
    and removed on Mar 13, 2018
  2. alexander-akait commented on Mar 14, 2018

    @alexander-akait
    Member

    @aholtkamp i add tests #4145 and all works as expected, what editor you use and how you run prettier, looks something wrong with cursor

  3. aholtkamp commented on Mar 14, 2018

    @aholtkamp
    Author

    I'm using IntelliJ IDEA. It seems your tests do not use "@mixin" but media-queries. For media-queries everything works as expected.

  4. removed
    status:awaiting response
    on Mar 14, 2018
  5. alexander-akait commented on Mar 14, 2018

    @alexander-akait
    Member

    @aholtkamp added you example, all fine

  6. alexander-akait commented on Mar 14, 2018

    @alexander-akait
    Member

    @aholtkamp maybe you can create minimum reproducible repo or describe instruction how you run prettier?

  7. aholtkamp commented on Mar 14, 2018

    @aholtkamp
    Author

    I will see if I can provide a repo, probably in the next few hours

  8. aholtkamp commented on Mar 14, 2018

    @aholtkamp
    Author

    Oh, I'm sorry, it seems I have changed and formatted my code too often when trying to provide a minimal example for the issue (our affected file is much bigger).

    The problem occurs when the mixin parameter list too long and will be split into multiple lines.

    Input (CRLF line endings):

    @mixin create-rules(
      $padding,
      $param2: 30px,
      $param3: 1px solid black,
      $param4: 1,
      $param5: 1
    ) {
      //
      // single line comment
      //
      .abc {
        padding: $padding;
      }
    
      /**
       * multi line comment
       */
      .def {
        padding: $padding;
      }
    }
    

    I hope you can reproduce it with this code, otherwise I will provide a repo.

  9. aholtkamp commented on Mar 14, 2018

    @aholtkamp
    Author

    In addition to this the problem also occurs when the parameter list is rewritten:

    Input (CRLF line endings):

    @mixin create-rules(
      $padding
    ) {
      //
      // single line comment
      //
      .abc {
        padding: $padding;
      }
    
      /**
       * multi line comment
       */
      .def {
        padding: $padding;
      }
    }
    

    Output:

    @mixin create-rules($padding) {
      $p // single line comment
      //
      .abc {
        padding: $padding;
      }
      /* *
       * multi line comment */
      .def {
        padding: $padding;
      }
    }
    

    Expected Output:

    @mixin create-rules($padding) {
      //
      // single line comment
      //
      .abc {
        padding: $padding;
      }
    
      /**
       * multi line comment
       */
      .def {
        padding: $padding;
      }
    }
    
  10. aholtkamp commented on Mar 26, 2018

    @aholtkamp
    Author

    Could you reproduce the issue?

  11. darekkay commented on May 16, 2018

    @darekkay

    I can reproduce the issue in my project for @mixin and @function declarations and only on Windows (CRLF). On Linux/Mac there are no issues (LF).

  12. justrhysism commented on Sep 6, 2018

    @justrhysism

    This issue isn't only for comments, have noticed that Prettier (SCSS) has all sorts of trouble with CRLF. Worth also noting that I haven't experienced this with JS, TS or JSON using the same config.

    Input (CRLF) - Expected output should be unchanged

    /// Greys
    $colour-map-grey: (
      40: #58606e,
      60: #8e99ab,
      80: #c8d1e0,
      100: #f5f7fa,
      default: #8e99ab
    ) !default;
    
    /// Blues
    $colour-map-blue: (
      30: #114599,
      50: #3272d9,
      70: #84b1fa,
      100: #f0f5fc,
      default: #3272d9
    ) !default;
    
    $colour-map-green: (
      20: #1a5130,
      30: #2a844e,
      50: #57c182,
      90: #e1faeb,
      default: #2a844e
    ) !default;

    Output

    /// Greys
    $colour-map-grey: (
      40: #58606e,
      60: #8e99ab,
      80: #c8d1e0,
      100: #f5f7fa,
      default: #8e99ab
    ) !default;
    
    // / Blues
    $colour-map-blue: (
      30: #114599,
      50: #3272d9,
      70: #84b1fa,
      100: #f0f5fc,
      default: #3272d9
    ) !default;
    $colour-map-green: (
      20: #1a5130,
      30: #2a844e,
      50: #57c182,
      90: #e1faeb,
      default: #2a844e
    ) !default;
  13. thorn0 commented on Apr 25, 2020

    @thorn0
    Member

    Fixed at some point between versions 1.15 and 1.16.

  14. added
    locked-due-to-inactivity
    on Jul 24, 2020
  15. locked as resolved and limited conversation to collaborators on Jul 24, 2020
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-inactivity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions