cmd eslint 找不到 IDE 发现的 ts 错误



我想在cmd中使用eslint来检查ts文件,但它无法获取我在IDE中得到的错误信息。

我在eslintrc.js中设置了@typescript-eslint/parser。当我做错一些事情时,在 cmd 中运行的 eslint 给了我一些 ts 错误。但是没有发现其他一些错误。

我有一个带有代码的 ts 文件:

interface Item {
name: string;
age: number;
}
const config: Array<Item> = [{
name: 'foo',
}]

所以,我在 IDE 中遇到了一些错误:

Property 'age' is missing in type '{ name: string; age: number }' but required in type 'Item'.ts(2741)

那个权利。我需要此错误信息。

但是当我在 cmd 中运行 eslint 时

eslint fileName.ts  or  eslint --ext .ts fileName.ts

cmd eslint 在此文件中不返回任何内容或其他警告/错误。

埃斯林特克在这里


module.exports = {
"extends": ["xxx"],
"globals": {
"__SERVER_ENV__": true,
},
"rules": {
"react/jsx-filename-extension": 0,
"no-console": ["warn", { allow: ["error", "warn"] }],
"@typescript-eslint/no-unused-vars": ["error", {
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": true
}],
},
"settings": {
"react": {
"createClass": "createReactClass", // Regex for Component Factory to use,
// default to "createReactClass"
"pragma": "React",  // Pragma to use, default to "React"
"version": "detect", // React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
},
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
// use <root>/tsconfig.json
"typescript": {
// always try to resolve types under `<roo/>@types` directory even it doesn't contain any source code, like`@types/unist`
"alwaysTryTypes": true,
"directory": "./",
},
},
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"modules": true,
},
},
"plugins": ["@typescript-eslint", "import"],
};

和 tsconfig.json

{
"compilerOptions": {
"experimentalDecorators": true,
"noImplicitAny": true,
"module": "commonjs",
"lib": ["es6","dom","es2017"],
"target": "es5",
"jsx": "react",
"types":["react"],
"outDir": "/output",
"baseUrl": ".",
"paths": {
"src/*": ["./src/*"]
},
"allowSyntheticDefaultImports": true,
"sourceMap": true
},
"awesomeTypescriptLoaderOptions": {
"useWebpackText": true,
"useTranspileModule": true,
"doTypeCheck": true,
"forkChecker": true
},
"include": [
".d.ts",
"./src/**/*"
]
}

我希望通过cmd获得完整的错误信息。 我该怎么办?

看来 eslint 在设计上不会执行您的 Typescript 类型检查。我只是在本地运行我的构建命令,使用tsc来通知此"类型中缺少属性"错误消息,并在构建失败时修复。

这非常不方便,因为我每次构建尝试只会收到一个错误的警报。如果有人有更好的解决方案,我将不胜感激任何帮助。

最新更新