stylelint: Add function-no-unknown

What is the problem you’re trying to solve?

I’m looking for a list of known CSS functions in order to catch typo errors.

see https://github.com/stylelint-scss/stylelint-scss/issues/581#issuecomment-1017484418

What solution would you like to see?

  1. Stylelint could export a list of known CSS functions that could be imported inside stylelint.config.js
  2. Stylelint could provide a rule function-no-unknown which throws errors for unknown functions

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Yes, for example, see the demo.

Should we consider extending this lint rule to be able to include all sass functions as well? 🤔

stylelint-csstree-validator is exactly what I was looking for!

Yeah, that plugin is amazing. It has full syntax validation for declaration property/value pairs and at-rules. You may find you need to turn off most of Stylelint’s built-in *-no-unknown rules when using it.

Using the css-functions-list package for a new function-no-unknown rule sounds good to me. 👍🏼

Okay, let’s go with:

  • Name: function-no-unknown
  • Primary option: true
  • Secondary options: None
  • Autofixable: No
  • Message: Unexpected unknown function "${function}"
  • Description: “Disallow unknown functions.”
  • Section: “Avoid errors” -> “Functions”
  • Extended description:

"This rule considers functions defined in the CSS Specificationsto be known.

This rule ignores double-dashed custom functions, e.g. --custom-function()"

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

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

@gnuletik Thanks for the request.

The stylelint-csstree-validator plugin will catch this for you.

Having said that, spotting unknown functions is a simple use case that users who don’t wish to use the CSSTree validator would benefit from. There is also a lot of innovation happening in the CSS parser world and we may use a different parser (or a combination of parsers) in the future, which may have better syntax validation. While we wait for the dust to settle on those innovations, we can add a function-no-unknown rule.

We can use the css-functions-list package.

The rule should ignore doubled dashed custom functions by default, e.g. --custom-function().

What does everyone think?

Yes, like scss/at-rule-no-unknown. Please see also ~~https://github.com/stylelint-scss/stylelint-scss/issues/581~~ https://github.com/stylelint-scss/stylelint-scss/issues/589

EDIT: Sorry, wrong issue link. 😅

I think we should ignore non standard CSS syntax

@mizozobu Sounds good, but please open a request issue so that we can track it.