原文: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 ///
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.