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
Feature request: scss/function-no-unknown
#581
Comments
@rdebeasi Thanks for the proposal! I see this as a bit tricky to implement, because Functions are something that are created by users, so we don't really know if the function exists in another file, so this rule would really only work if the function is placed in the same file. |
Totally makes sense. If there's anything that I can do to help to make this proposal more practical, just let me know. Thank you! |
I'm also looking for a way to avoid these kind of easy mistakes.
/*
* Config to check unknown functions inside `dist` folder (compiled CSS)
* see https://github.com/stylelint-scss/stylelint-scss/issues/581#issuecomment-1017484418
* As recommended in SASS docs
* > 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!
* https://sass-lang.com/documentation/at-rules/function#plain-css-functions
*/
module.exports = {
rules: {
"property-no-unknown": true,
"media-feature-name-no-unknown": true,
"at-rule-no-unknown": true,
"selector-pseudo-class-no-unknown": true,
"selector-pseudo-element-no-unknown": true,
"unit-no-unknown": true,
// add any missing functions here
"function-allowed-list": [
"scale",
"scaleY",
"rgb",
"rgba",
"gradient",
"linear-gradient",
"color-stop", // inside webkit-linear-gradient
"calc",
"translate",
"translateX",
"translateY",
"translateZ",
"rotate",
"url",
"hsla",
"drop-shadow",
"rotateX",
"rotateY",
"minmax",
"var",
"cubic-bezier",
"saturate",
"format", // font
"alpha", // filter
"counter"
]
}
}
"scripts": {
- "build": "vite build",
+ "build": "vite build && npm run check:css",
+ "check:css": "stylelint --config stylelint.dist.config.js 'dist/**/*.css'"
}, However, I did not find a list of known CSS functions so you need to manually add them in your config. |
For anyone looking for a solution here:
|
Hi there, the Stylelint built-in See also stylelint/stylelint#5865 (comment) |
I've opened PR #591 but still draft. I have some difficulties with implementation. |
@ybiquitous looks really nice already. What do you need help with? |
@kristerkari Thanks. I've left some comments in #591. |
When using Sass // _functions.scss
@function example() {
// ..
}
// index.scss
@use "./functions" as fn;
.selector {
color: fn.example();
} Would it be possible to scan the |
Doing something like that would most likely make the rule really slow because you would have to be constantly reading the Usually going outside of the current file for linting is just a bad idea. |
Problem
Sass doesn't catch typos in function names. The docs recommend using a linter to catch these issues:
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 itscss/function-no-unknown
.Example
Here's an example of a mistake. I've typed
invart
instead ofinvert
:Sass assumes that
invart
must be a CSS function and writes it into the compiled CSS:Our proposed rule would realize that there's no Sass function called
invart
and also no CSS function calledinvart
. It would throw an error, alerting us to the fact that we've made a typo.Thank you so much for your time! :)
The text was updated successfully, but these errors were encountered: