使用 Stylelint 的 SCSS mixin 函数上的未知单词

发布于 2025-01-17 01:56:34 字数 2046 浏览 5 评论 0原文

我正在开发 webpack 样板,并且一直在尝试使用 scss mixins 设置 px 到 rem 转换函数。我也在使用 stylelint 来检查该项目中的错误。

我不断收到以下错误,我需要一些帮助来解决此问题。

终端

When linting something other than CSS, you should install an appropriate syntax, 
e.g."postcss-scss", and use the "customSyntax" option

13:19  ✖  Unknown word  CssSyntaxError

我的 mixin 代码如下:

Mixin

$html-font-size: 16px;

@function stripUnit($value) {
    @return $value / ($value * 0 + 1);
}

@function ptpx($ptValue) {
    @return stripUnit($ptValue * 1.333);
}

@function rem($pxValue, $unit:'px') {
    @if $unit == 'pt' {
        @return #{ptpx($pxValue) / stripUnit($html-font-size)}rem;
    } @else {
        @return #{$pxValue / stripUnit($html-font-size)}rem;
    }
}

以下是我的 stylelint 配置:

Config

module.exports = {
    rules: {
      "at-rule-no-unknown": true,
      "block-no-empty": true,
      "color-no-invalid-hex": true,
      "comment-no-empty": true,
      "declaration-block-no-duplicate-properties": [
        true,
        {
          ignore: ["consecutive-duplicates-with-different-values"]
        }
      ],
      "declaration-block-no-shorthand-property-overrides": true,
      "font-family-no-duplicate-names": true,
      "font-family-no-missing-generic-family-keyword": true,
      "function-calc-no-unspaced-operator": true,
      "function-linear-gradient-no-nonstandard-direction": true,
      "keyframe-declaration-no-important": true,
      "media-feature-name-no-unknown": true,
      "no-descending-specificity": true,
      "no-duplicate-at-import-rules": true,
      "no-duplicate-selectors": true,
      "no-empty-source": true,
      "no-extra-semicolons": true,
      "property-no-unknown": true,
      "selector-pseudo-class-no-unknown": true,
      "selector-pseudo-element-no-unknown": true,
      "selector-type-no-unknown": true,
      "string-no-newline": true,
      "unit-no-unknown": true
    }
  };

我对此很困惑,有人可以帮助我吗? 提前致谢!

I'm working on a webpack boilerplate, and I've been trying to set up a px to rem conversion function using scss mixins. I'm using stylelint to check for errors in this project too.

I keep getting the following errors, and I'd like some help with fixing this please.

Terminal

When linting something other than CSS, you should install an appropriate syntax, 
e.g."postcss-scss", and use the "customSyntax" option

13:19  ✖  Unknown word  CssSyntaxError

My code for the mixin is as follows:

Mixin

$html-font-size: 16px;

@function stripUnit($value) {
    @return $value / ($value * 0 + 1);
}

@function ptpx($ptValue) {
    @return stripUnit($ptValue * 1.333);
}

@function rem($pxValue, $unit:'px') {
    @if $unit == 'pt' {
        @return #{ptpx($pxValue) / stripUnit($html-font-size)}rem;
    } @else {
        @return #{$pxValue / stripUnit($html-font-size)}rem;
    }
}

The following is my config for stylelint:

Config

module.exports = {
    rules: {
      "at-rule-no-unknown": true,
      "block-no-empty": true,
      "color-no-invalid-hex": true,
      "comment-no-empty": true,
      "declaration-block-no-duplicate-properties": [
        true,
        {
          ignore: ["consecutive-duplicates-with-different-values"]
        }
      ],
      "declaration-block-no-shorthand-property-overrides": true,
      "font-family-no-duplicate-names": true,
      "font-family-no-missing-generic-family-keyword": true,
      "function-calc-no-unspaced-operator": true,
      "function-linear-gradient-no-nonstandard-direction": true,
      "keyframe-declaration-no-important": true,
      "media-feature-name-no-unknown": true,
      "no-descending-specificity": true,
      "no-duplicate-at-import-rules": true,
      "no-duplicate-selectors": true,
      "no-empty-source": true,
      "no-extra-semicolons": true,
      "property-no-unknown": true,
      "selector-pseudo-class-no-unknown": true,
      "selector-pseudo-element-no-unknown": true,
      "selector-type-no-unknown": true,
      "string-no-newline": true,
      "unit-no-unknown": true
    }
  };

I'm quite lost with this, could someone please help me?
Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2025-01-24 01:56:34

正如控制台中的警告所述,您需要使用自定义语法 对 SCSS 进行 lint 处理,因为它不是 CSS,而是另一种语言:

当对 CSS 以外的内容进行 linting 时,您应该安装适当的语法,例如“postcss-scss”,并使用“customSyntax”选项

当对 CSS 以外的内容进行 linting 时,您应该安装适当的语法,例如“postcss-scss”,并使用Stylelint 的 入门指南 建议扩展共享配置,其中包括并为您配置适当的自定义语法。

您应该将现有配置替换为:

{
  "extends": "stylelint-config-standard-scss"
}

如果需要,您可以使用 null 关闭现在不想强制执行的任何规则,如下所示:

{
  "extends": "stylelint-config-standard-scss"
  "rules": {
    "color-function-notation": null
  }
}

As the warning in the console states, you'll need to use a custom syntax to lint SCSS as it's not CSS but another language:

When linting something other than CSS, you should install an appropriate syntax, e.g."postcss-scss", and use the "customSyntax" option

Stylelint's getting started guide recommends extending a shared config that includes and configures the appropriate custom syntax for you.

You should replace your existing configuration with:

{
  "extends": "stylelint-config-standard-scss"
}

If needed, you can turn off any rules that you don't want to enforce right now using null, like so:

{
  "extends": "stylelint-config-standard-scss"
  "rules": {
    "color-function-notation": null
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文