为什么当stylelint-scss告诉我时,当我使用list.nth时,SCSS会抱怨吗?

时间:2020-05-13 22:08:28

标签: css webpack sass sass-loader stylelint

我这里有点情况。

我在使用sass-loader的React应用程序中使用SCSS,并使用stylelint及其扩展名stylelint-scss填充我的SCSS / CSS。

我从这里借来了一些代码:https://medium.com/dev-channel/using-sass-to-automatically-pick-text-colors-4ba7645d2796,我正在尝试在文件中使用它。这是我的方法:

@function luminance($color) {
  $red: nth(linear-channel-values(), red($color) + 1);
  $green: nth(linear-channel-values(), green($color) + 1);
  $blue: nth(linear-channel-values(), blue($color) + 1);

  @return 0.2126 * $red + 0.7152 * $green + 0.0722 * $blue;
}

然后stylelint-scss向我抱怨:

WARNING in
src/assets/scss/helpers.scss
 282:9   ✖  Expected list.nth instead of nth        scss/no-global-function-names
 282:38  ✖  Expected color.red instead of red       scss/no-global-function-names
 283:11  ✖  Expected list.nth instead of nth        scss/no-global-function-names
 283:40  ✖  Expected color.green instead of green   scss/no-global-function-names
 284:10  ✖  Expected list.nth instead of nth        scss/no-global-function-names
 284:39  ✖  Expected color.blue instead of blue     scss/no-global-function-names

好吧,所以我将nth函数调用更改为list.nth ...,然后又收到另一个投诉:

@use "sass:color";
@use "sass:list";

@function luminance($color) {
  $red: list.nth(linear-channel-values(), color.red($color) + 1);
  $green: list.nth(linear-channel-values(), color.green($color) + 1);
  $blue: list.nth(linear-channel-values(), color.blue($color) + 1);

  @return 0.2126 * $red + 0.7152 * $green + 0.0722 * $blue;
}
ERROR in ./src/assets/scss/index.scss (./node_modules/css-loader/dist/cjs.js??ref--6-1!./node_modules/postcss-loader/src??ref--6-2!./node_modules/sass-loader/dist/cjs.js!./node_modules/resolve-url-loader!./src/assets/scss/index.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: Invalid CSS after "  $red: list": expected expression (e.g. 1px, bold), was ".nth(linear-channel"
        on line 282 of src/assets/scss/helpers.scss
        from line 7 of /Users/ogabay/Projects/mercury/app/pennypal/src/assets/scss/index.scss
>>   $red: list.nth(linear-channel-values(), color.red($color) + 1);

   ------------^

 @ ./src/assets/scss/index.scss 2:26-262 43:4-64:5 46:18-254
 @ ./src/index.jsx

这里是stylelint-scss还是sass-loader的问题?

0 个答案:

没有答案