mbroadst/thinkagain

View on GitHub

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);
  }
Severity: Minor
Found in lib/util.js and 1 other location - About 35 mins to fix
lib/util.js on lines 129..131

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

Further Reading

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));
    }

Severity: Minor
Found in lib/query.js - About 35 mins to fix

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);
Severity: Major
Found in lib/query.js - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

            return result;
    Severity: Major
    Found in lib/query.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

            return query;
      Severity: Major
      Found in lib/query.js - About 30 mins to fix

        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'))
        Severity: Major
        Found in lib/query.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return false;
          Severity: Major
          Found in lib/types/keywords.js - About 30 mins to fix

            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.')
                      );
            Severity: Major
            Found in lib/query.js - About 30 mins to fix

              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);
              Severity: Minor
              Found in lib/util.js - About 25 mins to fix

              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) {
              Severity: Minor
              Found in lib/util.js - About 25 mins to fix

              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 {
              Severity: Minor
              Found in lib/document.js - About 25 mins to fix

              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);
              Severity: Minor
              Found in lib/model.js - About 25 mins to fix

              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);
                    }
              Severity: Minor
              Found in lib/feed.js - About 25 mins to fix

              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?
              Severity: Minor
              Found in lib/query.js by fixme

              TODO found
              Open

                  //TODO Remove once
              Severity: Minor
              Found in lib/document.js by fixme

              TODO found
              Open

                            //TODO Expand error with more information
              Severity: Minor
              Found in lib/model.js by fixme

              TODO found
              Open

                  //TODO Set a (string) id per document and use it to perform faster lookup
              Severity: Minor
              Found in lib/document.js by fixme

              TODO found
              Open

                      // TODO: This regex seems a bit too generous since messages such
              Severity: Minor
              Found in lib/model.js by fixme

              TODO found
              Open

                      //TODO: Should we warn the users? Throw an error?
              Severity: Minor
              Found in lib/document.js by fixme

              TODO found
              Open

                  //TODO: We do not need to make a deep copy. We can do the same as for this._schemaOptions.
              Severity: Minor
              Found in lib/document.js by fixme
              Severity
              Category
              Status
              Source
              Language