netdata/netdata

View on GitHub
src/web/gui/v1/dashboard-react.js

Summary

Maintainability
F
1 wk
Test Coverage

File dashboard-react.js has 453 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable */

/**
 *  after react-dashboard refractor, this file can be renamed to 'dashboard.js'
 *  and it will:
Severity: Minor
Found in src/web/gui/v1/dashboard-react.js - About 6 hrs to fix

    Function object has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

      object: function (name, obj, ignore_regex) {
        if (typeof ignore_regex !== 'undefined' && ignore_regex.test(name)) {
          // console.log('XSS: ignoring "' + name + '"');
          return obj;
        }
    Severity: Minor
    Found in src/web/gui/v1/dashboard-react.js - About 3 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 downloadAll has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      downloadAll: function (host, callback) {
        host = fixHost(host);
    
        let self = this;
    
    
    Severity: Minor
    Found in src/web/gui/v1/dashboard-react.js - About 1 hr to fix

      Function object has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        object: function (name, obj, ignore_regex) {
          if (typeof ignore_regex !== 'undefined' && ignore_regex.test(name)) {
            // console.log('XSS: ignoring "' + name + '"');
            return obj;
          }
      Severity: Minor
      Found in src/web/gui/v1/dashboard-react.js - About 1 hr to fix

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

        NETDATA.registrySearch = function (machine_guid, getFromRegistry, serverDefault, callback) {
          // SEARCH for the URLs of a machine:
          $.ajax({
            url: getFromRegistry("registryServer") + '/api/v1/registry?action=search&machine='
              + getFromRegistry("machineGuid") + '&name=' + encodeURIComponent(getFromRegistry("hostname"))
        Severity: Minor
        Found in src/web/gui/v1/dashboard-react.js - About 1 hr to fix

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

            downloadAll: function (host, callback) {
              host = fixHost(host);
          
              let self = this;
          
          
          Severity: Minor
          Found in src/web/gui/v1/dashboard-react.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 registryDelete has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          NETDATA.registryDelete = function (getFromRegistry, serverDefault, delete_url, callback) {
            // send DELETE to a netdata registry:
            $.ajax({
              url: getFromRegistry("registryServer") + '/api/v1/registry?action=delete&machine='
                + getFromRegistry("machineGuid") + '&name=' + encodeURIComponent(getFromRegistry("hostname"))
          Severity: Minor
          Found in src/web/gui/v1/dashboard-react.js - About 1 hr to fix

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

            NETDATA.xss = {
              enabled: (typeof netdataCheckXSS === 'undefined') ? false : netdataCheckXSS,
              enabled_for_data: (typeof netdataCheckXSS === 'undefined') ? false : netdataCheckXSS,
            
              string: function (s) {
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 2 other locations - About 3 days to fix
            src/web/gui/src/dashboard.js/xss.js on lines 4..84
            src/web/gui/v1/dashboard.js on lines 653..733

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

            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

              white: {
                bootstrap_css: "css/bootstrap-3.3.7.css",
                dashboard_css: "css/dashboard.css?v20180210-1",
                background: "#FFFFFF",
                foreground: "#000000",
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 1 other location - About 6 hrs to fix
            src/web/gui/v1/dashboard-react.js on lines 284..316

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

            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

              slate: {
                bootstrap_css: "css/bootstrap-slate-flat-3.3.7.css?v20161229-1",
                dashboard_css: "css/dashboard.slate.css?v20180210-1",
                background: "#272b30",
                foreground: "#C8C8C8",
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 1 other location - About 6 hrs to fix
            src/web/gui/v1/dashboard-react.js on lines 251..283

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

            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 3 locations. Consider refactoring.
            Open

            const isSlowDevice = function () {
              if (!isSlowDeviceResult) {
                return isSlowDeviceResult;
              }
            
            
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 2 other locations - About 4 hrs to fix
            src/web/gui/src/dashboard.js/utils.js on lines 23..39
            src/web/gui/v1/dashboard.js on lines 107..123

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

            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

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

            NETDATA.chartDefaults = {
              width: '100%',                  // the chart width - can be null
              height: '100%',                 // the chart height - can be null
              min_width: null,                // the chart minimum width - can be null
              library: 'dygraph',             // the graphing library to use
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 2 other locations - About 2 hrs to fix
            src/web/gui/src/dashboard.js/options.js on lines 58..68
            src/web/gui/v1/dashboard.js on lines 1370..1380

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

            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

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

            const fixHost = (host) => {
              while (host.slice(-1) === '/') {
                host = host.substring(0, host.length - 1);
              }
            
            
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 1 other location - About 1 hr to fix
            src/web/gui/v1/dashboard-react.js on lines 553..559

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

            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

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

            NETDATA.fixHost = function (host) {
              while (host.slice(-1) === '/') {
                host = host.substring(0, host.length - 1);
              }
            
            
            Severity: Major
            Found in src/web/gui/v1/dashboard-react.js and 1 other location - About 1 hr to fix
            src/web/gui/v1/dashboard-react.js on lines 468..474

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

            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

                url: getFromRegistry("registryServer") + '/api/v1/registry?action=delete&machine='
                  + getFromRegistry("machineGuid") + '&name=' + encodeURIComponent(getFromRegistry("hostname"))
                  + '&url=' + encodeURIComponent(serverDefault) + '&delete_url=' + encodeURIComponent(delete_url),
            Severity: Minor
            Found in src/web/gui/v1/dashboard-react.js and 1 other location - About 45 mins to fix
            src/web/gui/v1/dashboard-react.js on lines 602..604

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

            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

                url: getFromRegistry("registryServer") + '/api/v1/registry?action=search&machine='
                  + getFromRegistry("machineGuid") + '&name=' + encodeURIComponent(getFromRegistry("hostname"))
                  + '&url=' + encodeURIComponent(serverDefault) + '&for=' + machine_guid,
            Severity: Minor
            Found in src/web/gui/v1/dashboard-react.js and 1 other location - About 45 mins to fix
            src/web/gui/v1/dashboard-react.js on lines 639..641

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

            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