为什么TSLint只检查src目录?

时间:2019-09-01 09:30:37

标签: typescript tslint

为什么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以获取源代码。

3 个答案:

答案 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,就可以解决问题。