- References
- Objects
- Strings
- Possible Errors
- Best Practices
- Variables
- Stylistic
- ECMAScript 6
- Codelyzer
-
Use
const
instead oflet
andvar
if a variable is only assigned to once when it is declared."prefer-const": true
-
Use
let
instead ofvar
if a variable is reassigned."no-var-keyword": true
-
Use property and method shorthand syntax for object literals
"object-literal-shorthand": true
-
Enforces consistent object literal property quote style
"object-literal-key-quotes": [true, "consistent-as-needed"]
- Use single quotes for string literals.
"quotemark": [true, "single", "avoid-escape"]
- Never use
eval
on string becauseeval
is dangerous as it allows arbitrary code execution with full privileges."no-eval": true
These rules relate to possible syntax or logic errors in JavaScript code
Recommended | Rule | Description |
---|---|---|
✓ | no-conditional-assignment | Disallows any type of assignment in conditionals. |
✓ | no-console | Bans the use of specified console methods. |
✓ | no-debugger | Disallows debugger statements. |
✓ | use-isnan | Enforces use of the isNaN() function to check for NaN references instead of a comparison to the NaN constant. |
✓ | no-unsafe-finally | Disallows control flow statements, such as return , continue , break and throws in finally blocks. |
✓ | trailing-comma | Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters. |
These rules relate to better ways of doing things to help you avoid problems
Recommended | Rule | Description |
---|---|---|
ban | Bans the use of specific functions (alert , confirm , prompt ) or global methods. |
|
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 . |
|
✓ | curly | Enforces braces for if /for /do /while statements. |
✓ | cyclomatic-complexity | Enforces a threshold of cyclomatic complexity. |
✓ | forin | Requires a for ... in statement to be filtered with an if statement. |
✓ | label-position | Only allows labels in sensible locations.This rule only allows labels to be on do /for /while /switch statements. |
✓ | no-arg | Disallows use of arguments.callee . |
✓ | no-construct | Disallows access to the constructors of String , Number , and Boolean . |
✓ | no-duplicate-variable | Disallows duplicate variable declarations in the same block scope. |
✓ | no-empty | Disallows empty blocks. Blocks with a comment inside are not considered empty. |
✓ | no-eval | Disallows eval function invocations. |
✓ | no-invalid-this | Disallows using the this keyword outside of classes. |
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-string-throw | Flags throwing plain strings or concatenations of strings. |
✓ | no-switch-case-fall-through | Disallows falling through case statements. |
✓ | no-unused-expression | Disallows unused expression statements. |
✓ | radix | Requires the radix parameter to be specified when calling parseInt |
switch-default | Require a default case in all switch statements. |
|
✓ | triple-equals | Requires === and !== in place of == and != . |
These rules relate to variable declarations
Recommended | Rule | Description |
---|---|---|
✓ | no-shadowed-variable | Disallows shadowing variable declarations. |
no-unused-variable | Disallows unused imports, variables, functions and private class members. | |
✓ | no-use-before-declare | Disallows usage of variables before their declaration. |
These rules relate to style guidelines, and are therefore quite subjective
Recommended | Rule | Description |
---|---|---|
✓ | 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. |
✓ | 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. |
✓ | eofline | Ensures the file ends with a newline. |
✓ | import-blacklist | Disallows importing the specified modules directly via import and require. Instead only sub modules may be imported from that module. |
✓ | import-spacing | Ensures proper spacing between import statement keywords |
✓ | indent | Enforces indentation with tabs or spaces. |
✓ | interface-over-type-literal | Prefer an interface declaration over a type literal (type T = { ... } ). |
✓ | 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. |
✓ | member-access | Requires explicit visibility declarations for class members. |
✓ | member-ordering | Enforces member ordering. |
✓ | new-parens | Requires parentheses when invoking a constructor via the new keyword. |
✓ | newline-before-return | Enforces blank line before return when not the only line in the block. |
✓ | no-bitwise | Disallows bitwise operators. |
✓ | no-consecutive-blank-lines | Disallows one or more blank lines in a row. |
no-default-export | Disallows default exports in ES6-style modules.Use named exports instead. | |
no-duplicate-imports | Disallows multiple import statements from the same module. | |
no-dynamic-delete | Bans usage of the delete operator with computed key expressions. | |
✓ | no-empty-interface | Forbids empty interfaces. |
✓ | no-reference | Disallows /// <reference path=> imports (use ES6-style imports instead). |
✓ | 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-trailing-whitespace | Disallows trailing whitespace at the end of a line. |
✓ | no-unnecessary-initializer | Forbids a var /let statement or destructuring initializer to be initialized to undefined . |
✓ | object-literal-key-quotes | Enforces consistent object literal property quote style. |
✓ | object-literal-sort-keys | Checks ordering of keys in object literals. |
✓ | one-line | Requires the specified tokens to be on the same line as the expression preceding them. |
✓ | ordered-imports | Requires that import statements be alphabetized and grouped. |
✓ | no-inferrable-types | Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean. |
✓ | no-misused-new | Warns on apparent attempts to define constructors for interfaces or new for classes. |
✓ | no-non-null-assertion | Disallows non-null assertions using the ! postfix operator. |
✓ | no-return-await | Disallows unnecessary return await . |
✓ | one-variable-per-declaration | Disallows multiple variable definitions in the same declaration statement. |
✓ | quotemark | Requires single or double quotes for string literals. |
✓ | semicolon | Enforces consistent semicolon usage at the end of every statement. |
✓ | space-before-function-paren | Require or disallow a space before function parenthesis. |
✓ | 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. |
✓ | variable-name | Checks variable names for various errors. |
✓ | whitespace | Enforces whitespace style conventions. |
These rules relate to ES6, also known as ES2015
Recommended | Rule | Description |
---|---|---|
✓ | arrow-return-shorthand | Suggests to convert () => { return x; } to () => x . |
✓ | no-duplicate-super | Warns if super() appears twice in a constructor. |
no-require-imports | Disallows invocation of require() . |
|
✓ | no-var-keyword | Disallows usage of the var keyword. Use let or const instead. |
✓ | no-var-requires | Disallows the use of require statements except in import statements. |
✓ | object-literal-shorthand | Enforces/disallows use of ES6 object literal shorthand. |
✓ | prefer-const | Requires that variable declarations use const instead of let and var if possible. If a variable is only assigned to once when it is declared, it should be declared using const . |
prefer-object-spread | Enforces the use of the ES2015 object spread operator over Object.assign() where appropriate. |
Lint rules encode logic for syntactic & semantic checks of TypeScript, HTML, CSS and Angular expressions source code.
These rules catch common errors in JS programming or otherwise confusing constructs that are prone to producing bugs:
Recommended | Rule | Description |
---|---|---|
banana-in-box | Ensure that the two-way data binding syntax is correct. |
These rules make code maintenance easier:
Recommended | Rule | Description |
---|---|---|
no-attribute-parameter-decorator | Disallow usage of @Attribute decorator. | |
no-forward-ref | Disallows usage of forward references for DI. | |
no-input-rename | Disallows renaming directive inputs by providing a string to the decorator. | |
no-output-on-prefix | Name events without the prefix on. | |
no-output-rename | Disallows renaming directive outputs by providing a string to the decorator. | |
use-life-cycle-interface | Ensure that components implement life cycle interfaces if they use them. | |
use-pipe-transform-interface | Ensure that pipes implement PipeTransform interface. |
These rules enforce consistent style across your codebase:
Recommended | Rule | Description |
---|---|---|
angular-whitespace | Ensures the proper formatting of Angular expressions. | |
component-class-suffix | Classes decorated with @Component must have suffix “Component” (or custom) in their name. | |
component-selector | Component selectors should follow given naming rules. | |
directive-class-suffix | Classes decorated with @Directive must have suffix “Directive” (or custom) in their name. | |
directive-selector | Directive selectors should follow given naming rules. | |
use-host-property-decorator | Use @HostProperty decorator rather than the host property of @Component and @Directive metadata. |
|
use-input-property-decorator | Use @Input decorator rather than the inputs property of @Component and @Directive metadata. |
|
use-output-property-decorator | Use @Output decorator rather than the outputs property of @Component and @Directive metadata. |
This project is licensed under the MIT License