ForestAdmin/forest-express-mongoose

View on GitHub

Showing 63 of 66 total issues

Function formatOperatorValue has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  this.formatOperatorValue = async (field, operator, value) => {
    if (this.operatorDateParser.isDateOperator(operator)) {
      return this.operatorDateParser.getDateFilter(operator, value);
    }

Severity: Minor
Found in src/services/filters-parser.js - About 1 hr to fix

    Function perform has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async perform() {
        const params = await getScopedParams(this._params, this._model, this._user);
        const field = _.find(this._schema.fields, { field: params.groupByFieldName });
        const queryBuilder = new QueryBuilder(this._model, params, this._opts);
        const populateGroupByField = this._getReference(params.groupByFieldName);
    Severity: Minor
    Found in src/services/pie-stat-getter.js - About 1 hr to fix

      Function _getValidations has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static _getValidations(fieldInfo) {
          const validations = [];
      
          if (fieldInfo.validators && fieldInfo.validators.length > 0) {
            _.each(fieldInfo.validators, (validator) => {
      Severity: Minor
      Found in src/utils/field-analyser.js - About 1 hr to fix

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

          _getTypeFromNative(type) {
            if (type instanceof Array) {
              if (_.isEmpty(type)) {
                return [null];
              }
        Severity: Minor
        Found in src/utils/field-analyser.js - About 1 hr to fix

          Function getNestedFieldType has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          const getNestedFieldType = (mongooseSchema, nestedFieldPath) => {
            if (!mongooseSchema || !nestedFieldPath) return undefined;
          
            const [currentFieldName, ...deepNestedFieldPath] = nestedFieldPath.split(FLATTEN_SEPARATOR);
          
          
          Severity: Minor
          Found in src/utils/schema.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

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

            constructor(schema, flatten, model, lianaOptions) {
              this.schema = schema;
              this.flatten = flatten;
              this.model = model;
              this.lianaOptions = lianaOptions;
          Severity: Major
          Found in src/services/flattener.js and 4 other locations - About 1 hr to fix
          src/services/embedded-document-updater.js on lines 2..7
          src/services/resource-updater.js on lines 9..14
          src/services/resources-remover.js on lines 5..10
          src/services/value-stat-getter.js on lines 5..10

          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 56.

          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

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

            constructor(model, params, record, user) {
              this._model = model;
              this._params = params;
              this._record = record;
              this._user = user;
          Severity: Major
          Found in src/services/resource-updater.js and 4 other locations - About 1 hr to fix
          src/services/embedded-document-updater.js on lines 2..7
          src/services/flattener.js on lines 9..14
          src/services/resources-remover.js on lines 5..10
          src/services/value-stat-getter.js on lines 5..10

          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 56.

          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

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

            constructor(model, params, opts, user) {
              this._model = model;
              this._params = params;
              this._opts = opts;
              this._user = user;
          Severity: Major
          Found in src/services/value-stat-getter.js and 4 other locations - About 1 hr to fix
          src/services/embedded-document-updater.js on lines 2..7
          src/services/flattener.js on lines 9..14
          src/services/resource-updater.js on lines 9..14
          src/services/resources-remover.js on lines 5..10

          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 56.

          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

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

            constructor(model, params, association, record) {
              this._model = model;
              this._params = params;
              this._association = association;
              this._record = record;
          Severity: Major
          Found in src/services/embedded-document-updater.js and 4 other locations - About 1 hr to fix
          src/services/flattener.js on lines 9..14
          src/services/resource-updater.js on lines 9..14
          src/services/resources-remover.js on lines 5..10
          src/services/value-stat-getter.js on lines 5..10

          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 56.

          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

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

            constructor(model, params, ids, user) {
              this._model = model;
              this._params = params;
              this._ids = ids;
              this._user = user;
          Severity: Major
          Found in src/services/resources-remover.js and 4 other locations - About 1 hr to fix
          src/services/embedded-document-updater.js on lines 2..7
          src/services/flattener.js on lines 9..14
          src/services/resource-updater.js on lines 9..14
          src/services/value-stat-getter.js on lines 5..10

          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 56.

          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 _formatLabel has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            static _formatLabel(record, momentRange) {
              switch (momentRange) {
                case 'day':
                  return moment()
                    .year(record._id.year)
          Severity: Minor
          Found in src/services/line-stat-getter.js - About 1 hr to fix

            Function perform has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async perform() {
                const modelName = utils.getModelName(this._model);
                const schema = Interface.Schemas.schemas[utils.getModelName(this._model)];
            
                const recordId = this._record._id;
            Severity: Minor
            Found in src/services/resource-updater.js - About 1 hr to fix

              Function getFieldSchema has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                getFieldSchema(path, fieldInfo) {
                  const schema = { field: path, type: this._getTypeFromMongoose(fieldInfo) };
              
                  const ref = this._detectReference(fieldInfo);
                  if (ref) { schema.reference = ref; }
              Severity: Minor
              Found in src/utils/field-analyser.js - About 1 hr to fix

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                function NoMatchingOperatorError(message) {
                  this.name = 'NoMatchingOperatorError';
                  this.message = message || 'The given operator is not handled.';
                  this.stack = (new Error()).stack;
                }
                Severity: Major
                Found in src/services/errors.js and 2 other locations - About 55 mins to fix
                src/services/errors.js on lines 8..12
                src/services/errors.js on lines 15..19

                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 53.

                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

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                function InvalidParameterError(message) {
                  this.name = 'InvalidParameterError';
                  this.message = message || 'The given parameter is invalid.';
                  this.stack = (new Error()).stack;
                }
                Severity: Major
                Found in src/services/errors.js and 2 other locations - About 55 mins to fix
                src/services/errors.js on lines 1..5
                src/services/errors.js on lines 8..12

                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 53.

                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

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                function InvalidFiltersFormatError(message) {
                  this.name = 'InvalidFiltersFormatError';
                  this.message = message || 'The filters format is not a valid JSON string.';
                  this.stack = (new Error()).stack;
                }
                Severity: Major
                Found in src/services/errors.js and 2 other locations - About 55 mins to fix
                src/services/errors.js on lines 1..5
                src/services/errors.js on lines 15..19

                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 53.

                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

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    return this._model
                      .findByIdAndUpdate(this._params.recordId, {
                        $pull: updateParams,
                      }, {
                        new: true,
                Severity: Major
                Found in src/services/has-many-dissociator.js and 2 other locations - About 50 mins to fix
                src/services/belongs-to-updater.js on lines 16..23
                src/services/has-many-associator.js on lines 16..23

                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 51.

                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

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    return this._model
                      .findByIdAndUpdate(this._params.recordId, {
                        $push: updateParams,
                      }, {
                        new: true,
                Severity: Major
                Found in src/services/has-many-associator.js and 2 other locations - About 50 mins to fix
                src/services/belongs-to-updater.js on lines 16..23
                src/services/has-many-dissociator.js on lines 21..28

                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 51.

                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

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                    return this._model
                      .findByIdAndUpdate(this._params.recordId, {
                        $set: updateParams,
                      }, {
                        new: true,
                Severity: Major
                Found in src/services/belongs-to-updater.js and 2 other locations - About 50 mins to fix
                src/services/has-many-associator.js on lines 16..23
                src/services/has-many-dissociator.js on lines 21..28

                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 51.

                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 requestUnflattener has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  static requestUnflattener(request, response, next) {
                    if (request.originalUrl.includes('.csv?')) {
                      return next();
                    }
                
                
                Severity: Minor
                Found in src/services/flattener.js - About 45 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