Skip to content

Latest commit

 

History

History
162 lines (152 loc) · 13.7 KB

File metadata and controls

162 lines (152 loc) · 13.7 KB

下面的规则查找与TypeScript功能相关的错误

  • adjacent-overload-signatures - Enforces function overloads to be consecutive.
  • 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).
  • 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.
  • 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.

下面的规则检查JS中常见的错误,或者容易产生错误的结构

  • 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.
  • import-blacklist - Disallows importing the specified modules directly via import and require. Instead only sub modules may be imported from that module.
  • 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.
  • no-floating-promises - Promises returned by functions must be handled appropriately.
  • 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
  • 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 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.
  • no-unbound-method - Warns when a method is used outside of a method call.
  • no-unnecessary-class - Disallows classes that are not strictly necessary.
  • 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.
  • 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.
  • no-use-before-declare - Disallows usage of variables before their declaration.
  • no-var-keyword - Disallows usage of the var keyword.
  • 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 ES2015 object spread operator over Object.assign() where appropriate.
  • radix - Requires the radix parameter to be specified when calling parseInt.
  • restrict-plus-operands - When adding two variables, operands must both be of type number or of type string.
  • 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.
  • 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
  • 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.

以下规则使代码维护更容易

  • cyclomatic-complexity - Enforces a threshold of cyclomatic complexity.
  • 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-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.
  • 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.

以下规则强制执行一致的样式

  • 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.
  • 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
  • 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.
  • 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 .
  • 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’.
  • 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 - Requires single or double quotes for string literals.
  • 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.
  • variable-name - Checks variable names for various errors.
  • whitespace - Enforces whitespace style conventions.