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 `no-unknown-custom-properties`

See original GitHub issue

What is the problem you’re trying to solve?

I’d like to disallow unknown custom properties. For example:

:root {
  --foo: 1px;
}

a {
  top: var(--bar);
}

What solution would you like to see?

A new rule to catch this. It’s currently available as a plugin but it meets our criteria to be a built-in rule.

Prior art for user-defined unknowns is no-unknown-animations.

Also, see this Twitter thread.

We’d need to address https://github.com/stylelint/stylelint/issues/4088 first, and work out how best to add imports & resolvers to configuration files. Is standardised importForm and resolver secondary options on each of these types of rules the way to go?

  • Name: no-unknown-custom-properties
  • Primary option: true
  • Secondary options: importForm & resolver?
  • Autofixable: No
  • Message: - Unexpected unknown custom property
  • Description: “Disallow unknown custom properties.”
  • Extended description: “This rule considers custom properties defined within the same source to be known. Use the importForm secondary option to specify more sources.”
  • Section: “Avoid errors” -> “General”

Like no-unknown-animations, we won’t turn the rule on in the recommended config and we’ll want to update the recommended config to reflect this.

Any thoughts?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jeddy3commented, Oct 30, 2022

Indeed, there may be a helpful case if defaultImportFrom is supported. But I’m not sure whether it is necessary for the first step. If it is easy to implement defaultImportFrom and importFrom simultaneously, I agree with adding both.

I agree.

I’ll label this as ready to implement.

  • Name: no-unknown-custom-properties
  • Primary option: true
  • Secondary options: importFrom: [] - array of glob paths to .css files
  • Autofixable: No
  • Message: - Unexpected unknown custom property
  • Description: “Disallow unknown custom properties.”
  • Extended description: “This rule considers custom properties defined within the same source to be known. You can use the importFrom secondary option to specify more sources.”
  • Section: “Avoid errors” -> “Unknown”

If anyone fancies contributing this rule, there are steps on how to add a new rule in the Developer guide.

1reaction
ybiquitouscommented, Sep 27, 2022

I suggest we start by only supporting .css imports,

I agree with the idea.

Do you think there’s value in something like a defaultImportFrom configuration property

Indeed, there may be a helpful case if defaultImportFrom is supported. But I’m not sure whether it is necessary for the first step. If it is easy to implement defaultImportFrom and importFrom simultaneously, I agree with adding both.

Read more comments on GitHub >

github_iconTop Results From Across the Web

csstools/stylelint-value-no-unknown-custom-properties - GitHub
Stylelint Value No Unknown Custom Properties is a stylelint rule to disallow usage of unknown custom properties. Usage. Add stylelint and Stylelint Value...
Read more >
stylelint-value-no-unknown-custom-properties - npm
A stylelint rule to disallow usage of unknown custom properties. Latest version: 4.0.0, last published: 8 months ago.
Read more >
property-no-unknown | Stylelint
Disallow unknown properties. This rule considers properties defined in the CSS Specifications and browser specific properties to be known. This rule ignores:
Read more >
stylelint-value-no-unknown-custom-properties - npm package
A stylelint rule to disallow usage of unknown custom properties. Visit Snyk Advisor to see a full health score report for stylelint-value-no-unknown-custom- ...
Read more >
stylelint-value-no-unknown-custom-properties examples
Learn how to use stylelint-value-no-unknown-custom-properties by viewing and forking example apps that make use of stylelint-value-no-unknown-custom-properties ...
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