为什么TSLint只检查src目录?
tsconfig.json
{
"compilerOptions": {
"outDir": "./built",
"allowJs": true,
"target": "es5",
"typeRoots": ["node_modules/@types", "typings"]
},
"include": ["./src/**/*", "./typings/**/*"],
"exclude": ["node_modules"]
}
tslint.json
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {},
"rulesDirectory": []
}
检查整个项目
仅显示src目录错误
tslint --project .
ERROR: /Users/kiwenlau/Desktop/tslint-test/src/index.ts:1:1 - Forbidden 'var' keyword, use 'let' or 'const' instead
检查src目录
tslint "src/**/*"
ERROR: src/index.ts:1:1 - Forbidden 'var' keyword, use 'let' or 'const' instead
检查打字目录
tslint "typings/**/*"
ERROR: typings/index.d.ts:1:11 - interface name must start with a capitalized I
请检查kiwenlau/tslint-test以获取源代码。
答案 0 :(得分:2)
如this github issue中所述,TSLint在处理来自.d.ts
的{{1}}路径时会忽略include
文件。
不幸的是,TSLint不再在开发中,因此永远不会改变。官方建议是将ESLint与typescript-eslint结合使用。您可以在this blog post中了解更多相关信息。
如果您想暂时继续使用TSLint,则可以在调用时指定两个路径:
tsconfig.json
或更短一些:
tslint "src/**/*" "typings/**/*"
答案 1 :(得分:1)
即使这个问题
TSLint ignores .d.ts files when processing the include paths from tsconfig.json.
上面答案中提到的是固定的,或者使用了另一个linter,但是文件./typings/index.d.ts
仍然可以被任何linter忽略,就像Typescript编译器一样,它认为possible output是一个{{3}}文件src/index.ts
。
执行tslint "typings/**/*"
使src/index.ts
不在考虑之列,因此文件./typings/index.d.ts
不再被忽略。
答案 2 :(得分:0)
使用Visual Studio Code的TSLint扩展名时,只需将tslint.ignoreDefinitionFiles
设置为false
,就可以解决问题。