简体   繁体   English

如何使用 eslint-config-stylelint

[英]How to use eslint-config-stylelint

css: css:

.fontSize11{ font-size: calc(var(--font-scale, 1 ) * 11px); }

In our project, we are using the above format for font-size in CSS. Some people in our team are not following the above format.在我们的项目中,我们在 CSS 中使用上面的字体大小格式。我们团队中的一些人没有遵循上面的格式。 To keep consistency someone suggested me to use eslint-config-stylelint to create a custom rule so it can be caught during development.为了保持一致性,有人建议我使用 eslint-config-stylelint 创建自定义规则,以便在开发过程中捕获它。 I don't have experience with build tools and linters.我没有构建工具和 linters 的经验。 I'll appreciate if someone can help me with it.如果有人可以帮助我,我将不胜感激。 Thanks谢谢

You can use Stylelint's built-in declaration-property-value-allowed-list rule to enforce a specific pattern for the value of a property, rather than create a custom rule.您可以使用 Stylelint 的内置declaration-property-value-allowed-list规则为属性值强制执行特定模式,而不是创建自定义规则。

By using an regular expression, you can ensure that the value of the font-size property matches the calc(var(--font-size, 1) * XXpx) pattern:通过使用正则表达式,您可以确保font-size属性的值与calc(var(--font-size, 1) * XXpx)模式相匹配:

{
  "rules": {
    "declaration-property-value-allowed-list": {
      "font-size": ["/calc\\(var\\(--font-scale, 1\\) \\* \\d+px\\)/"]
    }
  }
}

(There may be a cleaner way to write that regular expression.) (可能有更简洁的方式来编写该正则表达式。)

If you're just getting started with Stylelint, you'll want to extend official standard config in your config.如果您刚刚开始使用 Stylelint,您将希望在您的配置中扩展官方标准配置。 Your complete Stylelint configuration should look like:您完整的 Stylelint 配置应该如下所示:

{
  "extends": ["stylelint-config-standard"],
  "rules": {
    "declaration-property-value-allowed-list": {
      "font-size": ["/calc\\(var\\(--font-scale, 1\\) \\* \\d+px\\)/"]
    }
  }
}

To keep consistency someone suggested me to use eslint-config-stylelint to create a custom rule为了保持一致性,有人建议我使用 eslint-config-stylelint 来创建自定义规则

Stylelint and ESLint are different tools. Stylelint 和 ESLint 是不同的工具。 You should use:你应该使用:

  • Stylelint to lint your CSS Stylelint 对你的 CSS 进行 lint
  • ESLint to lint your JavaScript ESLint 对你的 JavaScript 进行 lint

( eslint-config-stylelint is an internal package used by the Stylelint team to lint their JavaScript code. It's not intended for public consumption.) eslint-config-stylelint是 Stylelint 团队使用的内部 package 来检查他们的 JavaScript 代码。它不供公众使用。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM