less / less/less.js

Strip empty rulesets that contain only CSS comments

Open
#4,276 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug feature request
Dominant language
JavaScript
Stars
17k
Forks
3.4k
Avg merge
7h 42m
Merged PRs (30d)
26

Description

To reproduce:

Currently, when a ruleset contains nothing but a Less comment, that ruleset is considered empty and is stripped from the compile CSS output. The same is not true for CSS comments. Consider the following example:

Current behavior:

Screenshot 2024-08-14 at 12 41 10 PM

Expected behavior:
From a developer's perspective, I'd expect that the two rulesets would be treated equally, regardless of the comment format, and that neither would produce any CSS output.

When combined with nesting, this behaviour can lead to unnecessarily duplicated code, as was the case in the following issue:
https://phabricator.wikimedia.org/T372101

e.g.
Screenshot 2024-08-14 at 12 48 36 PM

Environment information:

  • less version: 4.2

p.s.
I think this is related to #2477 but I wasn't sure to what extent.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named in the issue. Start by reproducing the Less 4.2 example and trace how the compiler decides whether a ruleset is empty, comparing Less and CSS comments. Done means comment-only rulesets produce no CSS output consistently, including when nesting is involved.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.