我在我的配置中禁用了数组的逗号悬挂eslintrc
,如下所示:
{
"parser": "@typescript-eslint/parser",
"extends": ["airbnb-typescript", "plugin:@typescript-eslint/recommended"],
"rules": {
"react/jsx-filename-extension": "off",
"import/newline-after-import": ["error", { "count": 1 }],
"lines-between-class-members": "error",
"newline-before-return": "error",
"quotes": ["error", "single"],
// here
"comma-dangle": [
"error",
{
"arrays": "never",
"objects": "always",
"imports": "never",
"exports": "never",
"functions": "never"
}
],
"react/prop-types": "off"
},
"ignorePatterns": ["config", "public", "scripts"]
}
这是我的数组:const foo = [1, 2, 3];
VS Code不会突出显示任何错误以将尾随逗号添加到 的最后一个元素foo
,而 Typescript 无法编译并出现以下错误:Missing trailing comma comma-dangle。出于某种原因,Typescript无法遵循我的.eslintrc
配置中编写的规则。
tsconfig:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": ["src"]
}
该项目是创建create-react-app
打字稿模板。你能指导我在这里做错什么吗?谢谢 :)