crowdAI/crowdai

View on GitHub
app/assets/javascripts/modules/sorttable.js

Summary

Maintainability
F
1 wk
Test Coverage

Function makeSortable has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

  makeSortable: function(table) {
    if (table.getElementsByTagName('thead').length == 0) {
      // table doesn't have a tHead. Since it should have, create one and
      // put the first table row in it.
      the = document.createElement('thead');
Severity: Minor
Found in app/assets/javascripts/modules/sorttable.js - About 1 day 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

File sorttable.js has 338 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*
  SortTable
  version 2
  7th April 2007
  Stuart Langridge, http://www.kryogenix.org/code/browser/sorttable/
Severity: Minor
Found in app/assets/javascripts/modules/sorttable.js - About 4 hrs to fix

    Function makeSortable has 89 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      makeSortable: function(table) {
        if (table.getElementsByTagName('thead').length == 0) {
          // table doesn't have a tHead. Since it should have, create one and
          // put the first table row in it.
          the = document.createElement('thead');
    Severity: Major
    Found in app/assets/javascripts/modules/sorttable.js - About 3 hrs to fix

      Function innerSortFunction has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

                dean_addEvent(headrow[i],"click", sorttable.innerSortFunction = function(e) {
      
                if (this.className.search(/\bsorttable_sorted\b/) != -1) {
                  // if we're already sorted by this column, just
                  // reverse the table, which is quicker
      Severity: Minor
      Found in app/assets/javascripts/modules/sorttable.js - About 2 hrs to fix

        Function guessType has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

          guessType: function(table, column) {
            // guess the type of a column based on its first non-blank row
            sortfn = sorttable.sort_alpha;
            for (var i=0; i<table.tBodies[0].rows.length; i++) {
              text = sorttable.getInnerText(table.tBodies[0].rows[i].cells[column]);
        Severity: Minor
        Found in app/assets/javascripts/modules/sorttable.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 getInnerText has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          getInnerText: function(node) {
            // gets the text we want to use for sorting for a cell.
            // strips leading and trailing whitespace.
            // this is *not* a generic getInnerText function; it's special to sorttable.
            // for example, you can override the cell text with a customkey attribute.
        Severity: Minor
        Found in app/assets/javascripts/modules/sorttable.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 shaker_sort has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          shaker_sort: function(list, comp_func) {
            // A stable sort function to allow multi-level sorting of data
            // see: http://en.wikipedia.org/wiki/Cocktail_sort
            // thanks to Joseph Nahmias
            var b = 0;
        Severity: Minor
        Found in app/assets/javascripts/modules/sorttable.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 getInnerText has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          getInnerText: function(node) {
            // gets the text we want to use for sorting for a cell.
            // strips leading and trailing whitespace.
            // this is *not* a generic getInnerText function; it's special to sorttable.
            // for example, you can override the cell text with a customkey attribute.
        Severity: Minor
        Found in app/assets/javascripts/modules/sorttable.js - About 1 hr to fix

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

          function dean_addEvent(element, type, handler) {
              if (element.addEventListener) {
                  element.addEventListener(type, handler, false);
              } else {
                  // assign each event handler a unique ID
          Severity: Minor
          Found in app/assets/javascripts/modules/sorttable.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

          Avoid too many return statements within this function.
          Open

                return node.text.replace(/^\s+|\s+$/g, '');
          Severity: Major
          Found in app/assets/javascripts/modules/sorttable.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                      return innerText.replace(/^\s+|\s+$/g, '');
            Severity: Major
            Found in app/assets/javascripts/modules/sorttable.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return node.value.replace(/^\s+|\s+$/g, '');
              Severity: Major
              Found in app/assets/javascripts/modules/sorttable.js - About 30 mins to fix

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

                  sort_ddmm: function(a,b) {
                    mtch = a[0].match(sorttable.DATE_RE);
                    y = mtch[3]; m = mtch[2]; d = mtch[1];
                    if (m.length == 1) m = '0'+m;
                    if (d.length == 1) d = '0'+d;
                Severity: Minor
                Found in app/assets/javascripts/modules/sorttable.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 forEach has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                var forEach = function(object, block, context) {
                    if (object) {
                        var resolve = Object; // default
                        if (object instanceof Function) {
                            // functions have a "length" property
                Severity: Minor
                Found in app/assets/javascripts/modules/sorttable.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 sort_mmdd has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                  sort_mmdd: function(a,b) {
                    mtch = a[0].match(sorttable.DATE_RE);
                    y = mtch[3]; d = mtch[2]; m = mtch[1];
                    if (m.length == 1) m = '0'+m;
                    if (d.length == 1) d = '0'+d;
                Severity: Minor
                Found in app/assets/javascripts/modules/sorttable.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

                  sort_ddmm: function(a,b) {
                    mtch = a[0].match(sorttable.DATE_RE);
                    y = mtch[3]; m = mtch[2]; d = mtch[1];
                    if (m.length == 1) m = '0'+m;
                    if (d.length == 1) d = '0'+d;
                Severity: Major
                Found in app/assets/javascripts/modules/sorttable.js and 1 other location - About 1 day to fix
                app/assets/javascripts/modules/sorttable.js on lines 288..302

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

                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

                  sort_mmdd: function(a,b) {
                    mtch = a[0].match(sorttable.DATE_RE);
                    y = mtch[3]; d = mtch[2]; m = mtch[1];
                    if (m.length == 1) m = '0'+m;
                    if (d.length == 1) d = '0'+d;
                Severity: Major
                Found in app/assets/javascripts/modules/sorttable.js and 1 other location - About 1 day to fix
                app/assets/javascripts/modules/sorttable.js on lines 273..287

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

                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 (this.className.search(/\bsorttable_sorted_reverse\b/) != -1) {
                            // if we're already sorted by this column in reverse, just
                            // re-reverse the table, which is quicker
                            sorttable.reverse(this.sorttable_tbody);
                            this.className = this.className.replace('sorttable_sorted_reverse',
                Severity: Major
                Found in app/assets/javascripts/modules/sorttable.js and 1 other location - About 4 hrs to fix
                app/assets/javascripts/modules/sorttable.js on lines 94..106

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

                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 (this.className.search(/\bsorttable_sorted\b/) != -1) {
                            // if we're already sorted by this column, just
                            // reverse the table, which is quicker
                            sorttable.reverse(this.sorttable_tbody);
                            this.className = this.className.replace('sorttable_sorted',
                Severity: Major
                Found in app/assets/javascripts/modules/sorttable.js and 1 other location - About 4 hrs to fix
                app/assets/javascripts/modules/sorttable.js on lines 107..119

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

                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

                        for(var i = b; i < t; ++i) {
                            if ( comp_func(list[i], list[i+1]) > 0 ) {
                                var q = list[i]; list[i] = list[i+1]; list[i+1] = q;
                                swap = true;
                            }
                Severity: Major
                Found in app/assets/javascripts/modules/sorttable.js and 1 other location - About 3 hrs to fix
                app/assets/javascripts/modules/sorttable.js on lines 324..329

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

                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

                        for(var i = t; i > b; --i) {
                            if ( comp_func(list[i], list[i-1]) < 0 ) {
                                var q = list[i]; list[i] = list[i-1]; list[i-1] = q;
                                swap = true;
                            }
                Severity: Major
                Found in app/assets/javascripts/modules/sorttable.js and 1 other location - About 3 hrs to fix
                app/assets/javascripts/modules/sorttable.js on lines 314..319

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

                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