ben-eb / perfectionist

Beautify CSS files.
MIT License
229 stars 14 forks source link

Comments being removed #8

Closed Mottie closed 8 years ago

Mottie commented 8 years ago

We use our styles at userstyles.org, so some css definitions have placeholder comments within the definition (see "placeholder" in the example below) which get replaced with user set choices:

.selector {
  /* comment 1 */
  color: /*[[placeholder]]*/ white;
  /* comment 2 */
}

With default settings, the result removes the essential placeholder comment:

.selector {/* comment 1 */
    color: white; /* comment 2 */
}
ben-eb commented 8 years ago

Looks like an issue with resetting decl.between. Thanks for reporting.

ben-eb commented 8 years ago

Released as 1.2.1.

Mottie commented 8 years ago

Thanks for the fix!

Mottie commented 8 years ago

Still one minor issue though. If I include a comment before the selectors, it adds an extra carriage return now:

Starting with:

/* comment 0 */
.selector {
  /* comment 1 */
  color: /*[[placeholder]]*/ white;
  /* comment 2 */
}

the result becomes:

/* comment 0 */

.selector {/* comment 1 */
    color: /*[[placeholder]]*/ white; /* comment 2 */
}

Any way to get the first comment directly above the selector, and the second comment back on it's own line? :grin:

ben-eb commented 8 years ago

This might need a bit more thought. For example if we have some CSS like this:

h1 {
  color: black; /* Don't change this line! */
}

The formatter would then break the semantics of the comment. I wonder if there is some way to tell if both the property value pair & the comment are on the same line.

In terms of block formatting comments, there are different opinions on that and we could look into providing options for that. See https://github.com/ben-eb/perfectionist/issues/4 also.

Mottie commented 8 years ago

I got a little lost trying to read through the code, so I don't know how much help I could be with troubleshooting. I guess it's not a huge deal if the comment ends up on the next line, given you are trying to support different levels of formatting.

Adding an option for comment formatting would be awesome! :cake: