Morphy2k/broadcast-notification-system

View on GitHub
public/dashboard/js/main.js

Summary

Maintainability
F
4 days
Test Coverage

File main.js has 487 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-env browser, commonjs */
'use strict';

const $ = require('../../../node_modules/jquery/dist/jquery.slim.min.js');
const IO = require('../../../node_modules/socket.io-client/dist/socket.io.slim.js');
Severity: Minor
Found in public/dashboard/js/main.js - About 7 hrs to fix

    Function response has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
    Open

      response(type, err, data) {
        if (err) return popup('ERROR!');
    
        if (type === 'response') {
          if (data.type === 'set') {
    Severity: Minor
    Found in public/dashboard/js/main.js - About 5 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 constructor has 115 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      constructor() {
    
        const sendEventListeners = [
    
          // API buttons
    Severity: Major
    Found in public/dashboard/js/main.js - About 4 hrs to fix

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

        constructor() {
      
          super();
          this.connect();
      
      
      Severity: Major
      Found in public/dashboard/js/main.js - About 2 hrs to fix

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

          update(data) {
        
            if (data.remove) return $(`#${data.remove}`).remove();
        
            for (let el of data) {
        Severity: Minor
        Found in public/dashboard/js/main.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 response has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          response(type, err, data) {
            if (err) return popup('ERROR!');
        
            if (type === 'response') {
              if (data.type === 'set') {
        Severity: Minor
        Found in public/dashboard/js/main.js - About 1 hr to fix

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

            addEventListener(obj) {
          
              const resolve = path => {
          
                let obj = window;
          Severity: Minor
          Found in public/dashboard/js/main.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 addEventListener has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            addEventListener(obj) {
          
              const resolve = path => {
          
                let obj = window;
          Severity: Minor
          Found in public/dashboard/js/main.js - About 1 hr to fix

            Function update has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              update(data) {
            
                if (data.remove) return $(`#${data.remove}`).remove();
            
                for (let el of data) {
            Severity: Minor
            Found in public/dashboard/js/main.js - About 1 hr to fix

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

                select(type) {
              
                  let types = this.filter.types,
                    id;
              
              
              Severity: Minor
              Found in public/dashboard/js/main.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 constructor has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                constructor() {
              
                  this.filter = {
                    all: '#feed-all',
                    types: [
              Severity: Minor
              Found in public/dashboard/js/main.js - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                            if (i === props.length) {
                              obj[prop] = value;
                            } else {
                              obj = obj[prop];
                              i = i + 1;
                Severity: Major
                Found in public/dashboard/js/main.js - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                              if (el === selected) {
                  
                                $('#template > div > select').append(
                                  `<option value="${el}" selected>${el}</option>`
                                );
                  Severity: Major
                  Found in public/dashboard/js/main.js - About 45 mins to fix

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

                      compare(data) {
                    
                        if (data.remove) return this.update(data);
                    
                        let arr = [],
                    Severity: Minor
                    Found in public/dashboard/js/main.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 request has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      request(type, obj) {
                    
                        if (socket.connected) {
                          if (obj.value === true || obj.value === false) {
                            if (obj.value) {
                    Severity: Minor
                    Found in public/dashboard/js/main.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

                    Definition for rule 'semi-style' was not found
                    Open

                    'use strict';
                    Severity: Minor
                    Found in public/dashboard/js/main.js by eslint

                    For more information visit Source: http://eslint.org/docs/rules/

                    There are no issues that match your filters.

                    Category
                    Status