javascript - eslint 在没有错误的地方抛出错误
问题描述
我在运行时收到以下错误yarn eslint
:
/…/src/a.js
4:1 error Expected indentation of 1 tab but found 2 spaces indent
4:43 error Strings must use singlequote quotes
5:1 error Expected indentation of 2 tabs but found 4 spaces indent
6:1 error Expected indentation of 1 tab but found 2 spaces indent
6:6 error Strings must use singlequote quotes
✖ 5 problems (5 errors, 0 warnings)
5 errors and 0 warnings potentially fixable with the `--fix` option.
这是我的.eslintrc.js
文件:
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'eslint:recommended',
'plugin:react/recommended',
],
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 12,
sourceType: 'module',
},
plugins: ['react'],
settings: {
react: { version: 'detect' },
},
rules: {
indent: [
'error',
'tab'
],
'linebreak-style': [
'error',
'unix',
],
quotes: [
'error',
'single'
],
semi: [
'error',
'always'
]
}
};
…以及有问题的文件:
import React from "react";
import { css } from "./a.css";
export function App() {
\treturn (
\t\t<div className={css.App}>
\t\t\tHello.
\t\t</div>
\t);
}
注意:我\t
在这里包括以表示选项卡,因为 Stack Overflow 用 4 个空格替换了实际的选项卡。
eslint 报告的错误都不是文件中的实际错误。所有缩进都是正确的,我只使用单引号。见鬼,该文件中甚至没有第 43 行,因为 eslint 正在报告。
这里可能会发生什么?
解决方案
indent: [
'error',
'tab'
],
quotes: [
'error',
'single'
],
eslint 中的这条规则告诉您不应使用空格,而是使用制表键进行缩进,或者删除此规则,或者在发生 INDENT 错误的行上,您将找到用于缩进的空间,删除它们并使用 Tab 键也用于引用错误检查您使用单引号保存的字符串值的变量,如果您使用的是 vscode,那么您可能需要删除此规则或更新 vscode 设置并防止它在自动保存时将单引号更新为双引号
推荐阅读
- snowflake-cloud-data-platform - 如何在雪花中编写用户定义的函数?
- sql-server - LAG 仅在第一行工作。忽略所有其他以下行
- api - 相同的 HTTPS 请求在 Postman 中有效,但在 JMeter 中给出 400 Bad Request
- python - 根据条件为观察赋值
- freemarker - Liferay 7.3 广告
- sql - 我在 SSIS 中的条件拆分有什么问题?
- amazon-web-services - 同一 VPC 中的 AWS EC2 实例是否使用公共 IP 通过 Internet 连接?
- bash - bash中两个at符号(@)包围的变量是什么意思?
- vba - 在按钮完全执行代码后,如何使用 vba 更改用户窗体上命令按钮的颜色?
- android - Android 范围存储:在共享存储中创建文档