问题描述
- 情况1:如果是属性不存在, IDE 会提醒错误,但是 TSlint/ESlint 不会抛出错误
- 情况2:TSlint 只会抛出在 rules 中有定义的错误,例如下面限制了
no-empty-interface
的rules
, 就会抛出错误
相关代码
-
TSlint.json 文件
{ "defaultSeverity": "warning", "extends": [ "tslint:recommended" ], "linterOptions": { "exclude": [ "node_modules/**" ] }, "rules": { "quotemark": [true, "single"], "indent": [true, "spaces", 2], "interface-name": false, "ordered-imports": false, "object-literal-sort-keys": false, "no-consecutive-blank-lines": false } }
-
tsconfig.json
{ "compilerOptions": { "target": "esnext", "module": "esnext", "strict": true, "jsx": "preserve", "importHelpers": true, "moduleResolution": "node", "experimentalDecorators": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "sourceMap": true, "baseUrl": ".", "types": [ "node" ], "paths": { "@/*": [ "src/*" ] }, "lib": [ "esnext", "dom", "dom.iterable", "scripthost" ] }, "include": [ "src/**/*.ts", "src/**/*.tsx", "src/**/*.vue", "tests/**/*.ts", "tests/**/*.tsx" ], "exclude": [ "node_modules" ] }
你期待的结果是什么?
TSlint 能够检查到并抛出 TSlint 代码类型检查(情况1)的错误么?
如果能,如何设置?
如果不能,有什么方法可以在gitHooks.pre-commit
拦截(情况1)的错误,未解决错误禁止提交代码么?
我没有研究过TSlint,但是从软件开发的角度来讲,TSlint不应该抛出类型检查错误。
如果要加上类型检查,首先需要安装typescript
然后在
pre-commit
里加上调用tsc的代码。取决于是不是全局安装,代码会略有差异。