【问题标题】:Style Lint : Max Specificity Selector with RegexStylelint:带正则表达式的最大特异性选择器
【发布时间】:2019-06-04 17:58:25
【问题描述】:

我对 Style Lint 有疑问。我已将 selector-max-specificity 设置为 0,2,0 并忽略了一些规则:ignoreSelectors: [":focus", ":hover", etc..]

现在,我想忽略 :not(.myClass) 选择器,但这不起作用:(

例如,我有这个名字的班级:.track a:not(.track-visual)

我尝试过使用正则表达式选择器"/:not\\(.*\\)/" 甚至"/.*:not\\(.*\\)/"

但没有机会:'(

如果您有解决方案,我很感兴趣 :) 谢谢

【问题讨论】:

    标签: css regex stylelint


    【解决方案1】:

    我猜我们希望在这里捕获那些使用:not 的人,在这种情况下,我们将从一个简单的表达式开始,例如:

    .+?:not\(.+?\)
    

    Demo

    正则表达式电路

    jex.im 可视化正则表达式:

    【讨论】:

    • 感谢您的回复,我已经测试了您的解决方案,但这不起作用:'(我不明白为什么,因为例如,如果我想忽略选择器属性,这很好用: /\[.*\]/
    【解决方案2】:

    不要认为这是可以做到的。 latest code for the rule 包括以下内容:

    const ownSpecificity =
        ownValue === ':not' || ownValue === ':matches'
            ? // :not and :matches don't add specificity themselves, but their children do
              zeroSpecificity()
            : simpleSpecificity(ownValue);
    

    根据评论,这不包括 :not 本身,因为它会增加特异性,但包括其子项,这是正则表达式将检查的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-08
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多