Commit 1fb1cd1b4eb392dcf6ac73ae2897ca44811bc4d4
Committed by
GitHub
Merge pull request #5461 from yangdan8/2.0_加入tslint检测d.ts规范
添加tslint检测d.ts规范
Showing
3 changed files
with
154 additions
and
1 deletions
Show diff stats
package.json
| ... | ... | @@ -29,8 +29,9 @@ |
| 29 | 29 | "dist:locale": "webpack --config build/webpack.dist.locale.config.js", |
| 30 | 30 | "dist": "npm run dist:style && npm run dist:dev && npm run dist:prod && npm run dist:locale", |
| 31 | 31 | "lint": "eslint --fix --ext .js,.vue src", |
| 32 | + "tslint": "tslint --type-check --fix --project .", | |
| 32 | 33 | "unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run", |
| 33 | - "test": "npm run lint && npm run unit", | |
| 34 | + "test": "npm run lint && npm run tslint && npm run unit", | |
| 34 | 35 | "prepare": "npm run dist" |
| 35 | 36 | }, |
| 36 | 37 | "repository": { |
| ... | ... | @@ -103,6 +104,8 @@ |
| 103 | 104 | "sinon": "^4.4.2", |
| 104 | 105 | "sinon-chai": "^3.3.0", |
| 105 | 106 | "style-loader": "^0.20.2", |
| 107 | + "tslint": "^5.14.0", | |
| 108 | + "typescript": "^3.3.4000", | |
| 106 | 109 | "uglifyjs-webpack-plugin": "^1.3.0", |
| 107 | 110 | "url-loader": "^1.1.2", |
| 108 | 111 | "vue": "^2.5.17", | ... | ... |
| 1 | +{ | |
| 2 | + "compilerOptions": { | |
| 3 | + "target": "esnext", | |
| 4 | + "module": "esnext", | |
| 5 | + "strict": true, | |
| 6 | + "jsx": "preserve", | |
| 7 | + "importHelpers": true, | |
| 8 | + "moduleResolution": "node", | |
| 9 | + "experimentalDecorators": true, | |
| 10 | + "esModuleInterop": true, | |
| 11 | + "allowSyntheticDefaultImports": true, | |
| 12 | + "sourceMap": true, | |
| 13 | + "baseUrl": ".", | |
| 14 | + "paths": { | |
| 15 | + "@/*": ["src/*"] | |
| 16 | + }, | |
| 17 | + "lib": ["esnext", "dom", "dom.iterable", "scripthost"] | |
| 18 | + }, | |
| 19 | + "include": [ | |
| 20 | + "types/*.ts", | |
| 21 | + ], | |
| 22 | + "exclude": ["node_modules"] | |
| 23 | +} | ... | ... |
| 1 | +{ | |
| 2 | + "defaultSeverity": "warning", | |
| 3 | + "extends": ["tslint:recommended"], | |
| 4 | + "linterOptions": { | |
| 5 | + "exclude": ["node_modules/**"] | |
| 6 | + }, | |
| 7 | + "rules": { | |
| 8 | + "jsx-boolean-value": false, | |
| 9 | + "jsx-curly-spacing": false, | |
| 10 | + "jsx-no-multiline-js": false, | |
| 11 | + "jsx-wrap-multiline": false, | |
| 12 | + "jsx-alignment": false, | |
| 13 | + "jsx-no-lambda": true, | |
| 14 | + "jsx-no-string-ref": false, | |
| 15 | + "class-name": false, | |
| 16 | + "max-line-length": [true, 180], | |
| 17 | + "member-ordering": [true, "statics-first"], | |
| 18 | + "new-parens": true, | |
| 19 | + "no-consecutive-blank-lines": true, | |
| 20 | + "no-mergeable-namespace": true, | |
| 21 | + "no-switch-case-fall-through": true, | |
| 22 | + "no-trailing-whitespace": true, | |
| 23 | + "no-unused-variable": [true], | |
| 24 | + "no-var-keyword": true, | |
| 25 | + "one-variable-per-declaration": [false, "ignore-for-loop"], | |
| 26 | + "triple-equals": [false, "allow-null-check"], | |
| 27 | + "use-isnan": false, | |
| 28 | + //ts专用 | |
| 29 | + "prefer-const": false, //true, //const偏好 | |
| 30 | + "adjacent-overload-signatures": true, //Enforces function overloads to be consecutive. | |
| 31 | + "ban-comma-operator": true, //禁止逗号运算符。 | |
| 32 | + "ban-type": [true, ["object", "User {} instead."], ["string"]], //禁止类型 | |
| 33 | + //"member-access": [true, "no-public" || "check-accessor" || "check-constructor" || "check-parameter-property"], //类成员必须声明 private public .... | |
| 34 | + "member-order": [false], //类声明排序 | |
| 35 | + "no-any": false, //true, //不需使用any类型 | |
| 36 | + "no-empty-interface": true, //禁止空接口 {} | |
| 37 | + "no-import-side-effect": [ | |
| 38 | + true, | |
| 39 | + { | |
| 40 | + "ignore-module": "(\\.html|\\.css)$" | |
| 41 | + } | |
| 42 | + ], //禁止导入带有副作用的语句 | |
| 43 | + "no-inferrable-types": [true, "ignore-params", "ignore-properties"], //不允许将变量或参数初始化为数字,字符串或布尔值的显式类型声明。 | |
| 44 | + "no-internal-module": true, //不允许内部模块 | |
| 45 | + "no-magic-numbers": false, //[true, 1, 2, 3], //不允许在变量赋值之外使用常量数值。当没有指定允许值列表时,默认允许-1,0和1 | |
| 46 | + "no-namespace": false, //[true, "allpw-declarations"], //不允许使用内部modules和命名空间 | |
| 47 | + "no-non-null-assertion": true, //不允许使用!后缀操作符的非空断言。 | |
| 48 | + "no-parameter-reassignment": false, //true, //不允许重新分配参数 | |
| 49 | + "no-reference": false, //true, // 禁止使用/// <reference path=> 导入 ,使用import代替 | |
| 50 | + "no-unnecessary-type-assertion": true, //如果类型断言没有改变表达式的类型就发出警告 | |
| 51 | + "no-var-requires": true, //不允许使用var module = require("module"),用 import foo = require('foo')导入 | |
| 52 | + "only-arrow-functions": false, //[true, "allow-declarations", "allow-named-functions"], //允许箭头表达式,不需要传统表达式 ; 允许独立的函数声明 ;允许表达,function foo() {}但不是function() {} | |
| 53 | + "prefer-for-of": true, //建议使用for(..of) | |
| 54 | + "promise-function-async": true, //要求异步函数返回promise | |
| 55 | + "typedef": false, //[true, "call-signature", "parameter", "member-variable-declaration"], // 需要定义的类型存在 | |
| 56 | + "typedef-whitespace": true, //类型声明的冒号之前是否需要空格,在类型定义的时候,是否允许使用空格, 使用false,表示不对此项进行校验,不启用此项的校验 | |
| 57 | + "unified-signatures": true, //重载可以被统一联合成一个 | |
| 58 | + //function 专用 | |
| 59 | + "await-promise": true, //警告不是一个promise的await | |
| 60 | + // "ban": [ | |
| 61 | + // true, | |
| 62 | + // "eval", | |
| 63 | + // { | |
| 64 | + // "name": "$", | |
| 65 | + // "message": "please don't" | |
| 66 | + // }, | |
| 67 | + // ["describe", "only"], | |
| 68 | + // { | |
| 69 | + // "name": ["it", "only"], | |
| 70 | + // "message": "don't focus tests" | |
| 71 | + // }, | |
| 72 | + // { | |
| 73 | + // "name": ["chai", "assert", "equal"], | |
| 74 | + // "message": "Use 'strictEqual' instead." | |
| 75 | + // }, | |
| 76 | + // { | |
| 77 | + // "name": ["*", "forEach"], | |
| 78 | + // "message": "Use a regular for loop instead." | |
| 79 | + // } | |
| 80 | + // ], | |
| 81 | + "curly": true, //for if do while 要有括号 | |
| 82 | + "forin": false, //true, //用for in 必须用if进行过滤 | |
| 83 | + "import-blacklist": true, //允许使用import require导入具体的模块 | |
| 84 | + "label-postion": true, //允许在do/for/while/swith中使用label | |
| 85 | + "no-arg": true, //不允许使用 argument.callee | |
| 86 | + "no-bitwise": false, //true, //不允许使用按位运算符 | |
| 87 | + "no-conditional-assignmen": true, //不允许在do-while/for/if/while判断语句中使用赋值语句 | |
| 88 | + "no-console": [true, "time", "timeEnd"], //不能使用console | |
| 89 | + "no-construct": true, //不允许使用 String/Number/Boolean的构造函数 | |
| 90 | + "no-debugger": true, //不允许使用debugger | |
| 91 | + "no-duplicate-super": true, //构造函数两次用super会发出警告 | |
| 92 | + "no-empty": false, //true, //不允许空的块 | |
| 93 | + "no-eval": true, //不允许使用eval | |
| 94 | + "no-floating-promises": true, //必须正确处理promise的返回函数 | |
| 95 | + "no-for-in-array": true, //不允许使用for in 遍历数组 | |
| 96 | + "no-implicit-dependencies": true, //不允许在项目的package.json中导入未列为依赖项的模块 | |
| 97 | + "no-inferred-empty-object-type": true, //不允许在函数和构造函数中使用{}的类型推断 | |
| 98 | + "no-invalid-template-strings": true, //警告在非模板字符中使用${ | |
| 99 | + "no-invalid-this": false, //true, //不允许在非class中使用 this关键字 | |
| 100 | + "no-misused-new": true, //禁止定义构造函数或new class | |
| 101 | + "no-null-keyword": false, // true, //不允许使用null关键字 | |
| 102 | + "no-object-literal-type-assertion": false, //true, //禁止objext出现在类型断言表达式中 | |
| 103 | + "no-return-await": true, //不允许return await | |
| 104 | + "arrow-parens": false, //true, //箭头函数定义的参数需要括号 | |
| 105 | + "quotemark": [true, "single", "jsx-double", "avoid-escape"], //引号的使用规则 | |
| 106 | + "semicolon": false, //[true, "never", "ignore-interfaces"], //分号的使用规则 | |
| 107 | + "indent": false, //[true, "tabs", 2], //使用Tab进行缩进,每次强制缩进2个字符 | |
| 108 | + "whitespace": [ | |
| 109 | + true, | |
| 110 | + "check-branch", | |
| 111 | + "check-decl", | |
| 112 | + "check-operator", | |
| 113 | + "check-type" | |
| 114 | + ], //空格的校验 | |
| 115 | + "member-access": false, //类成员的显示可见性声明,即显示定义一个类的成员是否可见,即对类成员定义public | static 等 | |
| 116 | + "one-line": false //, //要求指定的标记与它们之前的表达式位于同一行 | |
| 117 | + // "trailing-comma": [true, { //对尾随逗号的校验 | |
| 118 | + // "multiline": { | |
| 119 | + // "objects": "ignore", | |
| 120 | + // "arrays": "never", | |
| 121 | + // "functions": "never", | |
| 122 | + // "typeLiterals": "ignore" | |
| 123 | + // }, | |
| 124 | + //"esSpecCompliant": true //是否允许尾随逗号出现在剩余变量中 | |
| 125 | + // }] | |
| 126 | + } | |
| 127 | +} | ... | ... |