Showing 143 of 143 total issues
Similar blocks of code found in 2 locations. Consider refactoring. Open
for (let i = 0, ii = preHooks.length; i < ii; ++i) {
preHooks[i].call(doc);
}
- 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 47.
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
Function _validateQueryResult
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
_validateQueryResult(result) {
if (result.errors > 0) {
return Promise.reject(new Errors.InvalidWrite('An error occured during the write', result));
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this function. Open
return this._convertGroupedData(result);
Avoid too many return
statements within this function. Open
return result;
Avoid too many return
statements within this function. Open
return query;
Avoid too many return
statements within this function. Open
return linkModel.insert(linkValue, {conflict: 'replace', returnChanges: 'always'})
.do(result => r.branch(
result('errors').eq(0),
true, // not relevant value
r.error(result('errors'))
Avoid too many return
statements within this function. Open
return false;
Avoid too many return
statements within this function. Open
return new Query(model, this, {},
new Errors.ThinkAgainError('The primary key or the joined key must be defined in the joined document for a `hasAndBelongsToMany` relation.')
);
Function deepCopy
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function deepCopy(value) {
let result;
if (value instanceof Buffer) {
// isPlainObject(buffer) returns true.
return new Buffer(value);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function loopKeys
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function loopKeys(obj, fn) {
if (isPlainObject(obj)) {
let keys = Object.keys(obj);
let result;
for (let i = 0, ii = keys.length; i < ii; ++i) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _syncValidate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
_syncValidate(options) {
let schemaOptions = this._getSchemaOptions();
if (util.isPlainObject(schemaOptions)) {
schemaOptions = util.mergeOptions(schemaOptions, options);
} else {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function docRemoveListener
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
docRemoveListener(ev, listener) {
if (Array.isArray(this._getModel()._listeners[ev])) {
for (let i = 0, ii = this._getModel()._listeners[ev].length; i < ii; ++i) {
if (this._getModel()._listeners[ev][i] === listener) {
this._getModel()._listeners[ev].splice(i, 1);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _eachCb
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
_eachCb(err, data) {
if (!!err) {
if ((this._closed !== false) || (err.message !== 'You cannot retrieve data from a cursor that is closed')) {
this._eventEmitter.emit('error', err);
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
TODO found Open
// TODO: Do not hardcode this?
- Exclude checks
TODO found Open
//TODO Remove once
- Exclude checks
TODO found Open
//TODO Expand error with more information
- Exclude checks
TODO found Open
//TODO Set a (string) id per document and use it to perform faster lookup
- Exclude checks
TODO found Open
// TODO: This regex seems a bit too generous since messages such
- Exclude checks
TODO found Open
//TODO: Should we warn the users? Throw an error?
- Exclude checks
TODO found Open
//TODO: We do not need to make a deep copy. We can do the same as for this._schemaOptions.
- Exclude checks