Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix false positives for parens in selectors in indentation #5181

Closed
fregante opened this issue Mar 2, 2021 · 4 comments
Closed

Fix false positives for parens in selectors in indentation #5181

fregante opened this issue Mar 2, 2021 · 4 comments
Labels
status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule

Comments

@fregante
Copy link

fregante commented Mar 2, 2021

Initially reported in #3461 (comment)

Clearly describe the bug

indentation does not cover the indentation of the content of parens in selectors, like :is()

What code is needed to reproduce the bug?

:is(
a,
b
) {}

What stylelint configuration is needed to reproduce the bug?

{
  "rules": {
    "indentation": 2
  }
}

Which version of stylelint are you using?

13.11.0

What did you expect to happen?

a and b should be indented:

:is(
  a,
  b
) {}

What actually happened (e.g. what warnings or errors did you get)?

They're accepted as is, without indentation.

Context

Originally posted by @jeddy3 in #3461 (comment)

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

@jeddy3 jeddy3 changed the title The content of parens in selectors is not indented Fix false positives for parens in selectors in indentation Mar 2, 2021
@jeddy3 jeddy3 added status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule labels Mar 2, 2021
@jeddy3
Copy link
Member

jeddy3 commented Mar 2, 2021

@fregante Thanks for the report and for using the template.

I can reproduce using the demo with:

:is(
 a,
 b
) {
  width:
    calc(
      100% - 10px
    );
}

I've labelled the issue as ready to implement. Please consider contributing if you have time.

There are steps on how to fix a bug in a rule in the Developer guide.

@fregante
Copy link
Author

fregante commented Mar 2, 2021

Interestingly enough, :is(:is()) is partially indented:

:is(
:is(
  a,
  b
),
b
) {
  width:
    calc(
      100% - 10px
    );
}

Whereas :is(:is(:is())) just fails between selector-pseudo-class-parentheses-space-inside and indentation

:is(
:is(
  :is(
    a,
    b
  ) /* Unexpected whitespace before ")" */
)
) {
  width:
    calc(
      100% - 10px
    );
}

@jeddy3
Copy link
Member

jeddy3 commented Mar 3, 2021

Thanks for digging deeper.

Whereas :is(:is(:is())) just fails between selector-pseudo-class-parentheses-space-inside and indentation

It looks like we'll need to bring the same flexibility we have for functions to pseudo-classes, i.e. add a:

  • never-single-line option to selector-pseudo-class-parentheses-space-inside, like function
  • selector-pseudo-class-parentheses-newline-inside rule, like function

If anyone fancies tackling these, please create new issues for each so we can track them.


Incidentally, it's amazing to see how much :is() cleaned things up in that referenced pull request.

It makes me think there's scope for a new use-matches-any-pseudo-class rule (spec ref) that, that would work like the stylelint-use-nesting plugin but would enforce the use of :is() where appropriate.

@jeddy3
Copy link
Member

jeddy3 commented Jan 18, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready to implement is ready to be worked on by someone type: bug a problem with a feature or rule
Development

No branches or pull requests

2 participants