我有两个具有相同package.json tsconfig.json和tslint.json文件(只是副本)的nodejs项目。当我在两个项目上致电tslint时,我会有不同的结果。在第一个项目中,一切正常,但是在第二个项目中,我有属性必须存在文档皮棉错误。
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"suppressImplicitAnyIndexErrors": true,
"target": "ES6",
"moduleResolution": "node",
"removeComments": false,
"sourceMap": false,
"noLib": false,
"declaration": true,
"lib": ["es5", "es6", "scripthost"],
"outDir": "dist",
"rootDir": "./"
},
"include": [
"src/**/*",
"test.ts"
// "test/**/*",
// "bdd/**/*.ts"
]
}
tslint.json:
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {},
"rules": {
"completed-docs": [
true,
{
"properties": {
"privacies": [
"public",
"protected"
]
},
"methods": {
"privacies": [
"public",
"protected"
]
},
"classes": true,
"functions": true,
"interfaces": true,
"namespaces": true,
"types": true
}
],
"max-line-length": false,
"no-trailing-whitespace": false,
"max-classes-per-file": false,
"array-type": false,
"file-header": true,
"only-arrow-functions": false,
"object-literal-sort-keys": false
},
"rulesDirectory": []
}
package.json:
{
"name": "testProj",
"version": "18.9.0",
"description": "",
"author": {
"name": "Me"
},
"license": "MIT",
"engines": {
"node": ">=4.8"
},
"scripts": {
"lint": "tslint test.ts --project ./tsconfig.json"
},
"dependencies": {
"@types/request": "^2.47.0",
"request": "^2.87.0",
"request-debug": "^0.2.0"
},
"devDependencies": {
"@types/chai": "^4.0.10",
"@types/mocha": "^2.2.44",
"asposestoragecloud": "^1.0.5",
"chai": "^4.1.2",
"cross-env": "^5.1.4",
"cucumber": "^3.0.0",
"del": "^3.0.0",
"gulp": "^4.0.0",
"gulp-cucumber": "0.0.23",
"gulp-typescript": "^4.0.1",
"gulp-util": "^3.0.8",
"mocha": "^4.0.1",
"mocha-cases": "^0.2.1",
"mocha-jenkins-reporter": "^0.4.0",
"mocha-sinon": "^2.0.0",
"sinon": "^4.1.3",
"ts-node": "^4.0.2",
"tslint": "^5.8.0",
"typescript": "^2.7.1"
}
}
test.ts:
/**
* Some awesome class
*/
export class MyCheckClass {
/**
* Very usefull method
* @param checkParameter Some unused parameter
*/
public myCheckMethod(checkParameter: string): Promise<{ code: number, data: string }> {
return new Promise((resolve, reject) => {
resolve({code : 200, data: "My Success Data"});
});
}
}
试图添加@ ts-ignore-无济于事,尝试使用@typedef添加有关返回类型的文档-无用。 什么是使linter不检查此类情况文档的正确方法,或者至少如何为退货类型创建适当的文档?
PS。在第一个项目中,这种情况不会导致linter引发错误-都一样。但是我发现的内容-如果我使用的是全局安装的tslint(只是卸载了node_modules文件夹)-会出现相同的错误,但是在 npm安装之后-可以正常工作。
答案 0 :(得分:0)
您看到的“文档必须存在”投诉来自TSLint(不是TypeScript)。 // @ts-ignore
仅适用于TypeScript投诉(不适用于TSLint),因此无济于事。
相反,您有两种选择:
tslint.json
对象(completed-docs
)内的"completed-docs": false
禁用"rules"
文件中的docs规则// tslint:disable-next-line:completed-docs
(docs)对于上下文,TSLint和TypeScript是两个单独的工具。 TypeScript是将.ts
/ .tsx
文件转换为.js
的语言; TSLint使用TypeScript来扫描您的代码中的问题。
关于为什么您在不同项目中看到的TSLint行为不同,也许您的版本不同?与5.12相比,TSLint 5.13改变了completed-docs
的运行方式。