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.

Feature request: `scss/function-no-unknown`

See original GitHub issue

Problem

Sass doesn’t catch typos in function names. The docs recommend using a linter to catch these issues:

Because any unknown function will be compiled to CSS, it’s easy to miss when you typo a function name. Consider running a CSS linter on your stylesheet’s output to be notified when this happens!

I’m unable to find any rules in stylelint-scss that catch mistakes like these, however.

Proposed solution

It would be awesome to have a new rule to catch mistakes like these. It would work like scss/at-rule-no-unknown, but for functions. Let’s call it scss/function-no-unknown.

Example

Here’s an example of a mistake. I’ve typed invart instead of invert:

@function invert($color, $amount: 100%) {
  $inverse: change-color($color, $hue: hue($color) + 180);
  @return mix($inverse, $color, $amount);
}

.button {
  background-color: invart(#f00)
}

Sass assumes that invart must be a CSS function and writes it into the compiled CSS:

.button {
  background-color: invart(#f00)
}

Our proposed rule would realize that there’s no Sass function called invart and also no CSS function called invart. It would throw an error, alerting us to the fact that we’ve made a typo.

Thank you so much for your time! 😃

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ybiquitouscommented, Feb 10, 2022

Hi there, the Stylelint built-in function-no-unknown rule will support the ignoreFunctions option with the next version. (stylelint/stylelint#5901)

See also https://github.com/stylelint/stylelint/pull/5865#issuecomment-1034871807

1reaction
kristerkaricommented, Mar 9, 2022

Would it be possible to scan the _functions.scss file while linting index.scss, list all functions defined in this file and add namespace prefix (fn in this example) and then add this list to the list of valid functions for the current file (index.scss)?

Doing something like that would most likely make the rule really slow because you would have to be constantly reading the _functions.scss file on fly and then parse/lint it.

Usually going outside of the current file for linting is just a bad idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

New stylelint `function-no-unknown` rule not working well with ...
This rule considers functions defined in the CSS Specifications to be 'known', and ignores double-dashed custom functions, e.g. --custom- ...
Read more >
function-no-unknown - Stylelint
Disallow unknown functions. This rule considers functions defined in the CSS Specifications to be known. This rule ignores double-dashed custom functions, e.g. ...
Read more >
Changelog - Stylelint 中文文档
Fixed: rule message function type to not require users to handle all kind ... Fixed: media-feature-name-no-unknown false positives for display-mode (#6073).
Read more >
stylelint-scss/README.md - UNPKG
stylelint-scss introduces rules specific to SCSS syntax. That said, the rules from this plugin can be used with other syntaxes, like Less or...
Read more >
stylelint-config-torchbox - npm
Shareable stylelint config for CSS and SCSS, following Torchbox's code style. ... There are no other projects in the npm registry using ...
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