eslint - 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 在此文件中不返回任何内容或其他一些警告/错误。
eslintrc 在这里
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
以便收到“类型中缺少属性”错误消息的通知,并在构建失败时进行修复。
这非常不方便,因为每次构建尝试我只会收到一个错误警报。如果有人有更好的解决方案,我将不胜感激。
推荐阅读
- c# - C#无法从导入的库中反序列化类的对象
- powershell - 从自定义属性中列出的每个 CN 获取电子邮件地址
- html - HTML/VBA 在特定时间自动发送电子邮件
- python - 分层组 Django 查询
- r - 使用 ifelse 有条件地在 tidyr r 中使用单独
- google-cloud-platform - GSuite OAuth 客户端 ID
- mysql - 像这样的响应“错误代码:2068。由于访问限制,LOAD DATA LOCAL INFILE 文件请求被拒绝。” 当我从 CSV 加载数据时
- cesium - QuadTreeProvider 和 WFS 数据
- macos - macOS - 如何在 /Volumes 中找到“僵尸”文件夹(不是挂载)
- reactjs - 通过从 useSelector Hook 返回的 Props 传递字符串值