yamadapc/mongoose-private-paths

View on GitHub
lib/index.js

Summary

Maintainability
C
1 day
Test Coverage

Function exports has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
Open

module.exports = function(schema, options) {
  options = _.defaults(options || {}, DEFAULT_OPTIONS);

  var private_paths = getPaths(schema, options);
  var refs = getRefs(schema);
Severity: Minor
Found in lib/index.js - About 3 hrs 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 exports has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function(schema, options) {
  options = _.defaults(options || {}, DEFAULT_OPTIONS);

  var private_paths = getPaths(schema, options);
  var refs = getRefs(schema);
Severity: Major
Found in lib/index.js - About 2 hrs to fix

    Function omitPopulated has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    function omitPopulated(refs, obj, populated, options) {
      for(var i = 0, len = populated.length; i < len; i++) {
        var path = populated[i];
        var modelName = refs[path] && (_.isArray(refs[path]) ? refs[path][0].ref : refs[path].ref);
        var model;
    Severity: Minor
    Found in lib/index.js - About 1 hr 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 isPrivate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    function isPrivate(options, node, path) {
      if(!node) return false;
    
      // Array case
      if(node instanceof Array) {
    Severity: Minor
    Found in lib/index.js - About 1 hr 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

      else if(_.includes(options.ignore, path)) return false;
    Severity: Major
    Found in lib/index.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          else return isPrivate(options, node, path);
      Severity: Major
      Found in lib/index.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

          else return node.private || path[0] === options.prefix;
        Severity: Major
        Found in lib/index.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return _.isEmpty(o) ? false : o;
          Severity: Major
          Found in lib/index.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              else if(node.private === false) return false;
            Severity: Major
            Found in lib/index.js - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status