Similar blocks of code found in 2 locations. Consider refactoring. Open
public connect (): Promise<void> {
return new Promise((resolve, reject) => {
this.client.connect((err: Error) => {
if (err) {
return reject(err);
- Read upRead up
- Create a ticketCreate a ticket
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 83.
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
public disconnect (): Promise<void> {
return new Promise((resolve, reject) => {
this.client.end((err: Error) => {
if (err) {
return reject(err);
- Read upRead up
- Create a ticketCreate a ticket
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 83.
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
Documentation must exist for properties. Open
prefixes: string[];
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Rule: completed-docs
Enforces JSDoc comments for important items be filled out.
Rationale
Helps ensure important components are documented.
Note: use this rule sparingly. It's better to have self-documenting names on components with single, concise responsibilities. Comments that only restate the names of variables add nothing to code, and can easily become outdated.
Config
true
to enable for [classes, functions, methods, properties]
,
or an array with each item in one of two formats:
-
string
to enable for that type -
object
keying types to when their documentation is required:-
"methods"
and"properties"
may specify:-
"privacies"
:"all"
"private"
"protected"
"public"
-
"locations"
:"all"
"instance"
"static"
-
- Other types may specify
"visibilities"
:"all"
"exported"
"internal"
-
"functions"
"methods"
may also specify"overloads"
to indicate that each overload should have its own documentation, which isfalse
by default. - All types may also provide
"tags"
with members specifying tags that allow the docs to not have a body.-
"content"
: Object mapping tags toRegExp
bodies content allowed to count as complete docs. -
"existence"
: Array of tags that must only exist to count as complete docs.
-
-
Types that may be enabled are:
"classes"
"constructors"
"enums"
"enum-members"
"functions"
"interfaces"
"methods"
"namespaces"
"properties"
"types"
"variables"
Examples
"completed-docs": true
"completed-docs": true,enums,functions,methods
"completed-docs": true,[object Object]
Schema
{
"type": "array",
"items": {
"anyOf": [
{
"options": [
"classes",
"enums",
"functions",
"interfaces",
"methods",
"namespaces",
"properties",
"types",
"variables"
],
"type": "string"
},
{
"type": "object",
"properties": {
"classes": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"constructors": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"enums": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"enum-members": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"functions": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"interfaces": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"methods": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"locations": {
"enum": [
"all",
"instance",
"static"
],
"type": "string"
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"namespaces": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"properties": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"locations": {
"enum": [
"all",
"instance",
"static"
],
"type": "string"
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
}
},
"type": "object"
},
"types": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"variables": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
}
}
}
]
}
}
For more information see this page.
Documentation must exist for properties. Open
id: string;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Rule: completed-docs
Enforces JSDoc comments for important items be filled out.
Rationale
Helps ensure important components are documented.
Note: use this rule sparingly. It's better to have self-documenting names on components with single, concise responsibilities. Comments that only restate the names of variables add nothing to code, and can easily become outdated.
Config
true
to enable for [classes, functions, methods, properties]
,
or an array with each item in one of two formats:
-
string
to enable for that type -
object
keying types to when their documentation is required:-
"methods"
and"properties"
may specify:-
"privacies"
:"all"
"private"
"protected"
"public"
-
"locations"
:"all"
"instance"
"static"
-
- Other types may specify
"visibilities"
:"all"
"exported"
"internal"
-
"functions"
"methods"
may also specify"overloads"
to indicate that each overload should have its own documentation, which isfalse
by default. - All types may also provide
"tags"
with members specifying tags that allow the docs to not have a body.-
"content"
: Object mapping tags toRegExp
bodies content allowed to count as complete docs. -
"existence"
: Array of tags that must only exist to count as complete docs.
-
-
Types that may be enabled are:
"classes"
"constructors"
"enums"
"enum-members"
"functions"
"interfaces"
"methods"
"namespaces"
"properties"
"types"
"variables"
Examples
"completed-docs": true
"completed-docs": true,enums,functions,methods
"completed-docs": true,[object Object]
Schema
{
"type": "array",
"items": {
"anyOf": [
{
"options": [
"classes",
"enums",
"functions",
"interfaces",
"methods",
"namespaces",
"properties",
"types",
"variables"
],
"type": "string"
},
{
"type": "object",
"properties": {
"classes": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"constructors": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"enums": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"enum-members": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"functions": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"interfaces": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"methods": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"locations": {
"enum": [
"all",
"instance",
"static"
],
"type": "string"
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"namespaces": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"properties": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"locations": {
"enum": [
"all",
"instance",
"static"
],
"type": "string"
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
}
},
"type": "object"
},
"types": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"variables": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
}
}
}
]
}
}
For more information see this page.
Documentation must exist for properties. Open
name: string;
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Rule: completed-docs
Enforces JSDoc comments for important items be filled out.
Rationale
Helps ensure important components are documented.
Note: use this rule sparingly. It's better to have self-documenting names on components with single, concise responsibilities. Comments that only restate the names of variables add nothing to code, and can easily become outdated.
Config
true
to enable for [classes, functions, methods, properties]
,
or an array with each item in one of two formats:
-
string
to enable for that type -
object
keying types to when their documentation is required:-
"methods"
and"properties"
may specify:-
"privacies"
:"all"
"private"
"protected"
"public"
-
"locations"
:"all"
"instance"
"static"
-
- Other types may specify
"visibilities"
:"all"
"exported"
"internal"
-
"functions"
"methods"
may also specify"overloads"
to indicate that each overload should have its own documentation, which isfalse
by default. - All types may also provide
"tags"
with members specifying tags that allow the docs to not have a body.-
"content"
: Object mapping tags toRegExp
bodies content allowed to count as complete docs. -
"existence"
: Array of tags that must only exist to count as complete docs.
-
-
Types that may be enabled are:
"classes"
"constructors"
"enums"
"enum-members"
"functions"
"interfaces"
"methods"
"namespaces"
"properties"
"types"
"variables"
Examples
"completed-docs": true
"completed-docs": true,enums,functions,methods
"completed-docs": true,[object Object]
Schema
{
"type": "array",
"items": {
"anyOf": [
{
"options": [
"classes",
"enums",
"functions",
"interfaces",
"methods",
"namespaces",
"properties",
"types",
"variables"
],
"type": "string"
},
{
"type": "object",
"properties": {
"classes": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"constructors": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"enums": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"enum-members": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"functions": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"interfaces": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"methods": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"locations": {
"enum": [
"all",
"instance",
"static"
],
"type": "string"
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
},
"overloads": {
"type": "boolean"
}
},
"type": "object"
},
"namespaces": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"properties": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"locations": {
"enum": [
"all",
"instance",
"static"
],
"type": "string"
},
"privacies": {
"enum": [
"all",
"private",
"protected",
"public"
],
"type": "string"
}
},
"type": "object"
},
"types": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
},
"variables": {
"properties": {
"tags": {
"properties": {
"content": {
"items": {
"type": "string"
},
"type": "object"
},
"existence": {
"items": {
"type": "string"
},
"type": "array"
}
}
},
"visibilities": {
"enum": [
"all",
"exported",
"internal"
],
"type": "string"
}
},
"type": "object"
}
}
}
]
}
}
For more information see this page.