ForestAdmin/forest-express-sequelize

View on GitHub

Showing 77 of 79 total issues

Function LeaderboardStatGetter has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function LeaderboardStatGetter(childModel, parentModel, params, user) {
  const labelField = params.labelFieldName;
  const aggregate = params.aggregator.toUpperCase();
  const { limit } = params;
  const childSchema = Schemas.schemas[childModel.name];
Severity: Major
Found in src/services/leaderboard-stat-getter.js - About 2 hrs to fix

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

        if (column.validate.contains) {
          validations.push({
            type: 'contains',
            value: column.validate.contains.args || column.validate.contains,
            message: column.validate.contains.msg,
    Severity: Major
    Found in src/services/apimap-field-builder.js and 4 other locations - About 2 hrs to fix
    src/services/apimap-field-builder.js on lines 31..37
    src/services/apimap-field-builder.js on lines 39..45
    src/services/apimap-field-builder.js on lines 47..53
    src/services/apimap-field-builder.js on lines 55..61

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

    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

        if (column.validate.max) {
          validations.push({
            type: 'is less than',
            value: column.validate.max.args || column.validate.max,
            message: column.validate.max.msg,
    Severity: Major
    Found in src/services/apimap-field-builder.js and 4 other locations - About 2 hrs to fix
    src/services/apimap-field-builder.js on lines 31..37
    src/services/apimap-field-builder.js on lines 47..53
    src/services/apimap-field-builder.js on lines 55..61
    src/services/apimap-field-builder.js on lines 89..95

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

    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

        if (column.validate.isAfter) {
          validations.push({
            type: 'is after',
            value: column.validate.isAfter.args || column.validate.isAfter,
            message: column.validate.isAfter.msg,
    Severity: Major
    Found in src/services/apimap-field-builder.js and 4 other locations - About 2 hrs to fix
    src/services/apimap-field-builder.js on lines 31..37
    src/services/apimap-field-builder.js on lines 39..45
    src/services/apimap-field-builder.js on lines 47..53
    src/services/apimap-field-builder.js on lines 89..95

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

    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

        if (column.validate.min) {
          validations.push({
            type: 'is greater than',
            value: column.validate.min.args || column.validate.min,
            message: column.validate.min.msg,
    Severity: Major
    Found in src/services/apimap-field-builder.js and 4 other locations - About 2 hrs to fix
    src/services/apimap-field-builder.js on lines 39..45
    src/services/apimap-field-builder.js on lines 47..53
    src/services/apimap-field-builder.js on lines 55..61
    src/services/apimap-field-builder.js on lines 89..95

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

    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

        if (column.validate.isBefore) {
          validations.push({
            type: 'is before',
            value: column.validate.isBefore.args || column.validate.isBefore,
            message: column.validate.isBefore.msg,
    Severity: Major
    Found in src/services/apimap-field-builder.js and 4 other locations - About 2 hrs to fix
    src/services/apimap-field-builder.js on lines 31..37
    src/services/apimap-field-builder.js on lines 39..45
    src/services/apimap-field-builder.js on lines 55..61
    src/services/apimap-field-builder.js on lines 89..95

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

    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

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

      function getAggregateField() {
        // NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'.
        const fieldName = params.aggregateFieldName
          || schema.primaryKeys[0]
          || schema.fields[0].field;
    Severity: Major
    Found in src/services/line-stat-getter.js and 1 other location - About 2 hrs to fix
    src/services/pie-stat-getter.js on lines 49..55

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

    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

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

      function getAggregateField() {
        // NOTICE: As MySQL cannot support COUNT(table_name.*) syntax, fieldName cannot be '*'.
        const fieldName = params.aggregateFieldName
          || schema.primaryKeys[0]
          || schema.fields[0].field;
    Severity: Major
    Found in src/services/pie-stat-getter.js and 1 other location - About 2 hrs to fix
    src/services/line-stat-getter.js on lines 12..18

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

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

    function normalizeInclude(model, include) {
      if (include.sequelize) {
        return {
          model: include,
          as: Object
    Severity: Minor
    Found in src/utils/sequelize-compatibility.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 ApimapFieldTypeDetector has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function ApimapFieldTypeDetector(column, options) {
      const DataTypes = options.Sequelize;
    
      this.perform = () => {
        if (column.type instanceof DataTypes.STRING
    Severity: Minor
    Found in src/services/apimap-field-type-detector.js - About 1 hr to fix

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

        this.perform = () => {
          if (column.type instanceof DataTypes.STRING
            || column.type instanceof DataTypes.TEXT
            || (DataTypes.CITEXT && column.type instanceof DataTypes.CITEXT)
            || column.type === 'citext') { // TODO: Remove 'citext' once Sequelize 4 has been deprecated.
      Severity: Minor
      Found in src/services/apimap-field-type-detector.js - About 1 hr to fix

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

          this.formatOperatorValue = (operator, value, isTextField = false) => {
            switch (operator) {
              case 'not':
                return { [this.OPERATORS.NOT]: value };
              case 'greater_than':
        Severity: Minor
        Found in src/services/filters-parser.js - About 1 hr to fix

          Function HasManyDissociator has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function HasManyDissociator(model, association, options, params, data) {
            const OPERATORS = Operators.getInstance(options);
            const isDelete = Boolean(params.delete);
          
            this.perform = () => {
          Severity: Minor
          Found in src/services/has-many-dissociator.js - About 1 hr to fix

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

              this.perform = () => {
                const schema = {
                  field: column.fieldName,
                  type: new ApimapFieldTypeDetector(column, options).perform(),
                  // NOTICE: Necessary only for fields with different field and database
            Severity: Minor
            Found in src/services/apimap-field-builder.js - About 1 hr to fix

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

              function ErrorHTTP422(message) {
                this.name = 'ErrorHTTP422';
                this.message = message || 'Unprocessable Entity';
                this.status = 422;
                this.stack = (new Error()).stack;
              Severity: Major
              Found in src/services/errors.js and 2 other locations - About 1 hr to fix
              src/services/errors.js on lines 9..14
              src/services/errors.js on lines 17..22

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

              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.status = 422;
                this.stack = (new Error()).stack;
              Severity: Major
              Found in src/services/errors.js and 2 other locations - About 1 hr to fix
              src/services/errors.js on lines 1..6
              src/services/errors.js on lines 9..14

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

              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 NoMatchingOperatorError(message) {
                this.name = 'NoMatchingOperatorError';
                this.message = message || 'The given operator is not handled.';
                this.status = 422;
                this.stack = (new Error()).stack;
              Severity: Major
              Found in src/services/errors.js and 2 other locations - About 1 hr to fix
              src/services/errors.js on lines 1..6
              src/services/errors.js on lines 17..22

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

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

              function normalizeInclude(model, include) {
                if (include.sequelize) {
                  return {
                    model: include,
                    as: Object
              Severity: Minor
              Found in src/utils/sequelize-compatibility.js - About 1 hr to fix

                Function removeDuplicateAssociations has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                function removeDuplicateAssociations(model, includeList) {
                  // Remove duplicates
                  includeList.sort((include1, include2) => (include1.as < include2.as ? -1 : 1));
                  for (let i = 1; i < includeList.length; i += 1) {
                    if (includeList[i - 1].as === includeList[i].as) {
                Severity: Minor
                Found in src/utils/sequelize-compatibility.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 2 locations. Consider refactoring.
                Open

                  constructor(model, params, ids, user) {
                    this._model = model.unscoped();
                    this._params = params;
                    this._ids = ids;
                    this._user = user;
                Severity: Major
                Found in src/services/resources-remover.js and 1 other location - About 1 hr to fix
                src/services/resource-updater.js on lines 7..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 63.

                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

                Severity
                Category
                Status
                Source
                Language