@gdjiami/cli
Version:
CLI for build front end project.
280 lines • 10.3 kB
JSON
/**
* jm tslint 规范, 这里不会定义代码格式化相关的规则, 这个会被prettier处理. 所以这里定义了
* prettier这些格式化工具无法覆盖的规范
*/
{
"defaultSeverity": "warning",
"extends": ["tslint-react"],
"jsRules": {},
"rules": {
/*-----------------------
* Typescript 相关
*-------------------------*/
// 方法重载声明要连续
"adjacent-overload-signatures": true,
// 定义一些禁止使用的类型
"ban-types": [
true,
["Object", "Use {} instead."],
["String", "Use string instead."],
["Function", "Use () => void instead"]
],
// 需要显式设置成员的访问修饰符
"member-access": true,
// 规定类成员的声明顺序
"member-ordering": [
true,
{
"order": [
// 字段
"public-static-field",
"protected-static-field",
"private-static-field",
"public-instance-field",
"protected-instance-field",
"private-instance-field",
// 静态方法
"public-static-method",
"protected-static-method",
"private-static-method",
// 构造方法
"public-constructor",
"protected-constructor",
"private-constructor",
// 实例变量
"public-instance-method",
"protected-instance-method",
"private-instance-method"
]
}
],
// 禁止any
"no-any": true,
// 不要使用magic number, 比如foo(1), 1代表什么意思? 应该使用常量保存下来
// 暂时禁用, 会误判, 比如是地图坐标
"no-magic-numbers": false,
// 不要重新赋值参数
"no-parameter-reassignment": true,
// 禁止使用 /// <refrence path=>
"no-reference": true,
"no-unnecessary-type-assertion": true,
// const value = require('xxx') 在某些场景还是有用, 比如想逃避类型检查
"no-var-requires": false,
// 更多情况下应该使用箭头函数, 这里运行function name() {}这样的定义, 不允许function(){}传统的匿名函数方式
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"],
"prefer-for-of": true,
// 如果两个重载的方法, 可以使用union或者可选参数等方法处理. 则优先后者
"unified-signatures": true,
/*-----------------------
* 函数 相关
*-------------------------*/
// 禁止await 非promise
"await-promise": true,
// 禁止使用逗号表达式
"ban-comma-operator": true,
// 定义不应该使用的函数或全局方法
"ban": [true, "eval", "with"],
// 对于for, if, 总是要求使用{}
"curly": true,
// for in 时需要判断hasOwnProperty
"forin": true,
// 禁止直接导入的包, 应该引用它的子包
"import-blacklist": [true, "lodash", "rxjs"],
// 禁止滥用label
"label-position": true,
// 不要使用arguments.callee
"no-arg": true,
// 不到迫不得已不要使用二级制操作符, 因为很难理解
"no-bitwise": true,
// 不要在条件语句的赋值, 如if (a = 1)
"no-conditional-assignment": true,
// console对性能有影响
"no-console": [true, "log"],
// 不允许使用String, Number等作为构造函数使用, 如 new Number(1)
"no-construct": true,
"no-debugger": true,
"no-duplicate-super": true,
"no-duplicate-switch-case": true,
"no-duplicate-variable": true,
// delete 一个计算的key, 并没有很好的优化, 如果要动态删除, 推荐使用Map或Set
"no-dynamic-delete": true,
// 禁止空的函数或catch, 可以使用注释说明
"no-empty": true,
"no-eval": true,
"no-for-in-array": true,
// promise 必须被处理
"no-floating-promises": false,
"no-invalid-template-strings": true,
// 禁止在类之外使用this
"no-invalid-this": true,
// 禁止不正确使用new
"no-misused-new": true,
// 禁止使用null, 因为undefined和null在职责上面是有些重叠的. 最初Javascript发明undefined就是为了表示一个值
// 不存在. 而null则跟Java引用对象的概念一样, 表示一个引用为空. 所以推荐只使用一种方式, 避免困惑
"no-null-keyword": false,
// 相比const x = { ... } as T 更推荐const x: T = { ... }
"no-object-literal-type-assertion": false,
// return await 没有必要
"no-return-await": true,
// 即父作用域定义的变量, 不应该在当前作用域定义. 容易导致bug
"no-shadowed-variable": true,
// 禁止使用[,,]这种稀疏数组
"no-sparse-arrays": true,
// 禁止obj["property"], 应使用obj.property
"no-string-literal": true,
// throw 应该是Error对象
"no-string-throw": true,
// 禁止switch case语句穿透, 应该比较容易出bug, 如果确定要穿透, 可以使用/* falls through */注释
"no-switch-case-fall-through": true,
// 不要使用this赋值, 应该使用箭头函数. 对象解构除外
"no-this-assignment": [
true,
{
"allowed-names": ["^self$"],
"allow-destructuring": true
}
],
// 不要将未绑定的方法传递给其他方法或赋值. 应该转换为箭头函数
"no-unbound-method": false,
"no-unnecessary-class": true,
"no-unsafe-any": false,
"no-unsafe-finally": true,
"no-unused-expression": [true, "allow-fast-null-checks", "allow-tagged-template"],
"no-use-before-declare": true,
// 禁止使用var
"no-var-keyword": true,
// 使用对象解构取代Object.assign
"prefer-object-spread": true,
// 在使用parseInt时, 要指定radix
"radix": true,
// 在相加两个值时, 类型必须一样
"restrict-plus-operands": true,
// 如果条件断言永远是true或false时警告
"strict-type-predicates": false,
"switch-default": true,
// 优先使用===进行比较
"triple-equals": [true, "allow-null-check", "allow-undefined-check"],
"use-isnan": true,
/*-----------------------
* 可维护性 相关
*-------------------------*/
// 圈复杂度, 是对一个函数的复杂度估算. 如果复杂度高则说明应该拆分
"cyclomatic-complexity": true,
// 禁止使用deprecated的API
"deprecation": true,
// 一个文件只能声明一个类
"max-classes-per-file": [true, 1, "exclude-class-expressions"],
"max-file-line-count": [true, 500],
"max-line-length": [true, 120],
"no-duplicate-imports": true,
// 字面量字段排序
"object-literal-sort-keys": false,
"prefer-const": true,
/*-----------------------
* 样式相关 相关(大部分忽略, 由prettier处理)
*-------------------------*/
// 推荐使用T[] 来声明数组, 而不是Array<T>
"array-type": false,
"arrow-return-shorthand": true,
// 二元操作符变量在先, 如 x + 1
"binary-expression-operand-order": true,
"callable-types": true,
// 类名必须是大写驼峰式
"class-name": true,
// 单行注释必须以空格开头
"comment-format": [true, "check-space"],
// 以下组件必须提供注释
// FIXME: 目前还没有过滤机制, 比如一些总所周知的方法, 如render, 不需要注释
"completed-docs": [
true,
{
"enums": true,
"methods": {
"privacies": "public",
"locations": "all"
},
"properties": {
"privacies": "public",
"locations": "all"
},
"classes": {
"visibilities": "exported"
},
"functions": {
"visibilities": "exported"
},
"interfaces": {
"visibilities": "exported"
},
"namespaces": {
"visibilities": "exported"
},
"types": {
"visibilities": "exported"
},
"variables": {
"visibilities": "exported"
}
}
],
// 优先使用interface, 而不是type
"interface-over-type-literal": true,
// 提供文件注释, 可以在默认导出上进行注释, 让一些文档生成工具可以更好地识别
"file-header": false,
"encoding": true,
// 不要使用I*这种接口形式
"interface-name": false,
// 注释使用jsdoc规范
"jsdoc-format": true,
"match-default-export-name": false,
"new-parens": true,
// 使用as关键字, 而不是<>来进行类型断言
"no-angle-bracket-type-assertion": true,
"no-boolean-literal-compare": true,
// 不要使用Typescript的构造函数的参数化的属性, 如constructor(public value: string)
"no-parameter-properties": true,
"no-reference-import": true,
// 避免没有必要的回调包装如, x => f(x), 直接使用f就可以了
"no-unnecessary-callback-wrapper": true,
// 避免没有必要的初始化, 如 let x = undefined
"no-unnecessary-initializer": true,
"no-unnecessary-qualifier": true,
"number-literal-format": true,
// 按字母顺序对import进行排序
"ordered-imports": [
true,
{
"named-imports-order": "any",
"import-sources-order": "case-insensitive",
// 对import进行分组, 比如"bar", "../baz", "./foo" 按照相对路径分组
"grouped-imports": true,
"module-source-path": "full"
}
],
"prefer-method-signature": false,
"prefer-switch": [
true,
{
"min-cases": 3
}
],
"prefer-template": [true, "allow-single-concat"],
"prefer-while": true,
"return-undefined": true,
// 只允许UPPER_CASE,lowerCamelCase,UpperCamelCase
"variable-name": [true, "ban-keywords", "check-format", "allow-pascal-case"],
"object-literal-shorthand": true,
"promise-function-async": false,
/*-----------------------
* React 相关(大部分忽略, 由prettier处理)
*-------------------------*/
"jsx-wrap-multiline": false,
"jsx-boolean-value": [true, "never"],
"jsx-no-multiline-js": false,
"jsx-no-lambda": true,
"jsx-key": true,
"jsx-no-string-ref": true,
"jsx-curly-spacing": false
},
"rulesDirectory": []
}