voxgig/seneca-owner

View on GitHub

Showing 27 of 27 total issues

Function Owner has 282 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function Owner(this: any, options: any) {
  const seneca = this

  const { deep } = seneca.util

Severity: Major
Found in src/Owner.ts - About 1 day to fix

    Function checkOwner has 235 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        const checkOwner: any = function checkOwner(this: any, msg: any, reply: any, meta: any) {
          const self = this
          const explain = this.explain()
    
          const expdata: any = explain && {
    Severity: Major
    Found in src/Owner.ts - About 1 day to fix

      File Owner.ts has 373 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /* Copyright (c) 2018-2020 Voxgig and other contributors, MIT License */
      /* $lab:coverage:off$ */
      'use strict'
      
      
      
      Severity: Minor
      Found in src/Owner.ts - About 4 hrs to fix

        Function refine_query has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
        Open

        export function refine_query(
          seneca: any,
          msg: any,
          queryprop: any,
          spec: any,
        Severity: Minor
        Found in src/refine_query.ts - About 4 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

        Consider simplifying this complex logical expression.
        Open

                if (include.custom) {
                  let cip, cval, mval
                  for (cip in include.custom) {
                    active = active && (
        
        
        Severity: Critical
        Found in src/Owner.ts - About 3 hrs to fix

          Function refine_query has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function refine_query(
            seneca: any,
            msg: any,
            queryprop: any,
            spec: any,
          Severity: Major
          Found in src/refine_query.ts - About 2 hrs to fix

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

                        if (modifiers.list) {
                          explain &&
                            ((expdata.modifiers.list = true),
                              (expdata.orig_list_len = list ? list.length : 0))
                          list = modifiers.list.call(self, spec, owner, msg, list)
            Severity: Major
            Found in src/Owner.ts and 1 other location - About 1 hr to fix
            src/Owner.ts on lines 216..221

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

            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

                        if (modifiers.list) {
                          explain &&
                            ((expdata.modifiers.list = true),
                              (expdata.orig_list_len = list ? list.length : 0))
                          list = modifiers.list.call(self, spec, owner, msg, list)
            Severity: Major
            Found in src/Owner.ts and 1 other location - About 1 hr to fix
            src/Owner.ts on lines 193..198

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

            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 refine_query has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              seneca: any,
              msg: any,
              queryprop: any,
              spec: any,
              owner: any,
            Severity: Major
            Found in src/refine_query.ts - About 50 mins to fix

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

                                fail = {
                                  code: 'update-not-allowed',
                                  details: {
                                    why: 'field-mismatch-on-update',
                                    field: fieldName,
              Severity: Minor
              Found in src/Owner.ts and 1 other location - About 50 mins to fix
              src/Owner.ts on lines 351..361

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

                                const fail = {
                                  code: 'create-not-allowed',
                                  details: {
                                    why: 'field-mismatch-on-create',
                                    field: fieldName,
              Severity: Minor
              Found in src/Owner.ts and 1 other location - About 50 mins to fix
              src/Owner.ts on lines 403..413

              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

              Avoid deeply nested control flow statements.
              Open

                          for (let fieldI = 0; fieldI < spec.fields.length; fieldI++) {
                            const fieldName = spec.fields[fieldI]
                            const [ownerFieldName, entityFieldName] =
                              (resolvedFieldNames[fieldName] ||
                                (resolvedFieldNames[fieldName] =
              Severity: Major
              Found in src/Owner.ts - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            if (null == msg[queryprop].id) {
                              explain && ((expdata.query_load = true), (expdata.ent = load_ent))
                
                              return intern.reply(self, reply, load_ent, explain, expdata)
                            }
                Severity: Major
                Found in src/Owner.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            if (!owner_value.includes(qval)) {
                              seneca.fail('field-values-not-valid', {
                                field: fieldName,
                                entityFieldName,
                                ownerFieldName,
                  Severity: Major
                  Found in src/refine_query.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                if (modifiers.entity) {
                                  explain && (expdata.modifiers.entity = true)
                    
                                  spec = modifiers.entity.call(self, spec, owner, msg, load_ent)
                                  explain && (expdata.modifiers.entity_spec = spec)
                    Severity: Major
                    Found in src/Owner.ts - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  if (err) return reply(err)
                      Severity: Major
                      Found in src/Owner.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                  if (null == msg[queryprop].id) {
                                    refine_query(self, msg, queryprop, spec, owner, intern, resolvedFieldNames)
                                    explain && (expdata.query = msg[queryprop])
                                  }
                        Severity: Major
                        Found in src/Owner.ts - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                  else if ('save' === msg.cmd) {
                                    explain && (expdata.path = 'save')
                          
                                    const ent = msg[entprop]
                          
                          
                          Severity: Major
                          Found in src/Owner.ts - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                        if (null == load_ent) return reply()
                            Severity: Major
                            Found in src/Owner.ts - About 45 mins to fix

                              Consider simplifying this complex logical expression.
                              Open

                                        if (null == ent.id) {
                                          explain && (expdata.path = 'save/create')
                              
                                          for (let fieldI = 0; fieldI < spec.fields.length; fieldI++) {
                                            const fieldName = spec.fields[fieldI]
                              Severity: Major
                              Found in src/Owner.ts - About 40 mins to fix
                                Severity
                                Category
                                Status
                                Source
                                Language