【问题标题】:Eslint CLI No files matching the pattern "['warn']'" were foundEslint CLI 找不到匹配模式“['warn']'”的文件
【发布时间】:2022-02-21 12:16:34
【问题描述】:

我正在尝试通过我的 create-react-app 中的 eslint CLI 对某些规则进行 lint。我想修正的规则是react/jsx-sort-props

起初我尝试了这里提供的修复单个规则的格式:How to fix just one rule using eslint

"fix-style":"eslint --fix --rule 'react/jsx-sort-props"

但这给出了错误:

Invalid value for option 'rule' - expected type Object, received value: 'react/jsx-sort-props.

ESLint CLI with --rule option 中讨论了此错误,但似乎没有任何解决方案有效。

跑步:

//package.json
"scripts": {
    "fix-style": "eslint --fix --rule 'react/jsx-sort-props: ['warn']'",
}

给予:

$ eslint --fix --rule 'react/jsx-sort-props: ['warn']'

Oops! Something went wrong! :(

ESLint: 7.32.0

No files matching the pattern "['warn']'" were found.
Please check for typing mistakes in the pattern.

那么修复单个规则的正确方法是什么?

操作系统:Windows 10

【问题讨论】:

    标签: reactjs eslint create-react-app react-scripts


    【解决方案1】:

    内部的单引号过早结束了规则字符串,所以使用双引号将整个字符串括起来

    试试:eslint --fix --rule "react/jsx-sort-props: ['warn']"

    【讨论】:

      【解决方案2】:

      在我的package.json中使用命令时需要转义双引号:

        "scripts": {
          "start": "react-scripts start",
          "build": "react-scripts build",
          "fix-style": "eslint --fix --rule \"react/jsx-sort-props: ['warn']\"",
        },
      
      

      【讨论】:

        猜你喜欢
        • 2021-01-12
        • 2020-06-06
        • 2019-07-29
        • 2013-10-19
        • 2022-12-07
        • 2018-07-04
        • 2017-07-19
        • 2020-08-05
        相关资源
        最近更新 更多