netdata/netdata

View on GitHub
src/web/gui/src/dashboard.js/utils.js

Summary

Maintainability
F
2 wks
Test Coverage

File utils.js has 324 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// *** src/dashboard.js/utils.js

NETDATA.name2id = function (s) {
    return s
        .replace(/ /g, '_')
Severity: Minor
Found in src/web/gui/src/dashboard.js/utils.js - About 3 hrs to fix

    Function seconds4human has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    NETDATA.seconds4human = function (seconds, options) {
        let defaultOptions = {
            now: 'now',
            space: ' ',
            negative_suffix: 'ago',
    Severity: Minor
    Found in src/web/gui/src/dashboard.js/utils.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 seconds4human has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    NETDATA.seconds4human = function (seconds, options) {
        let defaultOptions = {
            now: 'now',
            space: ' ',
            negative_suffix: 'ago',
    Severity: Major
    Found in src/web/gui/src/dashboard.js/utils.js - About 2 hrs to fix

      Function getFixed has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          getFixed: function (min, max) {
              let key = max;
              if (min === max) {
                  if (typeof this.formattersFixed[key] === 'undefined') {
                      this.formattersFixed[key] = {
      Severity: Minor
      Found in src/web/gui/src/dashboard.js/utils.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 getLocaleString has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getLocaleString: function (min, max) {
              let key = max;
              if (min === max) {
                  if (typeof this.formattersFixed[key] === 'undefined') {
                      this.formattersFixed[key] = {
      Severity: Minor
      Found in src/web/gui/src/dashboard.js/utils.js - About 1 hr to fix

        Function dataAttribute has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

        NETDATA.dataAttribute = function (element, attribute, def) {
            let key = 'data-' + attribute.toString();
            if (element.hasAttribute(key)) {
                let data = element.getAttribute(key);
        
        
        Severity: Minor
        Found in src/web/gui/src/dashboard.js/utils.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 getFixed has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            getFixed: function (min, max) {
                let key = max;
                if (min === max) {
                    if (typeof this.formattersFixed[key] === 'undefined') {
                        this.formattersFixed[key] = {
        Severity: Minor
        Found in src/web/gui/src/dashboard.js/utils.js - About 1 hr to fix

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

              getIntlNumberFormat: function (min, max) {
                  let key = max;
                  if (min === max) {
                      if (typeof this.formattersFixed[key] === 'undefined') {
                          this.formattersFixed[key] = new Intl.NumberFormat(undefined, {
          Severity: Minor
          Found in src/web/gui/src/dashboard.js/utils.js - About 1 hr to fix

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

            NETDATA.dataAttributeBoolean = function (element, attribute, def) {
                let value = NETDATA.dataAttribute(element, attribute, def);
            
                if (value === true || value === false) // gmosx: Love this :)
                {
            Severity: Minor
            Found in src/web/gui/src/dashboard.js/utils.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 getIntlNumberFormat has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                getIntlNumberFormat: function (min, max) {
                    let key = max;
                    if (min === max) {
                        if (typeof this.formattersFixed[key] === 'undefined') {
                            this.formattersFixed[key] = new Intl.NumberFormat(undefined, {
            Severity: Minor
            Found in src/web/gui/src/dashboard.js/utils.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 getLocaleString has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                getLocaleString: function (min, max) {
                    let key = max;
                    if (min === max) {
                        if (typeof this.formattersFixed[key] === 'undefined') {
                            this.formattersFixed[key] = {
            Severity: Minor
            Found in src/web/gui/src/dashboard.js/utils.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 def;
            Severity: Major
            Found in src/web/gui/src/dashboard.js/utils.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return JSON.parse(data);
              Severity: Major
              Found in src/web/gui/src/dashboard.js/utils.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return value !== 0;
                Severity: Major
                Found in src/web/gui/src/dashboard.js/utils.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return def;
                  Severity: Major
                  Found in src/web/gui/src/dashboard.js/utils.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return data;
                    Severity: Major
                    Found in src/web/gui/src/dashboard.js/utils.js - About 30 mins to fix

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

                      NETDATA.fastNumberFormat = {
                          formattersFixed: [],
                          formattersZeroBased: [],
                      
                          // this is the fastest and the preferred
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 6 days to fix
                      src/web/gui/v1/dashboard.js on lines 291..492

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

                      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

                      NETDATA.seconds4human = function (seconds, options) {
                          let defaultOptions = {
                              now: 'now',
                              space: ' ',
                              negative_suffix: 'ago',
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 4 days to fix
                      src/web/gui/v1/dashboard.js on lines 143..226

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

                      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.dataAttribute = function (element, attribute, def) {
                          let key = 'data-' + attribute.toString();
                          if (element.hasAttribute(key)) {
                              let data = element.getAttribute(key);
                      
                      
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 6 hrs to fix
                      src/web/gui/v1/dashboard.js on lines 231..259

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

                      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

                      NETDATA.dataAttributeBoolean = function (element, attribute, def) {
                          let value = NETDATA.dataAttribute(element, attribute, def);
                      
                          if (value === true || value === false) // gmosx: Love this :)
                          {
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 6 hrs to fix
                      src/web/gui/v1/dashboard.js on lines 261..286

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

                      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._scriptSource = function () {
                          let script = null;
                      
                          if (typeof document.currentScript !== 'undefined') {
                              script = document.currentScript;
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 5 hrs to fix
                      src/web/gui/v1/dashboard.js on lines 499..516

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

                      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

                      NETDATA.guid = function () {
                          function s4() {
                              return Math.floor((1 + Math.random()) * 0x10000)
                                  .toString(16)
                                  .substring(1);
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 5 hrs to fix
                      src/web/gui/v1/dashboard.js on lines 125..133

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

                      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/src/dashboard.js/utils.js and 2 other locations - About 4 hrs to fix
                      src/web/gui/v1/dashboard-react.js on lines 24..40
                      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 2 locations. Consider refactoring.
                      Open

                      NETDATA.name2id = function (s) {
                          return s
                              .replace(/ /g, '_')
                              .replace(/:/g, '_')
                              .replace(/\(/g, '_')
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 2 hrs to fix
                      src/web/gui/v1/dashboard.js on lines 87..95

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

                      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.zeropad = function (x) {
                          if (x > -10 && x < 10) {
                              return '0' + x.toString();
                          } else {
                              return x.toString();
                      Severity: Major
                      Found in src/web/gui/src/dashboard.js/utils.js and 1 other location - About 1 hr to fix
                      src/web/gui/v1/dashboard.js on lines 135..141

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

                      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