【问题标题】:How to define rule in Stylelint which requires comma before newline in selectors?如何在 Stylelint 中定义规则,该规则需要在选择器中的换行符之前使用逗号?
【发布时间】:2019-01-09 15:11:04
【问题描述】:

我正在为我的 VS Code 编辑器设置一个 .stylint 文件。示例如下:

#main > div // there is no comma so stylint should throw an error here
div {
     ...
}

#main > div, // this is ok, no error here
div {
     ...
}

【问题讨论】:

  • 请提供有关您的问题的更多详细信息和/或代码。到目前为止,我们无法为您提供帮助。
  • @Ced 我真的不能再清楚了......
  • 哦,伙计,另一个网站明确声明在出现问题时询问 SO,甚至在他们的 github 上“阻止”问题。你读过常见问题解答吗?您尝试过什么,出了什么问题?您应该首先尝试自己解决它..
  • @Kaddath 我试图自己做,花了 2 个小时在文档中寻找合适的 stylelint 规则,但找不到任何有效的...
  • 第一个选择器是有效的所以不需要错误..或者,我怀疑,可能

标签: css stylelint


【解决方案1】:

使用 stylelint 中的 内置规则 无法做到这一点,因为以下是有效的选择器:

#main > div
div {}

相当于:

#main > div div {}

因为descendant combinator 是任何空格,包括换行符。

但是,您可以 write your own plugin 用于在选择器的每一行末尾强制使用逗号的 stylelint,但插件的后果可能会出现问题,除非您可以保证每个 选择器列表中的>选择器将占据一行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-17
    • 2019-12-01
    • 2021-12-23
    • 2020-04-10
    • 2020-05-21
    相关资源
    最近更新 更多