michielbdejong/solid-ui

View on GitHub
src/widgets/buttons.js

Summary

Maintainability
F
6 days
Test Coverage

File buttons.js has 853 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* UI Widgets such as buttons
 */
/* global alert */

const $rdf = require('rdflib')
Severity: Major
Found in src/widgets/buttons.js - About 2 days to fix

    Function attachmentList has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    buttons.attachmentList = function (dom, subject, div, options) {
      options = options || {}
      var doc = options.doc || subject.doc()
      if (options.modify === undefined) options.modify = true
      var modify = options.modify
    Severity: Major
    Found in src/widgets/buttons.js - About 2 hrs to fix

      Function selectorPanelRefresh has 64 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      buttons.selectorPanelRefresh = function (
        list,
        dom,
        kb,
        type,
      Severity: Major
      Found in src/widgets/buttons.js - About 2 hrs to fix

        Function refreshItem has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          var refreshItem = function (box, x) {
            // Scope to hold item and x
            var item, image
        
            var setStyle = function () {
        Severity: Major
        Found in src/widgets/buttons.js - About 2 hrs to fix

          Function deleteButtonWithCheck has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          buttons.deleteButtonWithCheck = function (
            dom,
            container,
            noun,
            deleteFunction
          Severity: Minor
          Found in src/widgets/buttons.js - About 1 hr to fix

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

            buttons.selectorPanelRefresh = function (
              list,
              dom,
              kb,
              type,
            Severity: Minor
            Found in src/widgets/buttons.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 askName has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            buttons.askName = function (dom, kb, container, predicate, klass, noun) {
              // eslint-disable-next-line promise/param-names
              return new Promise(function (resolve, _reject) {
                var form = dom.createElement('div') // form is broken as HTML behaviour can resurface on js error
                // classLabel = utils.label(ns.vcard('Individual'))
            Severity: Minor
            Found in src/widgets/buttons.js - About 1 hr to fix

              Function selectorPanelRefresh has 10 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                list,
                dom,
                kb,
                type,
                predicate,
              Severity: Major
              Found in src/widgets/buttons.js - About 1 hr to fix

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

                buttons.findImageFromURI = function findImageFromURI (x) {
                  const iconDir = UI.icons.iconBase
                
                  // Special cases from URI scheme:
                  if (x.uri) {
                Severity: Minor
                Found in src/widgets/buttons.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 shortDate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                buttons.shortDate = function (str, noTime) {
                  if (!str) return '???'
                  var month = [
                    'Jan',
                    'Feb',
                Severity: Minor
                Found in src/widgets/buttons.js - About 1 hr to fix

                  Function fileUploadButtonDiv has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  buttons.fileUploadButtonDiv = function fileUploadButtonDiv (
                    dom,
                    droppedFileHandler
                  ) {
                    const div = dom.createElement('div')
                  Severity: Minor
                  Found in src/widgets/buttons.js - About 1 hr to fix

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

                    buttons.propertyTriage = function (kb) {
                      var possibleProperties = {}
                      // if (possibleProperties === undefined) possibleProperties = {}
                      // var kb = UI.store
                      var dp = {}
                    Severity: Minor
                    Found in src/widgets/buttons.js - About 1 hr to fix

                      Function selectorPanel has 9 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                        dom,
                        kb,
                        type,
                        predicate,
                        inverse,
                      Severity: Major
                      Found in src/widgets/buttons.js - About 1 hr to fix

                        Function personTR has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        buttons.personTR = function (dom, pred, obj, options) {
                          var tr = dom.createElement('tr')
                          options = options || {}
                          // tr.predObj = [pred.uri, obj.uri]   moved to acl-control
                          var td1 = tr.appendChild(dom.createElement('td'))
                        Severity: Minor
                        Found in src/widgets/buttons.js - About 1 hr to fix

                          Function _trySetImage has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          buttons._trySetImage = function _trySetImage (element, thing, iconForClassMap) {
                            const kb = UI.store
                          
                            const explitImage = buttons.findImage(thing)
                            if (explitImage) {
                          Severity: Minor
                          Found in src/widgets/buttons.js - About 1 hr to fix

                            Function askName has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            buttons.askName = function (dom, kb, container, predicate, klass, noun) {
                            Severity: Minor
                            Found in src/widgets/buttons.js - About 45 mins to fix

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

                              buttons.attachmentList = function (dom, subject, div, options) {
                                options = options || {}
                                var doc = options.doc || subject.doc()
                                if (options.modify === undefined) options.modify = true
                                var modify = options.modify
                              Severity: Minor
                              Found in src/widgets/buttons.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 faviconOrDefault has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                              Open

                              var faviconOrDefault = function (dom, x) {
                                var image = dom.createElement('img')
                                image.style = UI.style.iconStyle
                                var isOrigin = function (x) {
                                  if (!x.uri) return false
                              Severity: Minor
                              Found in src/widgets/buttons.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

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

                              buttons.propertyTriage = function (kb) {
                                var possibleProperties = {}
                                // if (possibleProperties === undefined) possibleProperties = {}
                                // var kb = UI.store
                                var dp = {}
                              Severity: Minor
                              Found in src/widgets/buttons.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 null
                              Severity: Major
                              Found in src/widgets/buttons.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                  return false // we can do better
                                Severity: Major
                                Found in src/widgets/buttons.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                    return iconDir + 'noun_10636_grey.svg' // Grey Circle -  some thing
                                  Severity: Major
                                  Found in src/widgets/buttons.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                        return 'shortdate:' + e
                                    Severity: Major
                                    Found in src/widgets/buttons.js - About 30 mins to fix

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

                                      buttons._trySetImage = function _trySetImage (element, thing, iconForClassMap) {
                                        const kb = UI.store
                                      
                                        const explitImage = buttons.findImage(thing)
                                        if (explitImage) {
                                      Severity: Minor
                                      Found in src/widgets/buttons.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 personTR has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      buttons.personTR = function (dom, pred, obj, options) {
                                        var tr = dom.createElement('tr')
                                        options = options || {}
                                        // tr.predObj = [pred.uri, obj.uri]   moved to acl-control
                                        var td1 = tr.appendChild(dom.createElement('td'))
                                      Severity: Minor
                                      Found in src/widgets/buttons.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 defaultAnnotationStore has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                      Open

                                      buttons.defaultAnnotationStore = function (subject) {
                                        if (subject.uri === undefined) return undefined
                                        var s = subject.uri
                                        if (s.slice(0, 7) !== 'http://') return undefined
                                        s = s.slice(7) // Remove
                                      Severity: Minor
                                      Found in src/widgets/buttons.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

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

                                      buttons.refreshTree = function refreshTree (root) {
                                        if (root.refresh) {
                                          root.refresh()
                                          return
                                        }
                                      Severity: Major
                                      Found in src/widgets/buttons.js and 1 other location - About 1 hr to fix
                                      src/pad.js on lines 811..819

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

                                      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

                                            kb.any(x, ns.vcard('fn')) ||
                                            kb.any(x, ns.foaf('name')) ||
                                            kb.any(x, ns.vcard('organization-name'))
                                      Severity: Major
                                      Found in src/widgets/buttons.js and 1 other location - About 1 hr to fix
                                      src/widgets/buttons.js on lines 272..274

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

                                      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

                                          kb.any(thing, ns.sioc('avatar')) ||
                                          kb.any(thing, ns.foaf('img')) ||
                                          kb.any(thing, ns.vcard('logo')) ||
                                      Severity: Major
                                      Found in src/widgets/buttons.js and 1 other location - About 1 hr to fix
                                      src/widgets/buttons.js on lines 159..161

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

                                      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