contartec-team/generic-model-bookshelf

View on GitHub

Showing 18 of 20 total issues

GenericModel has 76 functions (exceeds 20 allowed). Consider refactoring.
Open

class GenericModel extends bookshelf.Model {

  /**
   * The `GenericModel` params
   * @description A mix of `bookshelf` and custom options (override this with the desired one)
Severity: Major
Found in lib/GenericModel.js - About 1 day to fix

    File GenericModel.js has 608 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict'
    
    const ObjectUtils = require('@contartec-team/object-utils')
    const validate = require('validate.js')
    
    
    Severity: Major
    Found in lib/GenericModel.js - About 1 day to fix

      Function getQueryAll has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        static getQueryAll(params, model, queryBuilder, isWhere = true) {
          const queryBoolean = isWhere ?
            'where' :
            'orWhere'
      
      
      Severity: Minor
      Found in lib/GenericModel.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 getQueryAll has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        static getQueryAll(params, model, queryBuilder, isWhere = true) {
          const queryBoolean = isWhere ?
            'where' :
            'orWhere'
      
      
      Severity: Minor
      Found in lib/GenericModel.js - About 1 hr to fix

        Function getAll has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static getAll(params, fetchOptions = {}) {
            const paramsTemp = { ...this.GET_ALL_DEFAULT_PARAMS, ...params }
            const fetchOptionsTemp = { ...this.GET_ALL_DEFAULT_FETCH_OPTIONS, ...fetchOptions }
        
            if (typeof(paramsTemp.orderBy) == 'string')
        Severity: Minor
        Found in lib/GenericModel.js - About 1 hr to fix

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

                    queryBuilder
                      .leftJoin(relatedManyToMany.tableName, `${relatedManyToMany.tableName}.${relatedManyToMany.idAttribute}`, `${related.tableName}.${relatedManyToMany.attrName}`)
          Severity: Major
          Found in lib/GenericModel.js and 1 other location - About 1 hr to fix
          lib/GenericModel.js on lines 759..760

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

          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 2 locations. Consider refactoring.
          Open

                  queryBuilder
                    .leftJoin(related.tableName, `${related.tableName}.${related.idAttribute}`, `${model.tableName}.${related.attrName}`)
          Severity: Major
          Found in lib/GenericModel.js and 1 other location - About 1 hr to fix
          lib/GenericModel.js on lines 767..768

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

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

            serialize(options) {
              const optionsTemp = { ...this._SERIALIZE_OPTIONS, ...options }
          
              let json = super
                .serialize(optionsTemp)
          Severity: Minor
          Found in lib/GenericModel.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

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

            _hasHiddenAttribute(attr) {
              let hasAttr = false
          
              if (this._hasHiddenAttributes())
                hasAttr = this.hidden.indexOf(attr) >= 0
          Severity: Major
          Found in lib/GenericModel.js and 2 other locations - About 55 mins to fix
          lib/GenericModel.js on lines 490..497
          lib/GenericModel.js on lines 512..519

          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

            _hasRelated(attr) {
              let hasAttr = false
          
              if (this._hasRelateds())
                hasAttr = this.relateds.indexOf(attr) >= 0
          Severity: Major
          Found in lib/GenericModel.js and 2 other locations - About 55 mins to fix
          lib/GenericModel.js on lines 490..497
          lib/GenericModel.js on lines 499..506

          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

            _hasVisibleAttribute(attr) {
              let hasAttr = false
          
              if (this._hasVisibleAttributes())
                hasAttr = this.visible.indexOf(attr) >= 0
          Severity: Major
          Found in lib/GenericModel.js and 2 other locations - About 55 mins to fix
          lib/GenericModel.js on lines 499..506
          lib/GenericModel.js on lines 512..519

          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

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

            _getAttributes(object) {
              let visibleAttributes = {}
          
              if (this._hasVisibleAttributes()) {
                const definedAttributes = this.getAttributes()
          Severity: Minor
          Found in lib/GenericModel.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

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

            _getNotDefinedAttributes(object) {
              let notDefinedAttributes = {}
          
              if (this._hasAttributes()) {
                for (const attr in object) {
          Severity: Minor
          Found in lib/GenericModel.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

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

            _getVisibleAttributes(object) {
              let visibleAttributes = {}
          
              if (this._hasVisibleAttributes()) {
                for (const attr in object) {
          Severity: Minor
          Found in lib/GenericModel.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

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

            _getRelateds(object) {
              const relateds = {}
          
              if (this._hasRelateds()) {
                for (const attr in object) {
          Severity: Minor
          Found in lib/GenericModel.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

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

            _getHiddenAttributes(object) {
              let hiddenAttributes = {}
          
              if (this._hasHiddenAttributes()) {
                for (const attr in object) {
          Severity: Minor
          Found in lib/GenericModel.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

          Bare URL used
          Open

          https://contartec-team.github.io/generic-model-bookshelf/
          Severity: Info
          Found in README.md by markdownlint

          MD034 - Bare URL used

          Tags: links, url

          Aliases: no-bare-urls

          This rule is triggered whenever a URL is given that isn't surrounded by angle brackets:

          For more information, see http://www.example.com/.

          To fix this, add angle brackets around the URL:

          For more information, see <http:></http:>.

          Rationale: Without angle brackets, the URL isn't converted into a link in many markdown parsers.

          Note: if you do want a bare URL without it being converted into a link, enclose it in a code block, otherwise in some markdown parsers it will be converted:

          `http://www.example.com`

          First header should be a top level header
          Open

          ## Install
          Severity: Info
          Found in README.md by markdownlint

          MD002 - First header should be a top level header

          Tags: headers

          Aliases: first-header-h1

          Parameters: level (number; default 1)

          This rule is triggered when the first header in the document isn't a h1 header:

          ## This isn't a H1 header
          
          ### Another header

          The first header in the document should be a h1 header:

          # Start with a H1 header
          
          ## Then use a H2 for subsections
          Severity
          Category
          Status
          Source
          Language