michielbdejong/solid-ui

View on GitHub
src/utils.js

Summary

Maintainability
F
5 days
Test Coverage

File utils.js has 512 lines of code (exceeds 250 allowed). Consider refactoring.
Open

//                  Solid-UI general Utilities
//                  ==========================
//
// This must load AFTER the rdflib.js and log-ext.js (or log.js).
//
Severity: Major
Found in src/utils.js - About 1 day to fix

    Function label has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

    function label (x, initialCap) {
      // x is an object
      function doCap (s) {
        // s = s.toString()
        if (initialCap) return s.slice(0, 1).toUpperCase() + s.slice(1)
    Severity: Minor
    Found in src/utils.js - 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

    Function shortName has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    function shortName (uri) {
      let p = uri
      if ('#/'.indexOf(p[p.length - 1]) >= 0) p = p.slice(0, -1)
      const namespaces = []
      for (const ns in this.prefixes) {
    Severity: Minor
    Found in src/utils.js - 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

    Function label has 77 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function label (x, initialCap) {
      // x is an object
      function doCap (s) {
        // s = s.toString()
        if (initialCap) return s.slice(0, 1).toUpperCase() + s.slice(1)
    Severity: Major
    Found in src/utils.js - About 3 hrs to fix

      Function syncTableToArray has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      function syncTableToArray (table, things, createNewRow) {
        let foundOne
        let row
        let i
      
      
      Severity: Minor
      Found in src/utils.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 syncTableToArrayReOrdered has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      function syncTableToArrayReOrdered (table, things, createNewRow) {
        const elementMap = {}
      
        for (let i = 0; i < table.children.length; i++) {
          const row = table.children[i]
      Severity: Minor
      Found in src/utils.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 ontologyLabel has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      function ontologyLabel (term) {
        if (term.uri === undefined) return '??'
        var s = term.uri
        var namespaces = []
        var i = s.lastIndexOf('#')
      Severity: Minor
      Found in src/utils.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 syncTableToArray has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function syncTableToArray (table, things, createNewRow) {
        let foundOne
        let row
        let i
      
      
      Severity: Minor
      Found in src/utils.js - About 1 hr to fix

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

        function ontologyLabel (term) {
          if (term.uri === undefined) return '??'
          var s = term.uri
          var namespaces = []
          var i = s.lastIndexOf('#')
        Severity: Minor
        Found in src/utils.js - About 1 hr to fix

          Function shortName has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function shortName (uri) {
            let p = uri
            if ('#/'.indexOf(p[p.length - 1]) >= 0) p = p.slice(0, -1)
            const namespaces = []
            for (const ns in this.prefixes) {
          Severity: Minor
          Found in src/utils.js - About 1 hr to fix

            Function getTerm has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

            function getTerm (target) {
              var statementTr = target.parentNode
              var st = statementTr ? statementTr.AJAR_statement : undefined
            
              var className = st ? target.className : '' // if no st then it's necessary to use getAbout
            Severity: Minor
            Found in src/utils.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 syncTableToArrayReOrdered has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function syncTableToArrayReOrdered (table, things, createNewRow) {
              const elementMap = {}
            
              for (let i = 0; i < table.children.length; i++) {
                const row = table.children[i]
            Severity: Minor
            Found in src/utils.js - About 1 hr to fix

              Function predicateLabelForXML has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function predicateLabelForXML (p, inverse) {
                var lab
                if (inverse) {
                  // If we know an inverse predicate, use its label
                  var ip = UI.store.any(p, UI.ns.owl('inverseOf'))
              Severity: Minor
              Found in src/utils.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

              Function stackString has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function stackString (e) {
                let str = '' + e + '\n'
                let i
                if (!e.stack) {
                  return str + 'No stack available.\n'
              Severity: Minor
              Found in src/utils.js - About 35 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

              Avoid too many return statements within this function.
              Open

                    return term.uri + '!?' // strange should have a nice part
              Severity: Major
              Found in src/utils.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                  if (hash >= 0) return cleanUp(s.slice(hash + 1))
                Severity: Major
                Found in src/utils.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                    if (slash >= 0 && slash < x.uri.length) return cleanUp(s.slice(slash + 1))
                  Severity: Major
                  Found in src/utils.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return doCap(decodeURIComponent(x.uri))
                    Severity: Major
                    Found in src/utils.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          for (i = 0; ; i++) if (canUse(p.slice(0, 3) + i)) return pok
                      Severity: Major
                      Found in src/utils.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            if (canUse(p.slice(0, 1))) return pok
                        Severity: Major
                        Found in src/utils.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              if (canUse(p.slice(0, 5))) return pok
                          Severity: Major
                          Found in src/utils.js - About 30 mins to fix

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

                            function getEyeFocus (element, instantly, isBottom, myWindow) {
                              if (!myWindow) myWindow = window
                              var elementPosY = findPos(element)[1]
                              var totalScroll = elementPosY - 52 - myWindow.scrollY // magic number 52 for web-based version
                              if (instantly) {
                            Severity: Minor
                            Found in src/utils.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

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

                              var hash = function (x) {
                                return x.split('').reduce(function (a, b) {
                                  a = (a << 5) - a + b.charCodeAt(0)
                                  return a & a
                                }, 0)
                            Severity: Major
                            Found in src/utils.js and 1 other location - About 1 hr to fix
                            src/pad.js on lines 31..36

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

                            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

                            function RDFComparePredicateSubject (self, other) {
                              var x = self.predicate.compareTerm(other.predicate)
                              if (x !== 0) return x
                              return self.subject.compareTerm(other.subject)
                            }
                            Severity: Major
                            Found in src/utils.js and 1 other location - About 1 hr to fix
                            src/utils.js on lines 640..644

                            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

                            function RDFComparePredicateObject (self, other) {
                              var x = self.predicate.compareTerm(other.predicate)
                              if (x !== 0) return x
                              return self.object.compareTerm(other.object)
                            }
                            Severity: Major
                            Found in src/utils.js and 1 other location - About 1 hr to fix
                            src/utils.js on lines 646..650

                            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

                            There are no issues that match your filters.

                            Category
                            Status