Avoid deeply nested control flow statements. Open
} else if (splits.length === 2 && splits[0].length > 0 && splits[1].length === 0) {
// intermittent range search, something like `250-` inbetween entering valid states
a = b = Number.parseInt(splits[0]);
} else if (splits.length === 3 && splits[0].length === 0 && splits[2].length === 0) {
// intermittent range search, something like `-250-` inbetween entering valid states
Avoid deeply nested control flow statements. Open
if (a > b) {
const c = b;
b = a;
a = c;
}
Avoid deeply nested control flow statements. Open
if (a <= numberValue && numberValue <= b) {
includeElement = true;
}
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (state.currentOrder.length > 0) {
if (query.length > 0) {
query += '&';
}
query += 'order=';
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 109.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (state.currentColumns.length > 0) {
if (query.length > 0) {
query += '&';
}
query += 'columns=';
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 109.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (state.rowIndexes.length !== indexes.length) {
state.currentChanged = true;
} else {
for (let i = 0; i < indexes.length; i++) {
state.currentChanged = state.currentChanged || indexes[i] === state.rowIndexes[i];
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 100.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (state.currentElements.length !== dataElements.length) {
state.currentChanged = true;
} else {
for (let i = 0; i < dataElements.length; i++) {
state.currentChanged = state.currentChanged || dataElements[i] === state.currentElements[i];
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 100.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else if (splits.length === 3 && splits[1].length === 0) {
// range search with second number negative
a = -1 * Number.parseInt(splits[2]);
b = Number.parseInt(splits[0]);
} else if (splits.length === 4 && splits[0].length === 0 && splits[2].length === 0) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 50.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} else if (splits.length === 3 && splits[0].length === 0 && splits[2].length > 0) {
// range search with first number negative
a = -1 * Number.parseInt(splits[1]);
b = Number.parseInt(splits[2]);
} else if (splits.length === 3 && splits[1].length === 0) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 50.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Missing radix parameter Open
a = b = -1 * Number.parseInt(splits[1]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
a = b = Number.parseInt(splits[0]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
b = Number.parseInt(splits[2]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Shadowed name: 'elements' Open
const elements = state.currentSearch.get(key);
- Read upRead up
- Exclude checks
Rule: no-shadowed-variable
Disallows shadowing variable declarations.
Rationale
When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs. Shadowing makes it impossible to access the variable in the containing scope and obscures to what value an identifier actually refers. Compare the following snippets:
const a = 'no shadow';
function print() {
console.log(a);
}
print(); // logs 'no shadow'.
const a = 'no shadow';
function print() {
const a = 'shadow'; // TSLint will complain here.
console.log(a);
}
print(); // logs 'shadow'.
ESLint has an equivalent rule. For more background information, refer to this MDN closure doc.
Config
You can optionally pass an object to disable checking for certain kinds of declarations.
Possible keys are "class"
, "enum"
, "function"
, "import"
, "interface"
, "namespace"
, "typeAlias"
and "typeParameter"
. You can also pass "underscore
" to ignore variable names that begin with _
.
Just set the value to false
for the check you want to disable.
All checks default to true
, i.e. are enabled by default.
Note that you cannot disable variables and parameters.
The option "temporalDeadZone"
defaults to true
which shows errors when shadowing block scoped declarations in their
temporal dead zone. When set to false
parameters, classes, enums and variables declared
with let
or const
are not considered shadowed if the shadowing occurs within their
temporal dead zone.
The following example shows how the "temporalDeadZone"
option changes the linting result:
function fn(value) {
if (value) {
const tmp = value; // no error on this line if "temporalDeadZone" is false
return tmp;
}
let tmp = undefined;
if (!value) {
const tmp = value; // this line always contains an error
return tmp;
}
}
Examples
"no-shadowed-variable": true
"no-shadowed-variable": true,[object Object]
Schema
{
"type": "object",
"properties": {
"class": {
"type": "boolean"
},
"enum": {
"type": "boolean"
},
"function": {
"type": "boolean"
},
"import": {
"type": "boolean"
},
"interface": {
"type": "boolean"
},
"namespace": {
"type": "boolean"
},
"typeAlias": {
"type": "boolean"
},
"typeParameter": {
"type": "boolean"
},
"temporalDeadZone": {
"type": "boolean"
},
"underscore": {
"type": "boolean"
}
}
}
For more information see this page.
Shadowed name: 'dataElement' Open
const dataElement: DataElement = data[i];
- Read upRead up
- Exclude checks
Rule: no-shadowed-variable
Disallows shadowing variable declarations.
Rationale
When a variable in a local scope and a variable in the containing scope have the same name, shadowing occurs. Shadowing makes it impossible to access the variable in the containing scope and obscures to what value an identifier actually refers. Compare the following snippets:
const a = 'no shadow';
function print() {
console.log(a);
}
print(); // logs 'no shadow'.
const a = 'no shadow';
function print() {
const a = 'shadow'; // TSLint will complain here.
console.log(a);
}
print(); // logs 'shadow'.
ESLint has an equivalent rule. For more background information, refer to this MDN closure doc.
Config
You can optionally pass an object to disable checking for certain kinds of declarations.
Possible keys are "class"
, "enum"
, "function"
, "import"
, "interface"
, "namespace"
, "typeAlias"
and "typeParameter"
. You can also pass "underscore
" to ignore variable names that begin with _
.
Just set the value to false
for the check you want to disable.
All checks default to true
, i.e. are enabled by default.
Note that you cannot disable variables and parameters.
The option "temporalDeadZone"
defaults to true
which shows errors when shadowing block scoped declarations in their
temporal dead zone. When set to false
parameters, classes, enums and variables declared
with let
or const
are not considered shadowed if the shadowing occurs within their
temporal dead zone.
The following example shows how the "temporalDeadZone"
option changes the linting result:
function fn(value) {
if (value) {
const tmp = value; // no error on this line if "temporalDeadZone" is false
return tmp;
}
let tmp = undefined;
if (!value) {
const tmp = value; // this line always contains an error
return tmp;
}
}
Examples
"no-shadowed-variable": true
"no-shadowed-variable": true,[object Object]
Schema
{
"type": "object",
"properties": {
"class": {
"type": "boolean"
},
"enum": {
"type": "boolean"
},
"function": {
"type": "boolean"
},
"import": {
"type": "boolean"
},
"interface": {
"type": "boolean"
},
"namespace": {
"type": "boolean"
},
"typeAlias": {
"type": "boolean"
},
"typeParameter": {
"type": "boolean"
},
"temporalDeadZone": {
"type": "boolean"
},
"underscore": {
"type": "boolean"
}
}
}
For more information see this page.
Missing radix parameter Open
a = Number.parseInt(splits[0]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
b = -1 * Number.parseInt(splits[1]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
.map(x => Number.parseInt(x.trim()));
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
a = b = -1 * Number.parseInt(splits[1]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
b = Number.parseInt(splits[1]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
misplaced 'else' Open
else {
- Read upRead up
- Exclude checks
Rule: one-line
Requires the specified tokens to be on the same line as the expression preceding them.
Notes
- Has Fix
Config
Five arguments may be optionally provided:
-
"check-catch"
checks thatcatch
is on the same line as the closing brace fortry
. -
"check-finally"
checks thatfinally
is on the same line as the closing brace forcatch
. -
"check-else"
checks thatelse
is on the same line as the closing brace forif
. -
"check-open-brace"
checks that an open brace falls on the same line as its preceding expression. -
"check-whitespace"
checks preceding whitespace for the specified tokens.
Examples
"one-line": true,check-catch,check-finally,check-else
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"check-catch",
"check-finally",
"check-else",
"check-open-brace",
"check-whitespace"
]
},
"minLength": 0,
"maxLength": 5
}
For more information see this page.
Missing radix parameter Open
a = -1 * Number.parseInt(splits[1]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
a = -1 * Number.parseInt(splits[2]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
const numberValue = Number.parseInt(label.name);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
a = b = Number.parseInt(splits[0]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
b = Number.parseInt(splits[0]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.
Missing radix parameter Open
a = -1 * Number.parseInt(splits[0]);
- Read upRead up
- Exclude checks
Rule: radix
Requires the radix parameter to be specified when calling parseInt
.
Rationale
From MDN:
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.
Config
Not configurable.
Examples
"radix": true
For more information see this page.