#stylelint

A mighty, modern CSS linter that helps you enforce consistent conventions and avoid errors in your stylesheets.

一个强大的现代 CSS 检测器,可以让你在样式表中遵循一致的约定和避免错误。

#Features

  • Over one hundred and fifty rules: Including those that:
  • 超过 150 条规则:包括:

    • Catch errors: e.g. invalid hex colors, indistinguishable colors, or overriding shorthand properties.
    • 捕捉错误:如,无效的十六进制颜色,无法识别的颜色,或覆盖了简写属性。
    • Enforce best practices: e.g. keeping specificity low or disallowing vendor prefixes in your source code.
    • 最佳实践:如,在你的源码中保持小写,或禁用浏览器引擎前缀。
    • Control what languages features can be used: e.g. whitelisting specific units, properties and functions, or disallowing certain selector types.
    • 控制可以使用的语言特性:如,特定单位的白名单,属性和函数 或禁止特定的选择器类型。
    • Enforce code style conventions: e.g. checking the spacing around the colon in declarations or specifying patterns for class selectors.
    • 强制代码风格规范:如,检查冒号周围的空格或指定类选择的匹配模式。
  • Support for the latest CSS syntax: Including custom properties, range context for media features, calc() and nesting.
  • 支持最新的 CSS 语法:包括自定义属性,media 特性的范围上下文,calc() 和 嵌套。
  • Understands CSS-like syntaxes: The linter is powered by PostCSS, so it understands any syntax that PostCSS can parse, including SCSS, SugarSS, and experimental support for Less.
  • 理解 CSS-like 语法: styelint 是基于 PostCSS 的,所以它能理解 PostCSS 可以解析的任何语法,包括 SCSS,SugarSS 和 Less 的实验特性
  • Completely unopinionated: Only enable the rules you want, and configure them with options that tailor the linter to your needs.
  • 灵活可配置:只启用你想要的规则,在配置它们的选项,来满足你的需求。
  • Support for plugins: It's easy to create your own rules and add them to the linter.
  • 支持插件:很容易创建你自己的规则,并将它们添加到检测器。
  • Automatically fix some stylistic warnings: By using stylefmt which supports stylelint configuration files.
  • 自动修复:通过使用支持 stylelint 配置文件的 stylefmt 可以进行自动修复。
  • Shareable configs: If you don't want to craft your own config, you can extend a shareable config.
  • 可分享的配置:如果你不想精雕细琢你自己的配置,你可以继承一个可分享的配置。
  • Options validator: So that you can be confident that your config is valid.
  • 选项验证器:你可以非常确信你的配置是有效的。
  • Well tested: Nearly twenty five thousand tests cover the internals and rules.
  • 充分的测试:将近 25000 个测试用例覆盖所有代码和规则。
  • Growing community: Used by Facebook, Github, Wikimedia, GSA, and WordPress among others.
  • 日益增长的社区:FacebookGithubWikimediaGSAWordPress 等等都在使用。

#Example output

Example

#Getting started

With stylelint, it's easy to start linting your CSS:

使用 stylelint,可以很容易开始检测你的 CSS:

  1. Decide how you want to use stylelint:
  2. 决定通过什么方式使用 stylelint:

  3. Create your configuration object by either extending a shared config or crafting your own:
  4. 通过以下两种方式创建你自己的配置对象

    • To extend a shared config, we recommend using stylelint-config-standard. It includes over 80 of stylelint's rules with sensible defaults. (You can always override specific rules after extending the config.) We update the config with each new release of stylelint. Alternately, you can search for a community config and extend that instead.
    • 继承一个可分享的配置,我们推荐使用 stylelint-config-standard。它包括超过 80 个 stylelint 规则,而且都有合理的默认值。 (你总是可以通过继承这个配置来覆盖特定的规则。) 我们会随每个 stylelint 新版本更新这个配置。你还可以 查找 一个社区的配置,然后 extend它。
    • To craft your own config, first learn about how rules are named and how they work together, then either:
    • 创建自己的配置,首先学习规则如何命名,如何协同配合,然后:

      • Start small and only learn about the rules you want to turn on and enforce. All of the rules are off by default, and so you can start small, growing your config over time as you have a chance to explore more of the rules.
      • 先了解一下你想开启和应用的规则所有的规则默认都是关闭的,因此你可以一步一步来,随着你对规则的了解,慢慢增加你的配置。
      • Or copy-paste this example configuration, which lists all of stylelint's rules and their primary options. Then you can edit the options of each rule to your liking, and remove (or turn off with null) the rules that you don't care to enforce.
      • 或者复制粘贴示例配置,包含了所有的 stylelint 规则和主要选项。然后你可以编辑每个你喜欢的规则的选项,也可以移除(或通过设置 null 关闭)你不关心的规则。
  5. Lint!
  6. 检测!

#Guides

You'll find more detailed information on using stylelint and tailoring it to your needs in our guides:

你可以在以下指南中根据自己需要详细了解如何使用 stylelint:

  • User guide - Usage, configuration, FAQ and complementary tools.
  • 用户指南 - 使用,配置,常见问题解答和工具。
  • Developer guide - Contributing to stylelint and writing your own plugins & formatters.
  • 开发者指南 - 参与到 stylelint,写你自己的插件和格式化器。

#Need help?

If you're looking for help or have a support question, then check out our FAQ first. If the answer to your problem isn't there, then go to stackoverflow. stackoverflow is a huge Question and Answer community, and tagging your post there with "stylelint" will catch the stylelint team's attention.

如果你寻求帮助或有问题需要支持,请先查看FAQ。如果没有找到你想要的答案,就去stackoverflow。stackoverflow 是一个非常大的问答社区,在你的文章打上 "stylelint" 标签,这样会吸引 stylelint 团队的注意。

If you think you've found a bug or if you have feature request, then create a new GitHub issue. Be sure to follow the issue template, answering each question, as this helps us greatly in understanding your problem or request.

如果你发现了 bug 或有新特性请求,请发issue。请按照 issue 模板,回答每一个问题,这将帮助我们理解你的问题或请求。

Upgrading? Please read our CHANGELOG to learn what changes to expect in the latest version, whether that's new features, bug fixes, renamed rules, or whatever else.

升级?请阅读我们的变更日志 了解最新版本的变化,新特性,bug 复现,规则重命名或其他。

#Help out

There is always a lot of work to do, and already well over 150 rules to maintain. So please help out in any way that you can:

还有很多事情需要去做,而且有超过 150 条规则需要维护。所以,用你的方式参与进来吧:

License