zk/src/main/resources/web/js/zk/fmt/numfmt.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function format has a Cognitive Complexity of 101 (exceeds 5 allowed). Consider refactoring.
Open

    format(fmt: string, val: string, rounding: number, localizedSymbols?: zk.LocalizedSymbols): string {
        if (val == null) return '';
        if (!fmt) return val + '';
        
        if (fmt.startsWith('locale:')) {
Severity: Minor
Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 2 days 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 unformat has a Cognitive Complexity of 60 (exceeds 5 allowed). Consider refactoring.
Open

    unformat(fmt: string, val: string, ignoreLocale: boolean, localizedSymbols?: zk.LocalizedSymbols): {raw: string; divscale: number} {
        if (!val) return {raw: val, divscale: 0};

        // localized symbols
        localizedSymbols = localizedSymbols || {
Severity: Minor
Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - 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 numfmt.ts has 427 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* numfmt.ts

    Purpose:
        
    Description:
Severity: Minor
Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 6 hrs to fix

    Function format has 146 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        format(fmt: string, val: string, rounding: number, localizedSymbols?: zk.LocalizedSymbols): string {
            if (val == null) return '';
            if (!fmt) return val + '';
            
            if (fmt.startsWith('locale:')) {
    Severity: Major
    Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 5 hrs to fix

      Function isRoundingRequired has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          isRoundingRequired(val: string | number, fmt: string, localizedSymbols?: zk.LocalizedSymbols): boolean {
              if (!fmt || val == null || val == '')
                  return false;
              
              var useMinsuFmt;
      Severity: Minor
      Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - 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 _escapeQuote has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
      Open

          _escapeQuote(fmt: string, localizedSymbols: zk.LocalizedSymbols): Efmt {
              //note we do NOT support mixing of quoted and unquoted percent
              var cc, q = -2, shift = 0, ret = '', jdot = -1, purejdot = -1, pure = '', prej = -1,
                  validPercent = fmt ? !new RegExp('(\'[' + localizedSymbols.PERCENT + '|' + localizedSymbols.PER_MILL + ']+\')', 'g').test(fmt) : true;
                  //note we do NOT support mixing of quoted and unquoted percent|permill
      Severity: Minor
      Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - 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 unformat has 72 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          unformat(fmt: string, val: string, ignoreLocale: boolean, localizedSymbols?: zk.LocalizedSymbols): {raw: string; divscale: number} {
              if (!val) return {raw: val, divscale: 0};
      
              // localized symbols
              localizedSymbols = localizedSymbols || {
      Severity: Major
      Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 2 hrs to fix

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

            rounding(valStr: string, ri: number, rounding: number, minus: boolean): string {
                switch (rounding) {
                    case 0: //UP
                        valStr = up(valStr, ri);
                        break;
        Severity: Minor
        Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - 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

        Consider simplifying this complex logical expression.
        Open

                    if (!ignore)
                        ignore = (cc < '0' || cc > '9')
                        && cc != zkDecimal && cc != zkMinus && cc != '+'
                        && (zUtl.isChar(cc, {whitespace: 1}) || cc == zkGrouping
                            || cc == ')' || (fmt && fmt.indexOf(cc) >= 0));
        Severity: Critical
        Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 2 hrs to fix

          Function isRoundingRequired has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              isRoundingRequired(val: string | number, fmt: string, localizedSymbols?: zk.LocalizedSymbols): boolean {
                  if (!fmt || val == null || val == '')
                      return false;
                  
                  var useMinsuFmt;
          Severity: Minor
          Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 1 hr to fix

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

            function up(valStr: string, ri: number): string {
                var k = 1, val = '';
                for (var j = ri; k && --j >= 0;) {
                    var ch = valStr.charAt(j);
                    if (k == 1) {
            Severity: Minor
            Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - 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 rounding has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                rounding(valStr: string, ri: number, rounding: number, minus: boolean): string {
                    switch (rounding) {
                        case 0: //UP
                            valStr = up(valStr, ri);
                            break;
            Severity: Minor
            Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 1 hr to fix

              Function _escapeQuote has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  _escapeQuote(fmt: string, localizedSymbols: zk.LocalizedSymbols): Efmt {
                      //note we do NOT support mixing of quoted and unquoted percent
                      var cc, q = -2, shift = 0, ret = '', jdot = -1, purejdot = -1, pure = '', prej = -1,
                          validPercent = fmt ? !new RegExp('(\'[' + localizedSymbols.PERCENT + '|' + localizedSymbols.PER_MILL + ']+\')', 'g').test(fmt) : true;
                          //note we do NOT support mixing of quoted and unquoted percent|permill
              Severity: Minor
              Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 1 hr to fix

                Consider simplifying this complex logical expression.
                Open

                                if (prej < 0
                                    && (cc == '#' || cc == '0' || cc == '.' || cc == '-' || cc == ',' || cc == 'E'))
                                    prej = ret.length;
                Severity: Major
                Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 1 hr to fix

                  Function _removePrefixSharps has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      _removePrefixSharps(val: string, localizedSymbols: zk.LocalizedSymbols): string {
                          var ret = '',
                              sharp = true;
                          for (var len = val.length, j = 0; j < len; ++j) {
                              var cc = val.charAt(j);
                  Severity: Minor
                  Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 55 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 deeply nested control flow statements.
                  Open

                                      if (jdot < 0)
                                          jdot = ret.length;
                  Severity: Major
                  Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if (cc == '.' && j > ++k)
                                        sb = sb.substring(0, k) + sb.substring(j);
                    Severity: Major
                    Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                  } else if (cc == '.') { //.xxx or . // B50-3297864
                                      break;
                                  }
                      Severity: Major
                      Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                            if (purejdot < 0)
                                                purejdot = pure.length;
                        Severity: Major
                        Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - About 45 mins to fix

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

                              setScale(val: zk.BigDecimal, scale: number, rounding: number): zk.BigDecimal { //bug #3089502: setScale in decimalbox not working
                                  if (scale === undefined || scale < 0)
                                      return val;
                                  var valStr = val.$toString(),
                                      indVal = valStr.indexOf('.'),
                          Severity: Minor
                          Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts - 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

                                      } case 5: {//HALF_DOWN
                                          const r = compareHalf(valStr, ri);
                                          valStr = r != null && r > 0 ? up(valStr, ri) : down(valStr, ri);
                                          break;
                                      } case 6: //HALF_EVEN
                          Severity: Major
                          Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts and 1 other location - About 1 hr to fix
                          zk/src/main/resources/web/js/zk/fmt/numfmt.ts on lines 156..160

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

                          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

                                      case 4: {//HALF_UP
                                          const r = compareHalf(valStr, ri);
                                          valStr = r != null && r < 0 ? down(valStr, ri) : up(valStr, ri);
                                          break;
                                      } case 5: {//HALF_DOWN
                          Severity: Major
                          Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts and 1 other location - About 1 hr to fix
                          zk/src/main/resources/web/js/zk/fmt/numfmt.ts on lines 160..164

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

                          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

                          var _defaultSymbols = {
                              GROUPING: zk.GROUPING,
                              DECIMAL: zk.DECIMAL,
                              PERCENT: zk.PERCENT,
                              PER_MILL: zk.PER_MILL,
                          Severity: Minor
                          Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts and 1 other location - About 35 mins to fix
                          zk/src/main/resources/web/js/zk/fmt/numfmt.ts on lines 412..418

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

                          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

                                  localizedSymbols = localizedSymbols || {
                                          GROUPING: zk.GROUPING,
                                          DECIMAL: zk.DECIMAL,
                                          PERCENT: zk.PERCENT,
                                          PER_MILL: zk.PER_MILL,
                          Severity: Minor
                          Found in zk/src/main/resources/web/js/zk/fmt/numfmt.ts and 1 other location - About 35 mins to fix
                          zk/src/main/resources/web/js/zk/fmt/numfmt.ts on lines 15..21

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

                          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