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 length-zero-no-unit false positives for custom properties #274

Closed
mbehzad opened this issue Nov 22, 2022 · 2 comments · Fixed by #277
Closed

Fix length-zero-no-unit false positives for custom properties #274

mbehzad opened this issue Nov 22, 2022 · 2 comments · Fixed by #277
Labels
status: ask to implement ask before implementing as may no longer be relevant type: bug a problem with a feature or rule

Comments

@mbehzad
Copy link

mbehzad commented Nov 22, 2022

What steps are needed to reproduce the bug?

Hi everyone,

CSS code:

.element {
  --offset: 0px;

  left: calc(var(--offset) + 50%);
}

stylelintrc config:

{
  "extends": "stylelint-config-standard"
}

Error:

2:14  ✖  Unexpected unit  length-zero-no-unit

Where left: calc(var(--offset) + 50%); with --offset: 0 (without unit) results to invalid left: calc(0 + 50%); css.
(mini repo to reproduce: https://github.com/mbehzad/reproduce-length-zero-no-unit-custom-properties-issue)

I think it is more safe to have the rule as

"length-zero-no-unit": [
      true,
      {
        "ignore": ["custom-properties"]
      }
    ],

If this makes sense, I can open a PR.
Cheers

What did you expect to happen?

Not removing the unit for this case: (--offset: 0px;)

What actually happened?

--offset: 0px; needs to be changed to --offset: 0;

@ybiquitous
Copy link
Member

@mbehzad Thanks for opening the issue with the minimal reproduction. I can confirm the behavior you reported.

Considering the background (stylelint/stylelint#2586) where the ignore: ["custom-properties"] option was introduced, your proposal sounds to make sense.

@ybiquitous ybiquitous added the status: needs discussion triage needs further discussion label Nov 23, 2022
@jeddy3 jeddy3 changed the title length-zero-no-unit rule in combination with custom properties and calc leads sometimes to invalid css Fix length-zero-no-unit false positives for custom properties Nov 24, 2022
@jeddy3 jeddy3 added type: bug a problem with a feature or rule status: ask to implement ask before implementing as may no longer be relevant and removed status: needs discussion triage needs further discussion labels Nov 24, 2022
@jeddy3
Copy link
Member

jeddy3 commented Nov 24, 2022

Turning on the ignore: ["custom-properties"]` option SGTM. It'll make the config more permissive, so "patch" semver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ask to implement ask before implementing as may no longer be relevant type: bug a problem with a feature or rule
Development

Successfully merging a pull request may close this issue.

3 participants