In the code above, the author almost certainly meant for both foo++ and bar++
to be executed only if foo === bar. However, they forgot braces and bar++ will be executed
no matter what. This rule could prevent such a mistake.
Notes
Has Fix
Config
One of the following options may be provided:
"as-needed" forbids any unnecessary curly braces.
"ignore-same-line" skips checking braces for control-flow statements
that are on one line and start on the same line as their control-flow keyword
In the code above, the author almost certainly meant for both foo++ and bar++
to be executed only if foo === bar. However, they forgot braces and bar++ will be executed
no matter what. This rule could prevent such a mistake.
Notes
Has Fix
Config
One of the following options may be provided:
"as-needed" forbids any unnecessary curly braces.
"ignore-same-line" skips checking braces for control-flow statements
that are on one line and start on the same line as their control-flow keyword
A consistent ordering for class members can make classes easier to read, navigate, and edit.
A common opposite practice to member-ordering is to keep related groups of classes together.
Instead of creating classes with multiple separate groups, consider splitting class responsibilities
apart across multiple single-responsibility classes.
Notes
Has Fix
Config
One argument, which is an object, must be provided. It should contain an order property.
The order property should have a value of one of the following strings:
fields-first
instance-sandwich
statics-first
fields-first puts, in order of precedence:
* fields before constructors before methods
* static members before instance members
* public members before protected members before private members
instance-sandwich puts, in order of precedence:
* fields before constructors before methods
* static fields before instance fields, but static methods after instance methods
* public members before protected members before private members
statics-first puts, in order of precedence:
* static members before instance members
* public members before protected members before private members
* fields before methods
* instance fields before constructors before instance methods
* fields before constructors before methods
* public members before protected members before private members
Note that these presets, despite looking similar, can have subtly different behavior due to the order in which these
rules are specified. A fully expanded ordering can be found in the PRESETS constant in
https://github.com/palantir/tslint/blob/master/src/rules/memberOrderingRule.ts.
(You may need to check the version of the file corresponding to your version of tslint.)
Alternatively, the value for order may be an array consisting of the following strings:
public-static-field
protected-static-field
private-static-field
public-static-method
private-static-method
protected-static-method
public-instance-field
protected-instance-field
private-instance-field
public-constructor
protected-constructor
private-constructor
public-instance-method
protected-instance-method
private-instance-method
public-static-accessor
protected-static-accessor
private-static-accessor
public-instance-accessor
protected-instance-accessor
private-instance-accessor
You can also omit the access modifier to refer to "public-", "protected-", and "private-" all at once; for example, "static-field".
You can also make your own categories by using an object instead of a string:
{
"name": "static non-private",
"kinds": [
"public-static-field",
"protected-static-field",
"public-static-method",
"protected-static-method"
]
}
The 'alphabetize' option will enforce that members within the same category should be alphabetically sorted by name.
Computed property names are sorted before others but not sorted amongst each other.
Additionally getters will be sorted before setters (after alphabetization).
In the code above, the author almost certainly meant for both foo++ and bar++
to be executed only if foo === bar. However, they forgot braces and bar++ will be executed
no matter what. This rule could prevent such a mistake.
Notes
Has Fix
Config
One of the following options may be provided:
"as-needed" forbids any unnecessary curly braces.
"ignore-same-line" skips checking braces for control-flow statements
that are on one line and start on the same line as their control-flow keyword
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
In the code above, the author almost certainly meant for both foo++ and bar++
to be executed only if foo === bar. However, they forgot braces and bar++ will be executed
no matter what. This rule could prevent such a mistake.
Notes
Has Fix
Config
One of the following options may be provided:
"as-needed" forbids any unnecessary curly braces.
"ignore-same-line" skips checking braces for control-flow statements
that are on one line and start on the same line as their control-flow keyword
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
"jsx-single" enforces single quotes for JSX attributes.
"jsx-double" enforces double quotes for JSX attributes.
"avoid-template" forbids single-line untagged template strings that do not contain string interpolations.
Note that backticks may still be used if "avoid-escape" is enabled and both single and double quotes are
present in the string (the latter option takes precedence).
"avoid-escape" allows you to use the "other" quotemark in cases where escaping would normally be required.
For example, [true, "double", "avoid-escape"] would not report a failure on the string literal
'Hello "World"'.
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".
Enforces consistent semicolon usage at the end of every statement.
Notes
Has Fix
Config
One of the following arguments must be provided:
"always" enforces semicolons at the end of every statement.
"never" disallows semicolons at the end of every statement except for when they are necessary.
The following arguments may be optionally provided:
"ignore-interfaces" skips checking semicolons at the end of interface members.
"ignore-bound-class-methods" skips checking semicolons at the end of bound class methods.
"strict-bound-class-methods" disables any special handling of bound class methods and treats them as any
other assignment. This option overrides "ignore-bound-class-methods".