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 ignoreFunctions: [] to unit-allowed-list

See original GitHub issue

What steps are needed to reproduce the bug?

Use css/scss functions that include a disallowed unit character.

button {
  border: 1px solid hsl(20deg 0% 20% / 80%);
  background-color: lighten(green, 20%);
}

What Stylelint configuration is needed to reproduce the bug?

{
  "rules": {
    "unit-allowed-list": "px"
  }
}

How did you run Stylelint?

CLI stylelint **/*.scss

Which version of Stylelint are you using?

14.2.0

What did you expect to happen?

Units within function to be ignored.

What actually happened?

The following problems were reported

2:25 errorUnexpected unit "deg" (unit-allowed-list)
2:31 errorUnexpected unit "%" (unit-allowed-list)
2:34 errorUnexpected unit "%" (unit-allowed-list)
2:40 errorUnexpected unit "%" (unit-allowed-list)
3:36 errorUnexpected unit "%" (unit-allowed-list)

Does the bug relate to non-standard syntax?

Yes, SCSS color functions and vanilla HSL functions

Proposal to fix the bug

Add ignore: ["inside-function"] secondary option to unit-allowed-list, similar fix to https://github.com/stylelint/stylelint/issues/5140

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
jeddy3commented, Jan 20, 2022

Okay, let’s go with ignoreFunctions: [].

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

There are steps on how to add a new option in the Developer guide.

1reaction
jeddy3commented, Jan 20, 2022

A new option sounds good.

I’m wondering whether we missed an opportunity when we added ignore: ["inside-function"] to those other rules. It’s too broad. If we pivot to a user defined list option, i.e. ignoreFunctions: [] we can cater to the above use case and others.

For example, given:

{
  "rules": {
    "unit-allowed-list": ["px", { "ignoreFunctions": ["hsl"] }]
  }
}

Would allow:

a {
  border: 1px solid hsl(20deg 0% 20% / 80%);
}

But disallow:

a {
  font-size: 10px;
}

b {
  font-size: var(--font-size, 1rem);
}

(When you want font sizes always in pixels).

You can still ignore all functions using this option by using regex in the list.

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changelog | Stylelint
Added : ignoreFunctions: [] to unit-allowed-list (#5857). Added: camelCaseSvgKeywords to value-keyword-case - use this option if you want legacy camel case ...
Read more >
stylelint 14.3.0 on Node.js Yarn - NewReleases.io
Added : ignoreFunctions: [] to unit-allowed-list (#5857). Added: camelCaseSvgKeywords to value-keyword-case - use this option if you want legacy camel case ...
Read more >
.stylelintrc - Qiita
"unit-allowed-list": ["単位名1","単位名2","単位名3"] ... 任意の文字列"] "ignoreFunctions": [正規表現, "任意の文字列"] ...
Read more >
CSSタグが付けられた新着記事 - Qiita
"unit-allowed-list": ["単位名1","単位名2","単位名3"] //オプション"ignoreProperties": ... 任意の文字列"] "ignoreFunctions": [正規表現, "任意の文字列"] ...
Read more >
Stylelint Stylelint Issues - IssueHint
Add message arguments to `declaration-property-unit-allowed-list` ... Fix `value-keyword-case` false positives for mixed case `ignoreFunctions` option ...
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