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.

Fix false negatives for multiline selectors in indentation

See original GitHub issue

What is the problem you’re trying to solve?

Some of the selectors we use in one of our projects are quite long and thereby violate the max-line-length: 80 rule.

body:not([data-dialog="language-add"]):not([data-dialog="language-change"]) #dialog-content-language-add

We tend to resolve such issues by splitting up the line and indenting subsequent lines.

body:not([data-dialog="language-add"]):not([data-dialog="language-change"])
  #dialog-content-language-add

Because the alternative would be to not indent subsequent lines which, however, makes it diffcult to differentiate whether a line is a selector or merely a continuation of the previous selector.

body:not([data-dialog="language-add"]):not([data-dialog="language-change"])
#dialog-content-language-add

However, this results in a violation of our indentation: 2 rule and there doesn’t appear to be an option for excluding selectors

✖  Expected indentation of 0 spaces   indentation

Because of that and https://github.com/stylelint/stylelint/issues/3111 we currently have to disable the “indentation” rule for the entire block which is not ideal.

/* stylelint-disable indentation */
body:not([data-dialog="language-add"]):not([data-dialog="language-change"])
  #dialog-content-language-add
{
  display: none;
}
/* stylelint-enable indentation */

Furthermore, due to https://github.com/stylelint/stylelint/issues/2643, that means that we have to be extra careful when running stylelint --fix.

What solution would you like to see?

A new option for the “indentation” rule that allows lines that represent continuations of selectors to be indendent by one more level.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeddy3commented, Mar 2, 2021

@fregante I believe that’s a separate problem. Can you create a new bug issue for it, please?

I think the following should be the default behaviour of the rule:

:is(
  a,
  b
) {}

We apply indentation to parens in at-rules and declaration-values, but not those in selectors. It should, though.


Revisiting the original issue, I think indenting multiline selectors should be the default behaviour rather than an option. I’ll change the labelling accordingly.

When both issues are fixed, we end up with:

body:not([data-dialog="language-add"]):not([data-dialog="language-change"]):is(
    a,
    b
  )
  #dialog-content-language-add,
.second-selector-in-list {}
0reactions
jeddy3commented, Jan 17, 2022

Closing as stylistic rules are frozen. The community is welcome to migrate the rule to a plugin and fix this bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stylelint indentation rule returns false negative on multi-line ...
I have an app that uses Stylelint to enforce stylistic rules inside styles, but here, Stylelint complains about indentation when ...
Read more >
indentation - Stylelint
Always indent at-rules, rules, comments, declarations, inside parentheses and multi-line values by 2 spaces. The following patterns are considered problems:.
Read more >
Configuration · Scalafmt - Scalameta
When this parameter is disabled, no indentation is added for same-line single-arg cases; the assumption is that if the argument expression spans multiple...
Read more >
stylelint | Yarn - Package Manager
Fixed : selector-type-case false positives for SVG elements (#5973). Fixed: unit-no-unknown false positives for large/small/dynamic viewport units (#5970). 14.6.
Read more >
Indentation of CSS pseudo-class with multiple selectors on ...
Indentation of CSS pseudo-class with multiple selectors on multiple lines ( :is(), :where() ) ... When using CSS pseudo-classes that can contain a...
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