prettier: Less: single quotes in comments lead to broken output

Prettier next Playground link

--parser less

Input:

// TODO: '
// '
.qux1 {
    a {
        color: #555;
        border-right: 1px solid transparent;/*   */
        &.close {
            margin: 0;
        }
    }
}

.qux2 {
  width: 100%;
  height: 180px;
}

.qux3 {
	margin-right: 10px; 
}
 

Output:

// TODO: '
 // '

.qux1 {
  a {
    color: #555;
    border-right: 1px solid transparent; id tran
    &.close {
      margin: 0;
    }
  }
}
.qux2 {
  width: 100%;
  height: 180px;
}
.qux3 {
  margin-right: 10px;
}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (17 by maintainers)

Most upvoted comments

The problem is that these quotes corrupt location data for all nodes after that comment. I’m going to add some location hacks to #7021.

@ExE-Boss only if the PR targets master.

Please have a look at #7021. Known issue: replaceQuotesInInlineComments should be improved to be aware of block comments (things like /* // */ don’t start inline comments whereas now that function thinks they do).

As workaround we can replace quotes in comments on __LESS_SINGLE_QUOTE__, __LESS_DOUBLE_QUOTE__ before parse and change them to original characters after print, it is very dirty, but I don’t think that guys fix problem, we have a lot of problems with Less in stylelint and no fixes a long time

I’m looking into this too, and it seems like I’ve found a good solution.

I’ll look into this.