如何解决 StyleLint 中的“property-no-unknown”错误?

Jos*_*anc 2 wordpress sass stylelint

我有一个 Wordpress 项目,其中使用了 Webpack 和 StyleLint 插件。

问题是编译 sass 时,它显示此错误,表示它无法识别我在样式中使用的“aspect-ratio”属性:

Unexpected unknown property "aspect-ratio" property-no-unknown

我尝试将“ignoreProperties”添加到 .stylelintrc.js 文件中的配置中,但它不起作用并且一直显示错误。

module.exports = {
  'extends': 'stylelint-config-standard',
  'rules': {
'no-empty-source': null,
'string-quotes': 'double',
'at-rule-no-unknown': [
  true,
  { 
    'ignoreProperties': [
      'aspect-ratio'
    ] 
  },
  {
    'ignoreAtRules': [
      'extend',
      'at-root',
    ],
   },
  ],
 },
};
Run Code Online (Sandbox Code Playgroud)

我该如何解决它?(我对 StyleLint 不是很了解,这个项目是由其他人启动的。)

jed*_*dy3 5

aspect-ratio最新版本 Stylelint 中的已知属性。您应该使用以下命令将 Stylelint 副本更新到最新版本:

npm install -D stylelint@latest
Run Code Online (Sandbox Code Playgroud)

或者,您可以使用ignoreProperties辅助选项,但您应该在property-no-unknown规则上使用它,而不是在规则上使用它at-rule-no-unknown,因为它是一个属性,而不是 at 规则:

module.exports = {
  'extends': 'stylelint-config-standard',
  'rules': {
'no-empty-source': null,
'string-quotes': 'double',
'at-rule-no-unknown': [
  true,
  {
    'ignoreAtRules': [
      'extend',
      'at-root',
    ],
   },
  ],
 },
 'property-no-unknown': [
  true,
  { 
    'ignoreProperties': [
      'aspect-ratio'
    ] 
  },
 ]
};
Run Code Online (Sandbox Code Playgroud)