ForestAdmin/forest-express-mongoose

View on GitHub

Showing 42 of 66 total issues

Function init has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

exports.init = (opts) => {
  exports.opts = opts;

  if (!opts.objectMapping) {
    Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
Severity: Minor
Found in src/index.js - About 1 day 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 FiltersParser has 183 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function FiltersParser(model, timezone, options) {
  const modelSchema = Interface.Schemas.schemas[utils.getModelName(model)];

  const parseInteger = (value) => Number.parseInt(value, 10);
  const parseDate = (value) => new Date(value);
Severity: Major
Found in src/services/filters-parser.js - About 7 hrs to fix

    Function FiltersParser has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
    Open

    function FiltersParser(model, timezone, options) {
      const modelSchema = Interface.Schemas.schemas[utils.getModelName(model)];
    
      const parseInteger = (value) => Number.parseInt(value, 10);
      const parseDate = (value) => new Date(value);
    Severity: Minor
    Found in src/services/filters-parser.js - About 7 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 init has 116 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    exports.init = (opts) => {
      exports.opts = opts;
    
      if (!opts.objectMapping) {
        Interface.logger.error('The objectMapping option appears to be missing. Please make sure it is set correctly.');
    Severity: Major
    Found in src/index.js - About 4 hrs to fix

      Function _getTypeFromMongoose has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

        _getTypeFromMongoose(fieldInfo) {
          if (_.isPlainObject(fieldInfo) && !fieldInfo.path) {
            // Deal with Object
            return this._objectType(
              fieldInfo,
      Severity: Minor
      Found in src/utils/field-analyser.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 perform has 92 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async perform() {
          const params = await getScopedParams(this._params, this._model, this._user);
          const timezone = -parseInt(moment().tz(params.timezone).format('Z'), 10);
          const timezoneOffset = timezone * 60 * 60 * 1000;
          const queryBuilder = new QueryBuilder(this._model, params, this._opts);
      Severity: Major
      Found in src/services/line-stat-getter.js - About 3 hrs to fix

        Function SearchBuilder has 85 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        function SearchBuilder(model, opts, params, searchFields) {
          const schema = Interface.Schemas.schemas[utils.getModelName(model)];
          const fieldsSearched = [];
        
          this.hasSmartFieldSearch = false;
        Severity: Major
        Found in src/services/search-builder.js - About 3 hrs to fix

          Function getConditions has 76 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            this.getConditions = async () => {
              this.hasSmartFieldSearch = false;
              const orQuery = { $or: [] };
          
              function pushCondition(condition, fieldName) {
          Severity: Major
          Found in src/services/search-builder.js - About 3 hrs to fix

            exports has 26 functions (exceeds 20 allowed). Consider refactoring.
            Open

            module.exports = class Flattener {
              constructor(schema, flatten, model, lianaOptions) {
                this.schema = schema;
                this.flatten = flatten;
                this.model = model;
            Severity: Minor
            Found in src/services/flattener.js - About 3 hrs to fix

              File flattener.js has 280 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import _ from 'lodash';
              import Interface from 'forest-express';
              import FieldIntrospector from '../utils/field-analyser';
              import { getMongooseSchemaFromFieldPath } from '../utils/schema';
              
              
              Severity: Minor
              Found in src/services/flattener.js - About 2 hrs to fix

                Function _getTypeFromNative has a Cognitive Complexity of 18 (exceeds 5 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 2 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 formatConditionForReferences has 52 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  this.formatConditionForReferences = async (condition) => {
                    if (_.isEmpty(condition)) {
                      throw new InvalidFiltersFormatError('Empty condition in filter');
                    }
                    if (!_.isObject(condition)) {
                Severity: Major
                Found in src/services/filters-parser.js - About 2 hrs to fix

                  Function _getTypeFromMongoose has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    _getTypeFromMongoose(fieldInfo) {
                      if (_.isPlainObject(fieldInfo) && !fieldInfo.path) {
                        // Deal with Object
                        return this._objectType(
                          fieldInfo,
                  Severity: Minor
                  Found in src/utils/field-analyser.js - About 1 hr to fix

                    Function _detectReference has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                    Open

                      _detectReference(fieldInfo) {
                        if (fieldInfo.options) {
                          if (fieldInfo.options.ref && fieldInfo.options.type) {
                            const ref = this._formatRef(fieldInfo.options.ref);
                            return ref ? `${ref}._id` : null;
                    Severity: Minor
                    Found in src/utils/field-analyser.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 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 _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 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 _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

                            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
                              Severity
                              Category
                              Status
                              Source
                              Language