question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `ignore: ["inside-block"]` to selector-disallowed-list

See original GitHub issue

What is the problem you’re trying to solve?

I also want to disallow top-level selectors which are starting with & because that’s invalid CSS code

&.foo { }

(common to SASS precompiler language but is not restricted to it)

What solution would you like to see?

either top-level flexible regex rule or an explicit rule for anything starting specifically with &

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
yairEOcommented, Sep 5, 2022

I’m a single person, not “they”… I don’t have the time capacity as I already am the author of dozens of open-source projects and have a fulltime job and also need to find the time watching funny cats YouTubes while eating watermelons and thus more busy than Elon MusK

2reactions
jeddy3commented, Sep 3, 2022

This is an interesting one.

According to the latest draft spec &.foo {} is a valid CSS:

When used in the selector of a nested style rule, the nesting selector represents the elements matched by the parent rule. When used in any other context, it represents nothing. (That is, it’s valid, but matches no elements.)

I think the CSSTree validator is currently flagging it as doesn’t parse nesting outright yet, e.g.:

Screenshot 2022-09-03 at 15 14 23

Stylelint is a good fit for CSS that is valid, but probably wasn’t what the author intended to write. It’d be inline with the other *-unmatchable rules we’re thinking of adding (e.g. https://github.com/stylelint/stylelint/issues/5907)). However, we probably don’t want to add any new nesting rules just yet as the nesting specification is influx (with the syntax still to be settled on).

I can see us adding a whole suite of rules for nesting when the specification does stabilise, though. For example, there is plenty of other valid nesting CSS that a person would probably want to limit:

a {
  && {}
}

Or enforce a particular notation, e.g. these two are equivalent:

a {
  @media (orientation: landscape) { color: red; }
}

a {
  @media (orientation: landscape) { & { color: red; } }
}

I suggest that anyone who is interested in these create plugins that we can port over to built-in rules once the specification stabilises.

In the meantime, we can add an ignore: ["inside-block"] option to the selector-disallowed-list rule (example of prior art). A user can then craft a regex to disallow the nesting selector (&) anywhere in a selector unless the selector is inside of a block.

It’s not a perfect solution as the option will apply to all the items in the array, but it’ll probably address @yairEO immediate use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

selector-disallowed-list - Stylelint
Specify a list of disallowed selectors. ... Split selector lists into individual selectors. ... Ignore selectors that are inside a block. Given: [".foo"]....
Read more >
@alexseitsinger/stylelint-config - npm
Specify a blacklist of disallowed attribute operators. https://stylelint.io/user-guide/rules/selector-attribute-operator-blacklist/. Examples. [] ...
Read more >
@fylgja/stylelint-config NPM | npm.io
We have not set any allowed/disallowed-list values. it's better to set those ... except: first-nested,; ignore: after-comment, inside-block. Selector.
Read more >
stylelint-config-sass-guidelines - npm package - Snyk
Simply add a "rules" key to your config and add your overrides there. ... at-rule-disallowed-list : Specify a list of disallowed at-rules.
Read more >
List of rules - Stylelint 中文文档
Keyframe block​. keyframe-block-no-duplicate-selectors : Disallow duplicate selectors within keyframe blocks. Declaration block​.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found