getlackey/lackey-cms

View on GitHub
modules/core/client/js/table.js

Summary

Maintainability
F
6 days
Test Coverage

File table.js has 643 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* jslint node:true, esnext:true, es6:true, browser:true, loopfunc:true*/
/* eslint no-param-reassign:0 no-alert:0 */
'use strict';
/*
    Copyright 2016 Enigma Marketing Services Limited
Severity: Major
Found in modules/core/client/js/table.js - About 1 day to fix

    Function constructor has 178 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        constructor(element) {
            var
                self = this;
            this._search = lackey.select('[data-lky-hook="table.filter"]')[0];
            this._root = element;
    Severity: Major
    Found in modules/core/client/js/table.js - About 7 hrs to fix

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

          constructor(element) {
              var
                  self = this;
              this._search = lackey.select('[data-lky-hook="table.filter"]')[0];
              this._root = element;
      Severity: Minor
      Found in modules/core/client/js/table.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 pageq has 84 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          pageq(options) {
              var self = this,
                  page = this.pageNumber,
                  cloneData = this.data.rows.slice(),
                  pages,
      Severity: Major
      Found in modules/core/client/js/table.js - About 3 hrs to fix

        Table has 24 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Table {
        
            constructor(element) {
                var
                    self = this;
        Severity: Minor
        Found in modules/core/client/js/table.js - About 2 hrs to fix

          Function sortData has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              sortData(field, dir) {
                  var direction = dir || this.sort.dir || 'desc';
          
                  field = field || this.sort.field;
          
          
          Severity: Minor
          Found in modules/core/client/js/table.js - About 1 hr to fix

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

                api() {
                    let self = this;
                    lackey.bind('[data-lky-api]', 'click', (event, hook) => {
                        event.preventDefault();
                        let apiAction = hook.getAttribute('data-lky-api').split(':'),
            Severity: Minor
            Found in modules/core/client/js/table.js - About 1 hr to fix

              Function selectFiller has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  selectFiller(data) {
                      var self = this,
                          i,
                          getOptions = (options, column) => {
                              data.forEach((row) => {
              Severity: Minor
              Found in modules/core/client/js/table.js - About 1 hr to fix

                Function selectFiller has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    selectFiller(data) {
                        var self = this,
                            i,
                            getOptions = (options, column) => {
                                data.forEach((row) => {
                Severity: Minor
                Found in modules/core/client/js/table.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 pageq has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    pageq(options) {
                        var self = this,
                            page = this.pageNumber,
                            cloneData = this.data.rows.slice(),
                            pages,
                Severity: Minor
                Found in modules/core/client/js/table.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 -1;
                Severity: Major
                Found in modules/core/client/js/table.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                                      return 1;
                  Severity: Major
                  Found in modules/core/client/js/table.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                        return -1;
                    Severity: Major
                    Found in modules/core/client/js/table.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                          return 1;
                      Severity: Major
                      Found in modules/core/client/js/table.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                        return 0;
                        Severity: Major
                        Found in modules/core/client/js/table.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                          return 0;
                          Severity: Major
                          Found in modules/core/client/js/table.js - About 30 mins to fix

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

                                        if (a.columns[field].value && a.columns[field].value.date) {
                                            fieldA = a.columns[field].value.date;
                                        } else if (a.columns[field].value) {
                                            fieldA = a.columns[field].value.toLocaleLowerCase();
                                        }
                            Severity: Major
                            Found in modules/core/client/js/table.js and 1 other location - About 3 hrs to fix
                            modules/core/client/js/table.js on lines 542..546

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

                            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 (b.columns[field].value && b.columns[field].value.date) {
                                            fieldB = b.columns[field].value.date;
                                        } else if (b.columns[field].value) {
                                            fieldB = b.columns[field].value.toLocaleLowerCase();
                                        }
                            Severity: Major
                            Found in modules/core/client/js/table.js and 1 other location - About 3 hrs to fix
                            modules/core/client/js/table.js on lines 536..540

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

                            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

                                        createUser: (root) => {
                                            createUser(root, function () {
                                                self.getData().then(() => {
                                                    if (self.sort.field) {
                                                        self.sortData();
                            Severity: Major
                            Found in modules/core/client/js/table.js and 1 other location - About 1 hr to fix
                            modules/core/client/js/table.js on lines 110..118

                            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

                                        createMedia: (root) => {
                                            createMedia(root, function () {
                                                self.getData().then(() => {
                                                    if (self.sort.field) {
                                                        self.sortData();
                            Severity: Major
                            Found in modules/core/client/js/table.js and 1 other location - About 1 hr to fix
                            modules/core/client/js/table.js on lines 135..143

                            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

                                        if (direction === 'desc') {
                                            if (!fieldA) {
                                                return -1;
                                            }
                                            if (!fieldB) {
                            Severity: Major
                            Found in modules/core/client/js/table.js and 1 other location - About 1 hr to fix
                            modules/core/client/js/table.js on lines 561..575

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

                            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

                                        } else {
                                            if (!fieldB) {
                                                return -1;
                                            }
                                            if (!fieldA) {
                            Severity: Major
                            Found in modules/core/client/js/table.js and 1 other location - About 1 hr to fix
                            modules/core/client/js/table.js on lines 547..561

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

                            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