tslint-digacon v0.0.4
TSLint rules
trailing-comma - Disallow trailing commas. Even though trailing commas in object literals are valid according to the ECMAScript 5.
INCORRECT
const foo = { bar: 'baz', qux: 'quux', }; const arr = [1,2,]; bar({ bar: 'baz', qux: 'quux', });
CORRECT
const foo = { bar: 'baz', qux: 'quux' }; const arr = [1,2]; bar({ bar: 'baz', qux: 'quux' });
no-conditional-assignment - Disallow assignment in conditional expressions.
INCORRECT
// Check the user's job title if (user.jobTitle = 'manager') { // user.jobTitle is now incorrect }
CORRECT
// Assignment replaced by comparison let x; if (x === 0) { let b = 1; }
no-console - Disallow use of console. INCORRECT
console.log('Some logging stuff')
no-constant-condition - Disallow use of constant expressions in conditions.
INCORRECT
if (false) { doSomethingUnfinished(); }
CORRECT
if (x === 0) { doSomething(); }
no-control-regex - Disallow use of control characters in regular expressions. Control characters are special, invisible characters in the ASCII range 0-31. These characters are rarely used in JavaScript strings so a regular expression containing these characters is most likely a mistake.
**INCORRECT** ```typescript const pattern1 = /\x1f/; const pattern2 = new RegExp('\x1f'); ``` **CORRECT** ```typescript const pattern1 = /\x20/; const pattern2 = new RegExp('\x20'); ```
no-debugger - Disallow use of debugger (recommended).
INCORRECT
function isTruthy(x) { debugger; return Boolean(x); }
no-duplicate-case - Disallow duplicate text expressions in case clauses
INCORRECT
switch (a) { case 1: break; case 2: break; case 1: // duplicate key break; default: break; }
CORRECT
switch (a) { case 1: break; case 2: break; case 3: break; default: break; }
no-empty - Disallow empty statements. Empty block statements, while not technically errors, usually occur due to refactoring that wasn’t completed. They can cause confusion when reading code.
**INCORRECT** ```typescript if (foo) { } ``` **CORRECT** ```typescript if (foo) { someFunction(); } ```
no-empty-character-class - Disallow the use of empty character classes in regular expressions. Because empty character classes in regular expressions do not match anything, they might be typing mistakes.
**INCORRECT** ```typescript /^abc[]/.test('abcdefg'); // false 'abcdefg'.match(/^abc[]/); // null ``` **CORRECT** ```typescript /^abc/.test('abcdefg'); // true 'abcdefg'.match(/^abc/); // ['abc'] ```
no-ex-assign - Disallow assigning to the exception in a catch block. If a catch clause in a try statement accidentally (or purposely) assigns another value to the exception parameter, it impossible to refer to the error from that point on.
**INCORRECT** ```typescript try { // code } catch (e) { e = 10; } ``` **CORRECT** ```typescript try { // code } catch (e) { const foo = 10; } ```
- no-extra-boolean-cast - This rule disallows unnecessary boolean casts.
In contexts such as an if statement’s test where the result of the expression
will already be coerced to a Boolean, casting to a Boolean via
double negation (!!) or a Boolean call is unnecessary.
**INCORRECT** ```typescript let foo = !!!bar; let foo = !!bar ? baz : bat; let foo = Boolean(!!bar); let foo = new Boolean(!!bar); ``` **CORRECT** ```typescript let foo = !!bar; let foo = Boolean(bar); function foo() { return !!bar; } let foo = bar ? !!baz : !!bat; ```
no-extra-semi - This rule disallows unnecessary semicolons. Typing mistakes and misunderstandings about where semicolons are required can lead to semicolons that are unnecessary. While not technically an error, extra semicolons can cause confusion when reading code.
**INCORRECT** ```typescript let x = 5;; ``` **CORRECT** ```typescript let x = 5; ```
no-inner-declarations - Disallow function declarations in nested blocks.
INCORRECT
if (test) { function doSomething() { } } function doSomethingElse() { if (test) { function doAnotherThing() { } } } if (test) { var foo = 42; } function doAnotherThing() { if (test) { var bar = 81; } }
CORRECT
function doSomething() { } function doSomethingElse() { function doAnotherThing() { } } if (test) { asyncCall(id, function (err, data) { }); } var fn; if (test) { fn = function fnExpression() { }; } var bar = 42; if (test) { let baz = 43; } function doAnotherThing() { var baz = 81; }
no-invalid-regexp - Disallow invalid regular expression strings in the RegExp constructor.
**INCORRECT** ```typescript RegExp('[') RegExp('.', 'z') new RegExp('\\') ``` **CORRECT** ```typescript RegExp('.') ```
- ter-no-irregular-whitespace - Disallow irregular whitespace.
Invalid or irregular whitespace causes issues with ECMAScript 5 parsers and also makes code harder to debug in
a similar nature to mixed tabs and spaces.
**INCORRECT** ```typescript function thing() /*<NBSP>*/{ return 'test'; } function thing( /*<NBSP>*/){ return 'test'; } function thing /*<NBSP>*/(){ return 'test'; } function thing/*<MVS>*/(){ return 'test'; } function thing() { return 'test'; /*<ENSP>*/ } ... ``` **CORRECT** ```typescript function thing() { return ' <NBSP>thing'; } function thing() { return '<ZWSP>thing'; } function thing() { return 'th <NBSP>ing'; } ```
- no-regex-spaces - Disallow multiple spaces in a
regular expression literal. Regular expressions can be very complex
and difficult to understand, which is why it’s important to keep them
as simple as possible in order to avoid mistakes.
**INCORRECT** ```typescript const re = /foo bar/; const re = new RegExp('foo bar'); //should throw error but it doesn't ``` **CORRECT** ```typescript const re = /foo {3}bar/; const re = new RegExp('foo {3}bar'); ```
- ter-no-sparse-arrays - This rule disallows sparse
array literals which have “holes” where commas are not preceded by elements.
It does not apply to a trailing comma following the last element. Invalid
or irregular whitespace causes issues with ECMAScript 5 parsers and also
makes code harder to debug in a similar nature to mixed tabs and spaces.
**INCORRECT** ```typescript const items = [,]; const colors = [ 'red',, 'blue' ]; ``` **CORRECT** ```typescript const items = []; const items = new Array(23); // trailing comma (after the last element) is not a problem const colors = [ 'red', 'blue', ]; ```
no-unexpected-multiline - This rule disallows confusing multiline expressions where a newline looks like it is ending a statement, but is not. INCORRECT
```typescript let foo = bar (1 || 2).baz(); let hello = 'world' [1, 2, 3].forEach(addNumber); ``` **CORRECT** ```typescript let foo = bar; (1 || 2).baz(); let foo = bar ;(1 || 2).baz() ```
no-unsafe-finally - JavaScript suspends the control flow statements of try and catch blocks until the execution of finally block finishes. So, when return, throw, break, or continue is used in finally, control flow statements inside try and catch are overwritten, which is considered as unexpected behavior. This rule disallows return, throw, break, and continue statements inside finally blocks. It allows indirect usages, such as in function or class definitions.
**INCORRECT** ```typescript let foo = function() { try { return 1; } catch(err) { return 2; } finally { return 3; } }; ``` **CORRECT** ```typescript let foo = function() { try { return 1; } catch(err) { return 2; } finally { console.log('hola!'); } }; ```
- use-isnan - This rule disallows comparisons to ‘NaN’.
Because NaN is unique in JavaScript by not being equal to anything,
including itself, the results of comparisons to NaN are confusing:
NaN === NaN or NaN == NaN evaluate to false NaN !== NaN or NaN != NaN evaluate to true
**INCORRECT** ```typescript if (foo == NaN) { // ... } if (foo != NaN) { // ... } ``` **CORRECT** ```typescript if (isNaN(foo)) { // ... } if (!isNaN(foo)) { // ... } ```
valid-jsdoc - Enforce valid JSDoc comments. JSDoc generates application programming interface (API) documentation from specially-formatted comments in JavaScript code. So does typedoc. If comments are invalid because of typing mistakes, then documentation will be incomplete. If comments are inconsistent because they are not updated when function definitions are modified, then readers might become confused.
valid-typeof - Ensure that the results of typeof are compared against a valid string. For a vast majority of use cases, the result of the typeof operator is one of the following string literals: "undefined", "object", "boolean", "number", "string", "function" and "symbol". It is usually a typing mistake to compare the result of a typeof operator to other string literals.
INCORRECT
typeof foo === "strnig" typeof foo == "undefimed" typeof bar != "nunber" typeof bar !== "function"
CORRECT
typeof foo === "string" typeof bar == "undefined" typeof foo === baz typeof bar === typeof qux
cyclomatic-complexity - This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).
**INCORRECT** ```typescript typeof foo === "strnig" typeof foo == "undefimed" typeof bar != "nunber" typeof bar !== "function" ``` **CORRECT** ```typescript typeof foo === "string" typeof bar == "undefined" typeof foo === baz typeof bar === typeof qux ```
curly - JavaScript allows the omission of curly braces when a block contains only one statement. However, it is considered by many to be best practice to never omit curly braces around blocks, even when they are optional, because it can lead to bugs and reduces code clarity.
**INCORRECT** ```typescript if (foo) foo++; while (bar) baz(); if (foo) { baz(); } else qux(); ``` **CORRECT** ```typescript if (foo) { foo++; } while (bar) { baz(); } if (foo) { baz(); } else { qux(); } ```
switch-default - Require a default case in all switch statements.
INCORRECT
switch (a) { case 1: /* code */ break; }
CORRECT
switch (a) { case 1: /* code */ break; default: /* code */ break; }
triple-equals - Requires === and !== in place of == and !=. It is considered good practice to use the type-safe equality operators === and !== instead of their regular counterparts == and !=. The reason for this is that == and != do type coercion which follows the rather obscure Abstract Equality Comparison Algorithm.
**INCORRECT** ```typescript a == b foo == true bananas != 1 value == undefined typeof foo == 'undefined' 'hello' != 'world' 0 == 0 true == true foo == null ``` **CORRECT** ```typescript a === b foo === true bananas !== 1 value === undefined typeof foo === 'undefined' 'hello' !== 'world' 0 === 0 true === true foo === null ```
forin - Prevents accidental iteration over properties inherited from an object’s prototype.
**INCORRECT** ```typescript for (key in foo) { doSomething(key); } ``` **CORRECT** ```typescript for (let key in someObject) { if (someObject.hasOwnProperty(key)) { // code here } } if (Object.prototype.hasOwnProperty.call(foo, key)) { doSomething(key); } if ({}.hasOwnProperty.call(foo, key)) { doSomething(key); } ```
ban - disallow the use of alert,eval, confirm, and prompt.
no-arg - Disallows use of
arguments.callee
. Usingarguments.callee
makes various performance optimizations impossible. It has been deprecated in future versions of JavaScript and their use is forbidden in ECMAScript 5 while in strict mode.no-eval - Disallows eval function invocations.
eval()
is dangerous as it allows arbitrary code execution with full privileges.no-switch-case-fall-through - Disallows falling through case statements. Fall though in switch statements is often unintentional and a bug.
**INCORRECT** ```typescript switch(foo) { case 1: doSomething(); case 2: doSomething(); } ``` **CORRECT** ```typescript switch(foo) { case 1: doSomething(); break; case 2: doSomething(); } function bar(foo) { switch(foo) { case 1: doSomething(); return; case 2: doSomething(); } } ```
label-position - Disallow Labeled Statements. While convenient in some cases, labels tend to be used only rarely and are frowned upon by some as a remedial form of flow control that is more error prone and harder to understand. This rule only allows labels to be on do/for/while/switch statements.
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. Magic numbers should be avoided as they often lack documentation, forcing them to be stored in variables gives them implicit documentation.
**INCORRECT** ```typescript const dutyFreePrice = 100; const finalPrice = dutyFreePrice + (dutyFreePrice * 0.25); const data = ['foo', 'bar', 'baz']; const dataLast = data[2]; let SECONDS; SECONDS = 60; ``` **CORRECT** ```typescript const TAX = 0.25; const dutyFreePrice = 100; const finalPrice = dutyFreePrice + (dutyFreePrice * TAX); ```
no-multi-spaces - Disallow use of multiple spaces. Multiple spaces in a row that are not used for indentation are typically mistakes.
**INCORRECT** ```typescript var a = 1; if(foo === "bar") {} a << b var arr = [1, 2]; a ? b: c ``` **CORRECT** ```typescript var a = 1; if(foo === "bar") {} a << b var arr = [1, 2]; a ? b: c ```
no-construct - Disallows access to the constructors of String, Number, and Boolean. Disallows constructor use such as new Number(foo) but does not disallow Number(foo). There is little reason to use String, Number, or Boolean as constructors. In almost all cases, the regular function-call version is more appropriate.
**INCORRECT** ```typescript var stringObject = new String("Hello world"); var numberObject = new Number(33); var booleanObject = new Boolean(false); var stringObject = new String; var numberObject = new Number; var booleanObject = new Boolean; ``` **CORRECT** ```typescript var text = String(someValue); var num = Number(someValue); var object = new MyString(); ```
no-duplicate-variable - In JavaScript, it’s possible to redeclare the same variable name using var. This can lead to confusion as to where the variable is actually declared and initialized.
**INCORRECT** ```typescript var a = 3; var a = 10; ``` **CORRECT** ```typescript var a = 3; // ... a = 10; ```
no-string-throw - Flags throwing plain strings or concatenations of strings because only Errors produce proper stack traces.
**INCORRECT** ```typescript throw "an " + err; throw "error"; ``` **CORRECT** ```typescript throw new Error(); throw new Error("error"); ```
radix - Requires the radix parameter to be specified when calling parseInt. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.
**INCORRECT** ```typescript var num = parseInt("071"); var num = parseInt(someValue); var num = parseInt("071", "abc"); var num = parseInt(); ``` **CORRECT** ```typescript var num = parseInt("071", 10); var num = parseInt("071", 8); var num = parseFloat(someValue); ```
no-shadowed-variable - Disallows shadowing variable declarations. Shadowing a variable masks access to it and obscures to what value an identifier actually refers.
**INCORRECT** ```typescript var a = 3; function b() { var a = 10; } var b = function () { var a = 10; } function b(a) { a = 10; } b(a); if (true) { let a = 5; } ``` **CORRECT** ```typescript function a (){ var b; } function c(b) { var a = 10; } ```
handle-callback-err - Enforce error handling in callbacks. In Node.js, a common pattern for dealing with asynchronous behavior is called the callback pattern. This pattern expects an Error object or null as the first argument of the callback. Forgetting to handle these errors can lead to some really strange behavior in your application.
**INCORRECT** ```typescript function loadData (err, data) { doSomething(); } function loadData (err, data) { doSomething(); } ``` **CORRECT** ```typescript function loadData (err, data) { if (err) { console.log(err.stack); } doSomething(); } function generateError (err) { if (err) {} } ```
- array-bracket-spacing - enforce consistent spacing inside array brackets.
A number of style guides require or disallow spaces between array brackets and
other tokens. This rule applies to both array literals and destructuring
assignments (ECMAScript 6).
**INCORRECT** ```typescript const arr = [ 'foo', 'bar' ]; const arr = ['foo', 'bar' ]; const arr = [ ['foo'], 'bar']; const arr = [[ 'foo' ], 'bar']; ``` **CORRECT** ```typescript const arr = []; const arr = ['foo', 'bar', 'baz']; const arr = [['foo'], 'bar', 'baz']; ```
block-spacing - This rule enforces consistent spacing inside an open block token and the next token on the same line. This rule also enforces consistent spacing inside a close block token and previous token on the same line.
**INCORRECT** ```typescript function foo() {return true;} if (foo) { bar = 0;} function baz() {let i = 0; return i; } ``` **CORRECT** ```typescript function foo() { return true; } if (foo) { bar = 0; } ```
brace-style - Brace style is closely related to indent style in programming and describes the placement of braces relative to their control statement and body. There are probably a dozen, if not more, brace styles in the world. The one true brace style is one of the most common brace styles in JavaScript, in which the opening brace of a block is placed on the same line as its corresponding statement or declaration.
**INCORRECT** ```typescript function foo() { return true; } if (foo) { bar(); } try { somethingRisky(); } catch(e) { handleError(); } if (foo) { bar(); } else { baz(); } ``` **CORRECT** ```typescript function foo() { return true; } if (foo) { bar(); } if (foo) { bar(); } else { baz(); } try { somethingRisky(); } catch(e) { handleError(); } // when there are no braces, there are no problems if (foo) bar(); else if (baz) boom(); ```
- variable-name - Checks variable names for various errors.
Require Camelcase.
**INCORRECT** ```typescript import { no_camelcased } from "external-module" const my_favorite_color = "#112C85"; function do_something() { // ... } ``` **CORRECT** ```typescript import { no_camelcased as camelCased } from "external-module"; var myFavoriteColor = "#112C85"; ```
eofline - Ensures the file ends with a newline. Fix for single-line files is not supported.
ter-func-call-spacing - disallow spacing between function identifiers and their invocations.
**INCORRECT** ```typescript fn (); fn (); ``` **CORRECT** ```typescript fn(); ```
ter-indent - 4 spaces indentation.
linebreak-style - Enforces a consistent linebreak style. Requires LF (\n) linebreaks.
ter-max-len - enforce a maximum line length. 120 chars.
max-file-line-count - Requires files to remain under a certain number of lines. Limiting the number of lines allowed in a file allows files to remain small, single purpose, and maintainable. We disabled it because React JSX files tend to be large.
new-parens - Require parentheses when invoking a constructor with no arguments.
**INCORRECT** ```typescript var person = new Person; var person = new (Person); ``` **CORRECT** ```typescript var person = new Person(); var person = new (Person)(); ```
no-bitwise - Disallows bitwise operators. Specifically, the following bitwise operators are banned: &, &=, |, |=, ^, ^=, <<, <<=, >>, >>=, >>>, >>>=, and ~. This rule does not ban the use of
&
and|
for intersection and union types. Bitwise operators are often typos - for example bool1 & bool2 instead of bool1 && bool2. They also can be an indicator of overly clever code which decreases maintainability.indent -Enforces indentation with spaces(4). Using only one of tabs or spaces for indentation leads to more consistent editor behavior, cleaner diffs in version control, and easier programmatic manipulation.
no-consecutive-blank-lines - Disallows more than 2 blank lines in a row.
no-trailing-whitespace - Disallows trailing whitespace at the end of a line. Keeps version control diffs clean as it prevents accidental whitespace from being committed.
object-curly-spacing - Require padding inside curly braces.
INCORRECT
var obj = {'foo': 'bar'}; var obj = {'foo': 'bar' }; var obj = { baz: {'foo': 'qux'}, bar}; var obj = {baz: { 'foo': 'qux' }, bar}; var obj = {'foo': 'bar' }; var obj = { 'foo':'bar'}; var {x} = y; import {foo } from 'bar';
CORRECT
var obj = {}; var obj = { 'foo': 'bar' }; var obj = { 'foo': { 'bar': 'baz' }, 'qux': 'quxx' }; var obj = { 'foo': 'bar' }; var { x } = y; import { foo } from 'bar';
object-literal-key-quotes - Enforces consistent object literal property quote style. Only property names which require quotes may be quoted (e.g. those with spaces in them).
**INCORRECT** ```typescript var object = { "a": 0, "0": 0, "true": 0, "null": 0 }; ``` **CORRECT** ```typescript var object1 = { "a-b": 0, "0x0": 0, "1e2": 0 }; var object2 = { foo: 'bar', baz: 42, true: 0, 0: 0, 'qux-lorem': true }; var object3 = { foo() { return; } }; ```
quotemark - Enforce the consistent use of either backticks, double, or single quotes.
**INCORRECT** ```typescript const foo = "Hello World"; const backtick = `backtick`; ``` **CORRECT** ```typescript const foo = 'Hello World'; const backtick = `backtick${bar}`; const unescaped = "a string containing 'single' quotes"; const foo = "Hello 'World'"; ```
semicolon - Enforces consistent semicolon usage at the end of every statement.
**INCORRECT** ```typescript const foo = "Hello World" ``` **CORRECT** ```typescript const foo = "Hello World"; ```
space-in-parens - This rule will enforce consistency of spacing directly inside of parentheses, by disallowing or requiring one or more spaces to the right of (and to the left of). In either case, () will still be allowed. enforces zero spaces inside of parentheses.
**INCORRECT** ```typescript foo( 'bar'); foo('bar' ); foo( 'bar' ); var foo = ( 1 + 2 ) * 3; ( function () { return 'bar'; }() ); ``` **CORRECT** ```typescript foo(); foo('bar'); var foo = (1 + 2) * 3; (function () { return 'bar'; }()); ```
comment-format - Enforces formatting rules for single-line comments. Helps maintain a consistent, readable style in your codebase. Requires that all single-line comments must begin with a space, as in // comment note that for comments starting with multiple slashes, e.g. ///, leading slashes are ignored. TypeScript reference comments are ignored completely. Requires that the first non-whitespace character of a comment must be uppercase, if applicable.
ter-arrow-body-style - Arrow functions have two syntactic forms for their function bodies. They may be defined with a block body (denoted by curly braces)
() => { ... }
or with a single expression() => ...
, whose value is implicitly returned. Enforces no braces where they can be omitted.**INCORRECT** ```typescript let foo = () => { return 0; }; ``` **CORRECT** ```typescript let foo = () => 0; let foo = (retv, name) => { retv[name] = true; return retv; }; let foo = () => ({ bar: { foo: 1, bar: 2, } }); let foo = () => { bar(); }; let foo = () => {}; let foo = () => { /* do nothing */ }; let foo = () => { // do nothing. }; let foo = () => ({ bar: 0 }); ```
ter-arrow-parens - Require parens in arrow function arguments. Requires parentheses around arguments in all cases.
**INCORRECT** ```typescript a => {}; a => a; a => {'\n'}; a.then(foo => {}); a.then(foo => a); a(foo => { if (true) {} }); ``` **CORRECT** ```typescript () => {}; (a) => {}; (a) => a; (a) => {'\n'} a.then((foo) => {}); a.then((foo) => { if (true) {} }); ```
ter-arrow-spacing - Require space before/after arrow function's arrow.
INCORRECT
()=> {}; () =>{}; (a)=> {}; (a) =>{}; a =>a; a=> a; ()=> {'\n'}; () =>{'\n'};
CORRECT
() => {}; (a) => {}; a => a; () => {'\n'};
no-var-keyword - Disallows usage of the var keyword. Use let or const instead.
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’.
adjacent-overload-signatures - Enforces function overloads to be consecutive. Improves readability and organization by grouping naturally related items together.
no-empty-interface - Forbids empty interfaces. An empty interface is equivalent to its supertype (or {}).
no-internal-module - Disallows internal module.Using module leads to a confusion of concepts with external modules. Use the newer namespace keyword instead.
no-parameter-reassignment - Disallows reassigning parameters. INCORRECT
function f4(foo: number, {bar}: {bar: number}, baz: string) { foo += 1; foo++; --foo; foo += foo; ({foo} = {foo: 1}); for (bar of arr) {} for (baz in obj) {} }
CORRECT
function f4(foo: number, {bar}: {bar: number}, baz: string) { const a = foo + 1; const a = foo -1; const a = foo; }
no-reference - no-reference Disallows ///<reference path=> imports (use ES6-style imports instead). Using /// <reference path=> comments to load other files is outdated. Use ES6-style imports to reference other files.
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. A for(… of …) loop is easier to implement and read when the index is not needed.
no-duplicate-super - Warns if ‘super()’ appears twice in a constructor. The second call to ‘super()’ will fail at runtime.
prefer-object-spread - Enforces the use of the ES2015 object spread operator over Object.assign() where appropriate. Object spread allows for better type checking and inference.
no-duplicate-imports - Disallows multiple import statements from the same module. Using a single import statement per module will make the code clearer because you can see everything being imported from that module on one line.
class-name - Enforces PascalCased class and interface names. Makes it easy to differentiate classes from regular variables at a glance.
interface-name - Requires interface names to begin with a capital ‘I’, Makes it easy to differentiate interfaces from regular classes at a glance.
interface-over-type-literal - Prefer an interface declaration over a type literal (type T = { ... }). Interfaces are generally preferred over type literals because interfaces can be implemented, extended and merged.
no-unnecessary-initializer - Forbids a ‘var’/’let’ statement or destructuring initializer to be initialized to ‘undefined’.
**INCORRECT** ```typescript let a: string | undefined = undefined; for (let c: number | undefined = undefined; c < 2; c++) {} ``` **CORRECT** ```typescript let d; const e = undefined; ```
number-literal-format - Checks that decimal literals should begin with ‘0.’ instead of just ‘.’, and should not end with a trailing ‘0’.
**INCORRECT** ```typescript 01; 1. 0.50; .5; 1e01; ``` **CORRECT** ```typescript 0; 0.5; 10; 1.1e10; ```
one-variable-per-declaration - Disallows multiple variable definitions in the same declaration statement.
**INCORRECT** ```typescript var foo9, foo10; var foo11: number, foo12: number; ``` **CORRECT** ```typescript const foo7: number = 1; const foo8 = 1; ```
ordered-imports - Requires that import statements be alphabetized and grouped.
prefer-template -Prefer a template expression over string literal concatenation.
**INCORRECT** ```typescript "foo" + x; x + "bar"; ``` **CORRECT** ```typescript `foo bar ${y} baz` ```
space-before-function-paren - Disallow space before function parenthesis. Allow only in anonymous.
space-within-parens - Disallow spaces within parentheses.
jsx-alignment - Enforces a consistent style for multiline JSX elements which promotes ease of editing via line-wise manipulations as well as maintainabilty via small diffs when changes are made.
**INCORRECT** ```typescript <Button appearance="pretty" disabled label="Click Me" size={size} /> ``` **CORRECT** ```typescript <Button appearance="pretty" disabled label="Click Me" size={size} /> ```
jsx-boolean-value - When using a boolean attribute in JSX, you can set the attribute value to true or omit the value. We omit the value.
**INCORRECT** ```typescript <Foo readOnly={true} /> ``` **CORRECT** ```typescript <Foo readOnly /> ```
jsx-curly-spacing - Bans spaces between curly brace characters in JSX.
INCORRECT
const failA = <App foo={ bar } />;
CORRECT
const passA = <App foo={bar} />;
jsx-equals-spacing - Bans spaces before and after the = token in JSX element attributes.
**INCORRECT** ```typescript <App foo = {bar} /> ``` **CORRECT** ```typescript <App foo="bar" /> ```
jsx-key - Warns for missing key props in JSX element array literals and inside return statements of Array.prototype.map callbacks.
jsx-no-bind - Forbids function binding in JSX attributes.
jsx-no-lambda - Forbids lambdas in JSX attributes.
jsx-no-string-ref - Passing strings to the ref prop of React elements is considered a legacy feature and will soon be deprecated. Instead, use a callback.
jsx-self-close - Enforces that JSX elements with no children are self-closing.
INCORRECT
<App></App>
CORRECT
<App />
jsx-wrap-multiline - Enforces that multiline JSX expressions are wrapped with parentheses. Opening parenthesis must be followed by a newline. Closing parenthesis must be preceded by a newline.
**INCORRECT** ```typescript const button = <button type="submit"> Submit </button>; ``` **CORRECT** ```typescript const button = ( <button type="submit"> Submit </button> ); ```
jsx-no-multiline-js - Allows multiline JS expressions inside JSX blocks.