TSLint core rules

原文:https://palantir.github.io/tslint/rules/

Lint rules encode logic for syntactic & semantic checks of TypeScript source code.

TypeScript-specific

These rules find errors related to TypeScript features:

adjacent-overload-signatures - Enforces function overloads to be consecutive.

ban-ts-ignore - Bans “// @ts-ignore” comments from being used.

ban-types - Bans specific types from being used. Does not ban the corresponding runtime objects from being used.

member-access - Requires explicit visibility declarations for class members.

member-ordering - Enforces member ordering.

no-any - Disallows usages of any as a type declaration.

no-empty-interface - Forbids empty interfaces.
no-import-side-effect - Avoid import statements with side-effect.

no-inferrable-types - Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.

no-internal-module - Disallows internal module
no-magic-numbers - Disallows the use constant number values outside of variable assignments. When no list of allowed values is specified, -1, 0 and 1 are allowed by default.

no-namespace - Disallows use of internal modules and namespaces.

no-non-null-assertion - Disallows non-null assertions using the ! postfix operator.
no-parameter-reassignment - Disallows reassigning parameters.
no-reference - Disallows /// <reference path=> imports (use ES6-style imports instead).

Requires Type Info
no-unnecessary-type-assertion - Warns if a type assertion does not change the type of an expression.

no-var-requires - Disallows the use of require statements except in import statements.
only-arrow-functions - Disallows traditional (non-arrow) function expressions.
prefer-for-of - Recommends a ‘for-of’ loop over a standard ‘for’ loop if the index is only used to access the array being iterated.
Requires Type Info
promise-function-async - Requires any function or method that returns a promise to be marked async.

typedef - Requires type definitions to exist.

typedef-whitespace - Requires or disallows whitespace for type definitions.

unified-signatures - Warns for any two overloads that could be unified into one by using a union or an optional/rest parameter.
Functionality
These rules catch common errors in JS programming or otherwise confusing constructs that are prone to producing bugs:

Requires Type Info
await-promise - Warns for an awaited value that is not a Promise.
ban-comma-operator - Disallows the comma operator to be used.
ban - Bans the use of specific functions or global methods.

curly - Enforces braces for if/for/do/while statements.
forin - Requires a for … in statement to be filtered with an if statement.
function-constructor - Prevents using the built-in Function constructor.
import-blacklist - Disallows importing the specified modules via import and require, or importing specific named exports of the specified modules.
label-position - Only allows labels in sensible locations.
no-arg - Disallows use of arguments.callee.
no-bitwise - Disallows bitwise operators.
no-conditional-assignment - Disallows any type of assignment in conditionals.
no-console - Bans the use of specified console methods.
no-construct - Disallows access to the constructors of String, Number, and Boolean.
no-debugger - Disallows debugger statements.
no-duplicate-super - Warns if ‘super()’ appears twice in a constructor.
no-duplicate-switch-case - Prevents duplicate cases in switch statements.
no-duplicate-variable - Disallows duplicate variable declarations in the same block scope.
no-dynamic-delete - Bans usage of the delete operator with computed key expressions.
no-empty - Disallows empty blocks.
no-eval - Disallows eval function invocations.

Requires Type Info
no-floating-promises - Promises returned by functions must be handled appropriately.
Requires Type Info
no-for-in-array - Disallows iterating over an array with a for-in loop.
no-implicit-dependencies - Disallows importing modules that are not listed as dependency in the project’s package.json

Requires Type Info
no-inferred-empty-object-type - Disallow type inference of {} (empty object type) at function and constructor call sites
no-invalid-template-strings - Warns on use of ${ in non-template strings.
no-invalid-this - Disallows using the this keyword outside of classes.

no-misused-new - Warns on apparent attempts to define constructors for interfaces or new for classes.

no-null-keyword - Disallows use of the null keyword literal.

no-object-literal-type-assertion - Forbids an object literal to appear in a type assertion expression. Casting to any or to unknown is still allowed.

no-return-await - Disallows unnecessary return await.
no-shadowed-variable - Disallows shadowing variable declarations.
no-sparse-arrays - Forbids array literals to contain missing elements.

no-string-literal - Forbids unnecessary string literal property access. Allows obj[“prop-erty”] (can’t be a regular property access). Disallows obj[“property”] (should be obj.property).

no-string-throw - Flags throwing plain strings or concatenations of strings.
no-submodule-imports - Disallows importing any submodule.
no-switch-case-fall-through - Disallows falling through case statements.
no-this-assignment - Disallows unnecessary references to this.

Requires Type Info
no-unbound-method - Warns when a method is used outside of a method call.
no-unnecessary-class - Disallows classes that are not strictly necessary.

Requires Type Info
no-unsafe-any - Warns when using an expression of type ‘any’ in a dynamic way. Uses are only allowed if they would work for {} | null | undefined. Type casts and tests are allowed. Expressions that work on all values (such as “” + x) are allowed.
no-unsafe-finally - Disallows control flow statements, such as return, continue, break and throws in finally blocks.
no-unused-expression - Disallows unused expression statements.

Requires Type Info
no-unused-variable - Disallows unused imports, variables, functions and private class members. Similar to tsc’s –noUnusedParameters and –noUnusedLocals options, but does not interrupt code compilation.
Requires Type Info
no-use-before-declare - Disallows usage of variables before their declaration.

no-var-keyword - Disallows usage of the var keyword.
Requires Type Info
no-void-expression - Requires expressions of type void to appear in statement position.
prefer-conditional-expression - Recommends to use a conditional expression instead of assigning to the same thing in each branch of an if statement.

prefer-object-spread - Enforces the use of the ES2018 object spread operator over Object.assign() where appropriate.
radix - Requires the radix parameter to be specified when calling parseInt.
Requires Type Info
restrict-plus-operands - When adding two variables, operands must both be of type number or of type string.

Requires Type Info
strict-boolean-expressions - Restricts the types allowed in boolean expressions. By default only booleans are allowed. The following nodes are checked:
Arguments to the !, &&, and || operators
The condition in a conditional expression (cond ? x : y)
Conditions for if, for, while, and do-while statements.

Requires Type Info
strict-type-predicates - Warns for type predicates that are always true or always false. Works for ‘typeof’ comparisons to constants (e.g. ‘typeof foo === “string”’), and equality comparison to ‘null’/’undefined’. (TypeScript won’t let you compare ‘1 === 2’, but it has an exception for ‘1 === undefined’.) Does not yet work for ‘instanceof’. Does not warn for ‘if (x.y)’ where ‘x.y’ is always truthy. For that, see strict-boolean-expressions. This rule requires strictNullChecks to work properly.
switch-default - Require a default case in all switch statements.
triple-equals - Requires === and !== in place of == and !=.
typeof-compare - Makes sure result of typeof is compared to correct string values
unnecessary-constructor - Prevents blank constructors, as they are redundant.

Requires Type Info
use-default-type-parameter - Warns if an explicitly specified type argument is the default for that type parameter.
use-isnan - Enforces use of the isNaN() function to check for NaN references instead of a comparison to the NaN constant.
Maintainability
These rules make code maintenance easier:

cyclomatic-complexity - Enforces a threshold of cyclomatic complexity.
Requires Type Info
deprecation - Warns when deprecated APIs are used.

eofline - Ensures the file ends with a newline.

indent - Enforces indentation with tabs or spaces.

linebreak-style - Enforces a consistent linebreak style.
max-classes-per-file - A file may not contain more than the specified number of classes
max-file-line-count - Requires files to remain under a certain number of lines
max-line-length - Requires lines to be under a certain max length.
no-default-export - Disallows default exports in ES6-style modules.
no-default-import - Disallows importing default members from certain ES6-style modules.
no-duplicate-imports - Disallows multiple import statements from the same module.

no-mergeable-namespace - Disallows mergeable namespaces in the same file.
no-require-imports - Disallows invocation of require().
object-literal-sort-keys - Checks ordering of keys in object literals. When using the default alphabetical ordering, additional blank lines may be used to group object properties together while keeping the elements within each group in alphabetical order.

prefer-const - Requires that variable declarations use const instead of let and var if possible.

Requires Type Info
prefer-readonly - Requires that private variables are marked as readonly if they’re never modified outside of the constructor.

trailing-comma - Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Style
These rules enforce consistent style across your codebase:

align - Enforces vertical alignment.

array-type - Requires using either ‘T[]’ or ‘Array’ for arrays.

arrow-parens - Requires parentheses around the parameters of arrow function definitions.

arrow-return-shorthand - Suggests to convert () => { return x; } to () => x.
binary-expression-operand-order - In a binary expression, a literal should always be on the right-hand side if possible. For example, prefer ‘x + 1’ over ‘1 + x’.

callable-types - An interface or literal type with just a call signature can be written as a function type.
class-name - Enforces PascalCased class and interface names.

comment-format - Enforces formatting rules for single-line comments.
comment-type - Allows a limited set of comment types
Requires Type Info
completed-docs - Enforces JSDoc comments for important items be filled out.
encoding - Enforces UTF-8 file encoding.

file-header - Enforces a certain header comment for all files, matched by a regular expression.
file-name-casing - Enforces a consistent file naming convention
import-spacing - Ensures proper spacing between import statement keywords
increment-decrement - Enforces using explicit += 1 or -= 1 operators.

interface-name - Requires interface names to begin with a capital ‘I’

interface-over-type-literal - Prefer an interface declaration over a type literal (type T = { … })
jsdoc-format - Enforces basic format rules for JSDoc comments.

Requires Type Info
match-default-export-name - Requires that a default import have the same name as the declaration it imports. Does nothing for anonymous default exports.
newline-before-return - Enforces blank line before return when not the only line in the block.
newline-per-chained-call - Requires that chained method calls be broken apart onto separate lines.
new-parens - Requires parentheses when invoking a constructor via the new keyword.

no-angle-bracket-type-assertion - Requires the use of as Type for type assertions instead of .

Requires Type Info
no-boolean-literal-compare - Warns on comparison to a boolean literal, as in x === true.

no-consecutive-blank-lines - Disallows one or more blank lines in a row.

no-irregular-whitespace - Disallow irregular whitespace within a file, including strings and comments.

no-parameter-properties - Disallows parameter properties in class constructors.

no-redundant-jsdoc - Forbids JSDoc which duplicates TypeScript functionality.

no-reference-import - Don’t if you import foo anyway.

no-trailing-whitespace - Disallows trailing whitespace at the end of a line.
no-unnecessary-callback-wrapper - Replaces x => f(x) with just f. To catch more cases, enable only-arrow-functions and arrow-return-shorthand too.

no-unnecessary-initializer - Forbids a ‘var’/’let’ statement or destructuring initializer to be initialized to ‘undefined’.

Requires Type Info
no-unnecessary-qualifier - Warns when a namespace qualifier (A.x) is unnecessary.
number-literal-format - Checks that decimal literals should begin with ‘0.’ instead of just ‘.’, and should not end with a trailing ‘0’.

object-literal-key-quotes - Enforces consistent object literal property quote style.

object-literal-shorthand - Enforces/disallows use of ES6 object literal shorthand.

one-line - Requires the specified tokens to be on the same line as the expression preceding them.
one-variable-per-declaration - Disallows multiple variable definitions in the same declaration statement.

ordered-imports - Requires that import statements be alphabetized and grouped.
prefer-function-over-method - Warns for class methods that do not use ‘this’.

prefer-method-signature - Prefer foo(): void over foo: () => void in interfaces and types.
prefer-switch - Prefer a switch statement to an if statement with simple === comparisons.
prefer-template - Prefer a template expression over string literal concatenation.

prefer-while - Prefer while loops instead of for loops without an initializer and incrementor.

quotemark - Enforces quote character for string literals.
Requires Type Info
return-undefined - Prefer return; in void functions and return undefined; in value-returning functions.

semicolon - Enforces consistent semicolon usage at the end of every statement.

space-before-function-paren - Require or disallow a space before function parenthesis

space-within-parens - Enforces spaces within parentheses or disallow them. Empty parentheses () are always allowed.

switch-final-break - Checks whether the final clause of a switch statement ends in break;.

type-literal-delimiter - Checks that type literal members are separated by semicolons. Enforces a trailing semicolon for multiline type literals.
Requires Type Info
unnecessary-bind - Prevents unnecessary and/or misleading scope bindings on functions.
variable-name - Checks variable names for various errors.

whitespace - Enforces whitespace style conventions.

TSLint 配置规则相关推荐

  1. webstrom TsLint配置

    tslint.json 文件解释 安装tslint package.json文件中添加如下配置后执行npm install "tslint": "~5.15.0" ...

  2. drools动态配置规则_关于规则引擎

    很早之前就知道Drools,这几天正好有个项目,里面用了大量的规则定义,就想是否能采用Drools来解决. 在github上分析了规则引擎项目,包括: Easy-rules https://githu ...

  3. Eslint 配置 + 规则说明 - 综合引入篇

    一. 配置: 参考引用文章:https://blog.csdn.net/hsl0530hsl/article/details/78594973 二.规则说明: 参考引用文章:https://blog. ...

  4. Sentinel配置规则持久化

    前言 在上一篇,我们讲解了基于springboot与Sentinel的整合与使用,但是有个很明显的问题就是,一旦服务重启,当前配置的针对某个接口的规则就丢掉了,然后就需要重新再配一遍,这就很坑爹了,如 ...

  5. linux防火墙规则命令意思,linux防火墙iptables配置规则分享

    类似的,对于HTTP/HTTPS(80/443).pop3(110).rsync(873).MySQL(3306)等基于tcp连接的服务,也可以参照上述命令配置. 对于基于udp的dns服务,使用以下 ...

  6. drools动态配置规则_微服务实战系列(八)-网关springcloud gateway自定义规则

    1. 场景描述 先说明下项目中使用的网关是:springcloud gateway, 因需要给各个网关服务系统提供自定义配置路由规则,实时生效,不用重启网关(重启风险大),目前已实现:动态加载自定义路 ...

  7. 解决阿里云redis监听6379,配置规则也将6379端口开放,但是外网仍无法连接6379的问题。

    问题描述: 阿里云linux安装完成redis,并且已经运行,检测6379端口,显示redis-server正在监听,如图 查看阿里云端口配置规则,6379端口对外开放 解决方法: 查看阿里云端口开放 ...

  8. drools规则引擎动态配置规则

    先说下我的业务需求背景,最近公司要推出运营活动,根据用户行为送用户积分:比如用户注册送.首次消费送,非首次消费送.累积消费送.针对我们这个的特殊要求是跟具体规则绑定:比如说 规则1 用户累积消费首次达 ...

  9. 安防RTSP无插件直播方案及RTSP配置规则

    LiveNVR搭建无插件直播方案时,采用行业标准的通用协议RTSP/Onvif接入摄像机IPC摄像机 / NVR硬盘录像机设备:Onvif是摄像机的发现与控制管理协议,Onvif用到的流媒体协议也是R ...

最新文章

  1. C++矩阵处理工具——Eigen
  2. 【正一专栏】欧冠四强猜想—不是冤家不聚首
  3. 都是套路:高并发系统的降级特技
  4. extjs 表单设置html5,ExtJS 配置和表格控件使用
  5. Linux系统删掉多个文件
  6. Java工作笔记-WebService使用JDK搭建WebService及调用
  7. C++中图的简单表示法
  8. 京东双十一大促网关承载十亿调用量背后的架构实践
  9. CSS三大特性(层叠/继承/优先)
  10. 178685-33-1,Azide-PEG3-Tos叠氮化物(N3)基团通过点击化学与炔烃、BCN、DBCO反应
  11. 《ANSYS 14.0超级学习手册》一1.1 有限元法概述
  12. 51nod 3199 操作栈
  13. 加拿大留学计算机专业好移民吗,加拿大最适合留学转移民的热门专业——计算机科学及信息技术...
  14. iOS开发-集成阿里云实人认证
  15. 奇瑞鲍思语将十万级无界Pro推出市场
  16. Java中类对象为空是什么意思?
  17. 新农慕课python项目答案_2020中国大学MOOC(慕课)Python编程基础题目及答案
  18. 解决echarts图表tooptip被挡住的问题
  19. Who Wants to Be a Millionaire?
  20. redux和mobx对比

热门文章

  1. tomcat关闭8009和8005端口
  2. 利用包含排斥原理求出给定范围内素数个数的问题
  3. [Error] expected declaration or statement at end of input
  4. 潮位调和分析工具学习(1)——T_tide
  5. 解决ESP32 驱动 28BYJ-48 步进电机反向不转之震动的问题
  6. 澳洲服务器拳头账号怎么注册,云顶之弈手游澳服账号怎么注册 澳洲服拳头账号注册方法分享...
  7. uboot usb设备驱动
  8. 关于计算机经历兼职的英文作文,求一篇兼职经历的英语作文
  9. 25k成功入职京东:拿到京东软件测试岗位offer经验分享
  10. 调戏木马病毒的正确姿势——下