简体   繁体   English

为什么 ESLint 看不到 JS 文件的所有引号问题?

[英]Why ESLint doesn't see all the quotes problems of a JS file?

Problem: ESLint doesn't see all the quotes problems in my JS file where I use React.问题: ESLint 在我使用 React 的 JS 文件中没有看到所有引号问题。

Expected: See that ESLint checks my errors and show them to me.预期:看到 ESLint 检查我的错误并将它们显示给我。

Things that I tried: I changed some quotes to see the difference and I saw that for the imports ESLint is working, but in the components it doesn't.我尝试过的事情:我更改了一些引号以查看差异,并且我看到对于导入 ESLint 正在工作,但在组件中却没有。 I checked my rules and there is the 'quotes' rule.我检查了我的规则,并且有“引号”规则。 I checked my errors to be exactly and just for quotes and I saw that there weren't any problems.我检查了我的错误是否准确,只是为了引用,我发现没有任何问题。


I will attach an image with the problem:我将附上一张有问题的图片:


在此处输入图像描述


As you can see, in the first line is everything ok, because I put double quotes.如您所见,第一行一切正常,因为我放了双引号。 Then in the second and in the third lines there are simple quotes and ESLint can see them.然后在第二行和第三行有简单的引号,ESLint 可以看到它们。 It can be seen that ESLint can see just the quotes problem, nothing more.可以看出,ESLint 只能看到引号问题,仅此而已。

And then, then it comes the problem.然后,问题就来了。 At the 'flex-container' it can't see that there must be double quotes and it can't fix that.在 'flex-container' 中,它看不到必须有双引号,它无法解决这个问题。 And it's not just an exeption, because on the last line are also single quotes and it can't see that.这不仅仅是一个例外,因为在最后一行也是单引号,它看不到。

My.eslintrc.json file: My.eslintrc.json 文件:

{
    "env": {
        "browser": true,
        "es2021": true,
        "node": true,
        "amd": true,
        "jquery": true
    },
    "extends": [
        "eslint:recommended",
        "plugin:react/recommended"
    ],
    "parserOptions": {
        "ecmaVersion": 12,
        "sourceType": "module"
    },
    "rules": {
        "react/prop-types": "off",
        "react/jsx-uses-react": "warn",
        "react/react-in-jsx-scope": "off",
        "quotes": [
            "error",
            "double",
            {
                "avoidEscape": true
            }
        ]
    },
    "globals": {
        "React": true,
        "ReactDOM": true,
        "ReactRedux": true,
        "ReactRouterDOM": true,
        "Redux": true
    },
    "settings": {
        "react": {
            "version": "detect"
        }
    }
}

There I changed some properties for rules, to put 'error' instead of 'off' or 'warn', but it is the same.在那里我更改了规则的一些属性,将“错误”而不是“关闭”或“警告”,但它是相同的。

What can I do?我能做些什么?

So, the answer from the ESLint authors is:所以,ESLint 作者的回答是:

"The quotes rule works as intended in this case, because it checks only string literals. “在这种情况下, quotes规则按预期工作,因为它只检查字符串文字。

For JSX attributes you can use the jsx-quotes rule, as in this demo ."对于 JSX 属性,您可以使用jsx-quotes规则,就像在这个演示中一样。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM