mimani/mongoose-diff-history

View on GitHub

Showing 10 of 15 total issues

Function lastModifiedPlugin has 70 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const plugin = function lastModifiedPlugin(schema, opts = {}) {
    if (opts.uri) {
        const mongoVersion = parseInt(mongoose.version);
        if (mongoVersion < 5) {
            mongoose.connect(opts.uri, { useMongoClient: true }).catch(e => {
Severity: Major
Found in diffHistory.js - About 2 hrs to fix

    File diffHistory.js has 282 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const mongoose = require('mongoose');
    
    const omit = require('omit-deep');
    const pick = require('lodash.pick');
    const empty = require('deep-empty-object');
    Severity: Minor
    Found in diffHistory.js - About 2 hrs to fix

      Function getHistories has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const getHistories = (modelName, id, expandableFields, cb) => {
          expandableFields = expandableFields || [];
          if (typeof expandableFields === 'function') {
              cb = expandableFields;
              expandableFields = [];
      Severity: Minor
      Found in diffHistory.js - About 1 hr to fix

        Function saveDiffHistory has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const saveDiffHistory = (queryObject, currentObject, opts) => {
            const queryUpdate = queryObject.getUpdate();
            const schemaOptions = queryObject.model.schema.options || {};
        
            let keysToBeModified = [];
        Severity: Minor
        Found in diffHistory.js - About 1 hr to fix

          Function saveDiffObject has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function saveDiffObject(currentObject, original, updated, opts, queryObject) {
              const { __user: user, __reason: reason, __session: session } =
                  (queryObject && queryObject.options) || currentObject;
          
              let diff = diffPatcher.diff(
          Severity: Minor
          Found in diffHistory.js - About 1 hr to fix

            Function saveDiffHistory has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            const saveDiffHistory = (queryObject, currentObject, opts) => {
                const queryUpdate = queryObject.getUpdate();
                const schemaOptions = queryObject.model.schema.options || {};
            
                let keysToBeModified = [];
            Severity: Minor
            Found in diffHistory.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 getVersion has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const getVersion = (model, id, version, queryOpts, cb) => {
                if (typeof queryOpts === 'function') {
                    cb = queryOpts;
                    queryOpts = undefined;
                }
            Severity: Minor
            Found in diffHistory.js - About 1 hr to fix

              Function lastModifiedPlugin has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

              const plugin = function lastModifiedPlugin(schema, opts = {}) {
                  if (opts.uri) {
                      const mongoVersion = parseInt(mongoose.version);
                      if (mongoVersion < 5) {
                          mongoose.connect(opts.uri, { useMongoClient: true }).catch(e => {
              Severity: Minor
              Found in diffHistory.js - About 55 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 saveDiffObject has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              function saveDiffObject(currentObject, original, updated, opts, queryObject) {
              Severity: Minor
              Found in diffHistory.js - About 35 mins to fix

                Function checkRequired has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                function checkRequired(opts, queryObject, updatedObject) {
                    if (queryObject && !queryObject.options && !updatedObject) {
                        return;
                    }
                    const { __user: user, __reason: reason } =
                Severity: Minor
                Found in diffHistory.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

                Severity
                Category
                Status
                Source
                Language