Avoid too many return
statements within this function. Open
return;
Similar blocks of code found in 2 locations. Consider refactoring. Open
function getDecoratorName(type: DecoratorType): string {
'use strict';
switch (type) {
case DecoratorType.Class:
return 'Class';
- 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 82.
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
function getDecoratorText(type: DecoratorType): string {
'use strict';
switch (type) {
case DecoratorType.Class:
return 'class decorator';
- 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 82.
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
The class property 'prop' must be marked either 'private', 'public', or 'protected' Open
prop: any;
- Read upRead up
- Exclude checks
Rule: member-access
Requires explicit visibility declarations for class members.
Rationale
Explicit visibility declarations can make code more readable and accessible for those new to TS.
Other languages such as C# default to private
, unlike TypeScript's default of public
.
Members lacking a visibility declaration may be an indication of an accidental leak of class internals.
Notes
- TypeScript Only
- Has Fix
Config
These arguments may be optionally provided:
-
"no-public"
forbids public accessibility to be specified, because this is the default. -
"check-accessor"
enforces explicit visibility on get/set accessors -
"check-constructor"
enforces explicit visibility on constructors -
"check-parameter-property"
enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"no-public",
"check-accessor",
"check-constructor",
"check-parameter-property"
]
},
"minLength": 0,
"maxLength": 4
}
For more information see this page.
Missing trailing comma Open
expected: [DecoratorType.Parameter]
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
expected variable-declaration: 'DecoratorTypes' to have a typedef Open
const DecoratorTypes = [
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.
expected call-signature: 'invokeDecorator' to have a typedef Open
function invokeDecorator(type: DecoratorType) {
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.
Missing trailing comma Open
expected: [DecoratorType.Property]
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
Use 'undefined' instead of 'null' Open
return null;
- Read upRead up
- Exclude checks
Rule: no-null-keyword
Disallows use of the null
keyword literal.
Rationale
Instead of having the dual concepts of null
andundefined
in a codebase,
this rule ensures that only undefined
is used.
JavaScript originally intended undefined
to refer to a value that doesn't yet exist,
while null
was meant to refer to a value that does exist but points to nothing.
That's confusing.
undefined
is the default value when object members don't exist, and is the return value
for newer native collection APIs such as Map.get
when collection values don't exist.
const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>
To remove confusion over the two similar values, it's better to stick with just undefined
.
Notes
- Has Fix
Config
Not configurable.
Examples
"no-null-keyword": true
For more information see this page.
Missing trailing comma Open
expected: [DecoratorType.Class]
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
The class property 'name' must be marked either 'private', 'public', or 'protected' Open
name: string;
- Read upRead up
- Exclude checks
Rule: member-access
Requires explicit visibility declarations for class members.
Rationale
Explicit visibility declarations can make code more readable and accessible for those new to TS.
Other languages such as C# default to private
, unlike TypeScript's default of public
.
Members lacking a visibility declaration may be an indication of an accidental leak of class internals.
Notes
- TypeScript Only
- Has Fix
Config
These arguments may be optionally provided:
-
"no-public"
forbids public accessibility to be specified, because this is the default. -
"check-accessor"
enforces explicit visibility on get/set accessors -
"check-constructor"
enforces explicit visibility on constructors -
"check-parameter-property"
enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"no-public",
"check-accessor",
"check-constructor",
"check-parameter-property"
]
},
"minLength": 0,
"maxLength": 4
}
For more information see this page.
The class property 'expected' must be marked either 'private', 'public', or 'protected' Open
expected: DecoratorType[];
- Read upRead up
- Exclude checks
Rule: member-access
Requires explicit visibility declarations for class members.
Rationale
Explicit visibility declarations can make code more readable and accessible for those new to TS.
Other languages such as C# default to private
, unlike TypeScript's default of public
.
Members lacking a visibility declaration may be an indication of an accidental leak of class internals.
Notes
- TypeScript Only
- Has Fix
Config
These arguments may be optionally provided:
-
"no-public"
forbids public accessibility to be specified, because this is the default. -
"check-accessor"
enforces explicit visibility on get/set accessors -
"check-constructor"
enforces explicit visibility on constructors -
"check-parameter-property"
enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"no-public",
"check-accessor",
"check-constructor",
"check-parameter-property"
]
},
"minLength": 0,
"maxLength": 4
}
For more information see this page.
Missing trailing comma Open
expected: [DecoratorType.Method]
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
expected arrow-parameter: 'type' to have a typedef Open
DecoratorTypes.forEach(type => {
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.
The key 'name' is not sorted alphabetically Open
name: 'isClassDecorator',
- Read upRead up
- Exclude checks
Rule: 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. To opt out of this use ignore-blank-lines option.
Rationale
Useful in preventing merge conflicts
Config
By default, this rule checks that keys are in alphabetical order. The following may optionally be passed:
-
ignore-blank-lines
will enforce alphabetical ordering regardless of blank lines between each key-value pair. -
ignore-case
will compare keys in a case insensitive way. -
locale-compare
will compare keys using the expected sort order of special characters, such as accents. -
match-declaration-order
will prefer to use the key ordering of the contextual type of the object literal, as in:interface I { foo: number; bar: number; } const obj: I = { foo: 1, bar: 2 };
If a contextual type is not found, alphabetical ordering will be used instead. * "match-declaration-order-only" exactly like "match-declaration-order", but don't fall back to alphabetical if a contextual type is not found.
Note: If both match-declaration-order-only and match-declaration-order options are present,
match-declaration-order-only will take precedence and alphabetical fallback will not occur.
-
shorthand-first
will enforce shorthand properties to appear first, as in:const obj = { a, c, b: true };
Examples
"object-literal-sort-keys": true
"object-literal-sort-keys": true,ignore-blank-lines,ignore-case,locale-compare,match-declaration-order,shorthand-first
Schema
{
"type": "string",
"enum": [
"ignore-blank-lines",
"ignore-case",
"locale-compare",
"match-declaration-order",
"match-declaration-order-only",
"shorthand-first"
]
}
For more information see this page.
The key 'name' is not sorted alphabetically Open
name: 'isMethodDecorator',
- Read upRead up
- Exclude checks
Rule: 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. To opt out of this use ignore-blank-lines option.
Rationale
Useful in preventing merge conflicts
Config
By default, this rule checks that keys are in alphabetical order. The following may optionally be passed:
-
ignore-blank-lines
will enforce alphabetical ordering regardless of blank lines between each key-value pair. -
ignore-case
will compare keys in a case insensitive way. -
locale-compare
will compare keys using the expected sort order of special characters, such as accents. -
match-declaration-order
will prefer to use the key ordering of the contextual type of the object literal, as in:interface I { foo: number; bar: number; } const obj: I = { foo: 1, bar: 2 };
If a contextual type is not found, alphabetical ordering will be used instead. * "match-declaration-order-only" exactly like "match-declaration-order", but don't fall back to alphabetical if a contextual type is not found.
Note: If both match-declaration-order-only and match-declaration-order options are present,
match-declaration-order-only will take precedence and alphabetical fallback will not occur.
-
shorthand-first
will enforce shorthand properties to appear first, as in:const obj = { a, c, b: true };
Examples
"object-literal-sort-keys": true
"object-literal-sort-keys": true,ignore-blank-lines,ignore-case,locale-compare,match-declaration-order,shorthand-first
Schema
{
"type": "string",
"enum": [
"ignore-blank-lines",
"ignore-case",
"locale-compare",
"match-declaration-order",
"match-declaration-order-only",
"shorthand-first"
]
}
For more information see this page.
The key 'name' is not sorted alphabetically Open
name: 'isParameterDecorator',
- Read upRead up
- Exclude checks
Rule: 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. To opt out of this use ignore-blank-lines option.
Rationale
Useful in preventing merge conflicts
Config
By default, this rule checks that keys are in alphabetical order. The following may optionally be passed:
-
ignore-blank-lines
will enforce alphabetical ordering regardless of blank lines between each key-value pair. -
ignore-case
will compare keys in a case insensitive way. -
locale-compare
will compare keys using the expected sort order of special characters, such as accents. -
match-declaration-order
will prefer to use the key ordering of the contextual type of the object literal, as in:interface I { foo: number; bar: number; } const obj: I = { foo: 1, bar: 2 };
If a contextual type is not found, alphabetical ordering will be used instead. * "match-declaration-order-only" exactly like "match-declaration-order", but don't fall back to alphabetical if a contextual type is not found.
Note: If both match-declaration-order-only and match-declaration-order options are present,
match-declaration-order-only will take precedence and alphabetical fallback will not occur.
-
shorthand-first
will enforce shorthand properties to appear first, as in:const obj = { a, c, b: true };
Examples
"object-literal-sort-keys": true
"object-literal-sort-keys": true,ignore-blank-lines,ignore-case,locale-compare,match-declaration-order,shorthand-first
Schema
{
"type": "string",
"enum": [
"ignore-blank-lines",
"ignore-case",
"locale-compare",
"match-declaration-order",
"match-declaration-order-only",
"shorthand-first"
]
}
For more information see this page.
variable name must be in lowerCamelCase or UPPER_CASE Open
const DecoratorTypes = [
- Read upRead up
- Exclude checks
Rule: variable-name
Checks variable names for various errors.
Config
Several arguments may be optionally provided:
-
"check-format"
enbables enforcement of a certain naming format. By default, the rule only allows only lowerCamelCased or UPPER_CASED variable names.- These additional options make the check stricter:
-
"require-const-for-all-caps"
: enforces that all variables with UPPER_CASED names should beconst
. - These additional options make the check more permissive:
-
"allow-leading-underscore"
allows underscores at the beginning (only has an effect if "check-format" specified) -
"allow-pascal-case"
allows PascalCase in addition to lowerCamelCase. -
"allow-snake-case"
allows snake_case in addition to lowerCamelCase. -
"allow-trailing-underscore"
allows underscores at the end. (only has an effect if "check-format" specified)
-
"ban-keywords"
: disallows the use of certain TypeScript keywords as variable or parameter names.- These are:
any
,Number
,number
,String
,string
,Boolean
,boolean
,Undefined
,undefined
- These are:
Examples
"variable-name": [object Object]
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"check-format",
"allow-leading-underscore",
"allow-pascal-case",
"allow-snake-case",
"allow-trailing-underscore",
"require-const-for-all-caps",
"ban-keywords"
]
},
"minLength": 0,
"maxLength": 6
}
For more information see this page.
Use 'undefined' instead of 'null' Open
return null;
- Read upRead up
- Exclude checks
Rule: no-null-keyword
Disallows use of the null
keyword literal.
Rationale
Instead of having the dual concepts of null
andundefined
in a codebase,
this rule ensures that only undefined
is used.
JavaScript originally intended undefined
to refer to a value that doesn't yet exist,
while null
was meant to refer to a value that does exist but points to nothing.
That's confusing.
undefined
is the default value when object members don't exist, and is the return value
for newer native collection APIs such as Map.get
when collection values don't exist.
const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>
To remove confusion over the two similar values, it's better to stick with just undefined
.
Notes
- Has Fix
Config
Not configurable.
Examples
"no-null-keyword": true
For more information see this page.
Use 'undefined' instead of 'null' Open
return null;
- Read upRead up
- Exclude checks
Rule: no-null-keyword
Disallows use of the null
keyword literal.
Rationale
Instead of having the dual concepts of null
andundefined
in a codebase,
this rule ensures that only undefined
is used.
JavaScript originally intended undefined
to refer to a value that doesn't yet exist,
while null
was meant to refer to a value that does exist but points to nothing.
That's confusing.
undefined
is the default value when object members don't exist, and is the return value
for newer native collection APIs such as Map.get
when collection values don't exist.
const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>
To remove confusion over the two similar values, it's better to stick with just undefined
.
Notes
- Has Fix
Config
Not configurable.
Examples
"no-null-keyword": true
For more information see this page.
Use 'undefined' instead of 'null' Open
beforeEach(() => injectedArguments = null);
- Read upRead up
- Exclude checks
Rule: no-null-keyword
Disallows use of the null
keyword literal.
Rationale
Instead of having the dual concepts of null
andundefined
in a codebase,
this rule ensures that only undefined
is used.
JavaScript originally intended undefined
to refer to a value that doesn't yet exist,
while null
was meant to refer to a value that does exist but points to nothing.
That's confusing.
undefined
is the default value when object members don't exist, and is the return value
for newer native collection APIs such as Map.get
when collection values don't exist.
const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>
To remove confusion over the two similar values, it's better to stick with just undefined
.
Notes
- Has Fix
Config
Not configurable.
Examples
"no-null-keyword": true
For more information see this page.
Missing trailing comma Open
DecoratorType.None
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
expected variable-declaration: 'expected' to have a typedef Open
let expected = config.expected.indexOf(type) !== -1;
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.
Use 'undefined' instead of 'null' Open
return null;
- Read upRead up
- Exclude checks
Rule: no-null-keyword
Disallows use of the null
keyword literal.
Rationale
Instead of having the dual concepts of null
andundefined
in a codebase,
this rule ensures that only undefined
is used.
JavaScript originally intended undefined
to refer to a value that doesn't yet exist,
while null
was meant to refer to a value that does exist but points to nothing.
That's confusing.
undefined
is the default value when object members don't exist, and is the return value
for newer native collection APIs such as Map.get
when collection values don't exist.
const myObject = {};
myObject.doesNotExist; // undefined
const myMap = new Map<string number>();
myMap.get("doesNotExist"); // undefined</string>
To remove confusion over the two similar values, it's better to stick with just undefined
.
Notes
- Has Fix
Config
Not configurable.
Examples
"no-null-keyword": true
For more information see this page.
The key 'name' is not sorted alphabetically Open
name: 'isPropertyDecorator',
- Read upRead up
- Exclude checks
Rule: 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. To opt out of this use ignore-blank-lines option.
Rationale
Useful in preventing merge conflicts
Config
By default, this rule checks that keys are in alphabetical order. The following may optionally be passed:
-
ignore-blank-lines
will enforce alphabetical ordering regardless of blank lines between each key-value pair. -
ignore-case
will compare keys in a case insensitive way. -
locale-compare
will compare keys using the expected sort order of special characters, such as accents. -
match-declaration-order
will prefer to use the key ordering of the contextual type of the object literal, as in:interface I { foo: number; bar: number; } const obj: I = { foo: 1, bar: 2 };
If a contextual type is not found, alphabetical ordering will be used instead. * "match-declaration-order-only" exactly like "match-declaration-order", but don't fall back to alphabetical if a contextual type is not found.
Note: If both match-declaration-order-only and match-declaration-order options are present,
match-declaration-order-only will take precedence and alphabetical fallback will not occur.
-
shorthand-first
will enforce shorthand properties to appear first, as in:const obj = { a, c, b: true };
Examples
"object-literal-sort-keys": true
"object-literal-sort-keys": true,ignore-blank-lines,ignore-case,locale-compare,match-declaration-order,shorthand-first
Schema
{
"type": "string",
"enum": [
"ignore-blank-lines",
"ignore-case",
"locale-compare",
"match-declaration-order",
"match-declaration-order-only",
"shorthand-first"
]
}
For more information see this page.
expected arrow-parameter: 'type' to have a typedef Open
DecoratorTypes.forEach(type => {
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.
The class method 'method' must be marked either 'private', 'public', or 'protected' Open
method(param: any) {
- Read upRead up
- Exclude checks
Rule: member-access
Requires explicit visibility declarations for class members.
Rationale
Explicit visibility declarations can make code more readable and accessible for those new to TS.
Other languages such as C# default to private
, unlike TypeScript's default of public
.
Members lacking a visibility declaration may be an indication of an accidental leak of class internals.
Notes
- TypeScript Only
- Has Fix
Config
These arguments may be optionally provided:
-
"no-public"
forbids public accessibility to be specified, because this is the default. -
"check-accessor"
enforces explicit visibility on get/set accessors -
"check-constructor"
enforces explicit visibility on constructors -
"check-parameter-property"
enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"no-public",
"check-accessor",
"check-constructor",
"check-parameter-property"
]
},
"minLength": 0,
"maxLength": 4
}
For more information see this page.
The class property 'target' must be marked either 'private', 'public', or 'protected' Open
target: Function;
- Read upRead up
- Exclude checks
Rule: member-access
Requires explicit visibility declarations for class members.
Rationale
Explicit visibility declarations can make code more readable and accessible for those new to TS.
Other languages such as C# default to private
, unlike TypeScript's default of public
.
Members lacking a visibility declaration may be an indication of an accidental leak of class internals.
Notes
- TypeScript Only
- Has Fix
Config
These arguments may be optionally provided:
-
"no-public"
forbids public accessibility to be specified, because this is the default. -
"check-accessor"
enforces explicit visibility on get/set accessors -
"check-constructor"
enforces explicit visibility on constructors -
"check-parameter-property"
enforces explicit visibility on parameter properties
Examples
"member-access": true
"member-access": true,no-public
"member-access": true,check-accessor
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"no-public",
"check-accessor",
"check-constructor",
"check-parameter-property"
]
},
"minLength": 0,
"maxLength": 4
}
For more information see this page.
Missing trailing comma Open
isPropertyDecorator
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
Missing trailing comma Open
}
- Read upRead up
- Exclude checks
Rule: trailing-comma
Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings, named imports and exports and function parameters.
Notes
- Has Fix
Config
One argument which is an object with the keys multiline
and singleline
.
Both can be set to a string ("always"
or "never"
) or an object.
The object can contain any of the following keys: "arrays"
, "objects"
, "functions"
,
"imports"
, "exports"
, and "typeLiterals"
; each key can have one of the following
values: "always"
, "never"
, and "ignore"
. Any missing keys will default to "ignore"
.
-
"multiline"
checks multi-line object literals. -
"singleline"
checks single-line object literals.
An array is considered "multiline" if its closing bracket is on a line after the last array element. The same general logic is followed for object literals, function typings, named import statements and function parameters.
To align this rule with the ECMAScript specification that is implemented in modern JavaScript VMs,
there is a third option esSpecCompliant
. Set this option to true
to disallow trailing comma on
object and array rest and rest parameters.
Examples
"trailing-comma": true,[object Object]
"trailing-comma": true,[object Object]
Schema
{
"type": "object",
"properties": {
"multiline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"singleline": {
"anyOf": [
{
"type": "string",
"enum": [
"always",
"never"
]
},
{
"type": "object",
"properties": {
"arrays": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"exports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"functions": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"imports": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"objects": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
},
"typeLiterals": {
"type": "string",
"enum": [
"always",
"never",
"ignore"
]
}
}
}
]
},
"esSpecCompliant": {
"type": "boolean"
}
},
"additionalProperties": false
}
For more information see this page.
expected call-signature: 'method' to have a typedef Open
method(param: any) {
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.
expected arrow-parameter: 'config' to have a typedef Open
testSuitConfig.forEach(config => {
- Read upRead up
- Exclude checks
Rule: typedef
Requires type definitions to exist.
Notes
- TypeScript Only
Config
Several arguments may be optionally provided:
-
"call-signature"
checks return type of functions. -
"arrow-call-signature"
checks return type of arrow functions. -
"parameter"
checks type specifier of function parameters for non-arrow functions. -
"arrow-parameter"
checks type specifier of function parameters for arrow functions. -
"property-declaration"
checks return types of interface properties. -
"variable-declaration"
checks non-binding variable declarations. -
"variable-declaration-ignore-function"
ignore variable declarations for non-arrow and arrow functions. -
"member-variable-declaration"
checks member variable declarations. -
"object-destructuring"
checks object destructuring declarations. -
"array-destructuring"
checks array destructuring declarations.
Examples
"typedef": true,call-signature,parameter,member-variable-declaration
Schema
{
"type": "array",
"items": {
"type": "string",
"enum": [
"call-signature",
"arrow-call-signature",
"parameter",
"arrow-parameter",
"property-declaration",
"variable-declaration",
"variable-declaration-ignore-function",
"member-variable-declaration",
"object-destructuring",
"array-destructuring"
]
},
"minLength": 0,
"maxLength": 10
}
For more information see this page.