polkadot-js/common

View on GitHub
packages/util/src/is/utf8.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function isUtf8 has a Cognitive Complexity of 127 (exceeds 5 allowed). Consider refactoring.
Open

export function isUtf8 (value?: number[] | Uint8Array | string | null): boolean {
  if (!value) {
    return isString(value);
  }

Severity: Minor
Found in packages/util/src/is/utf8.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 isUtf8 has 99 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function isUtf8 (value?: number[] | Uint8Array | string | null): boolean {
  if (!value) {
    return isString(value);
  }

Severity: Major
Found in packages/util/src/is/utf8.ts - About 3 hrs to fix

    Avoid deeply nested control flow statements.
    Open

            if (u8a[i + 2] < 0x80 || u8a[i + 2] > 0xBF) {
              // *message = "After a first byte of E0, expecting a 3nd byte between 80 and BF.";
              // *faulty_bytes = 3;
              return false;
            }
    Severity: Major
    Found in packages/util/src/is/utf8.ts - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

            if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
              if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
                // *message = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
                // *faulty_bytes = 2;
                return false;
      Severity: Major
      Found in packages/util/src/is/utf8.ts - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                if (u8a[i + 1] < 0xA0 || u8a[i + 1] > 0xBF) {
                  // *message = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
                  // *faulty_bytes = 2;
                  return false;
                }
        Severity: Major
        Found in packages/util/src/is/utf8.ts - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

              } else if (u8a[i] === 0xED) /* ED 80..9F 80..BF */ {
                if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
                  if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x9F) {
                    // *message = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
                    // *faulty_bytes = 2;
          Severity: Major
          Found in packages/util/src/is/utf8.ts - About 45 mins to fix

            Avoid too many return statements within this function.
            Open

                      return false;
            Severity: Major
            Found in packages/util/src/is/utf8.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                        return false;
              Severity: Major
              Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                          return false;
                Severity: Major
                Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return false;
                  Severity: Major
                  Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                      return true;
                    Severity: Major
                    Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return false;
                      Severity: Major
                      Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                  return false;
                        Severity: Major
                        Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return false;
                          Severity: Major
                          Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                      return false;
                            Severity: Major
                            Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                        return false;
                              Severity: Major
                              Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                        return false;
                                Severity: Major
                                Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                            return false;
                                  Severity: Major
                                  Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                              return false;
                                    Severity: Major
                                    Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                              return false;
                                      Severity: Major
                                      Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                  return false;
                                        Severity: Major
                                        Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                  return false;
                                          Severity: Major
                                          Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                      return false;
                                            Severity: Major
                                            Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                      return false;
                                              Severity: Major
                                              Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                          return false;
                                                Severity: Major
                                                Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                          return false;
                                                  Severity: Major
                                                  Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                          return false;
                                                    Severity: Major
                                                    Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                return false;
                                                      Severity: Major
                                                      Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                        Avoid too many return statements within this function.
                                                        Open

                                                                  return false;
                                                        Severity: Major
                                                        Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                          Avoid too many return statements within this function.
                                                          Open

                                                                    return false;
                                                          Severity: Major
                                                          Found in packages/util/src/is/utf8.ts - About 30 mins to fix

                                                            Avoid too many return statements within this function.
                                                            Open

                                                                      return false;
                                                            Severity: Major
                                                            Found in packages/util/src/is/utf8.ts - About 30 mins to fix

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

                                                                  } else if (u8a[i] === 0xF0) /* F0 90..BF 80..BF 80..BF */ {
                                                                    if (i + 3 < len) /* Expect a 2nd, 3rd 3th byte */ {
                                                                      if (u8a[i + 1] < 0x90 || u8a[i + 1] > 0xBF) {
                                                                        // *message = "After a first byte of F0, expecting 2nd byte between 90 and BF.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 2 other locations - About 6 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 147..203
                                                              packages/util/src/is/utf8.ts on lines 173..203

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

                                                              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

                                                                  } else if (u8a[i] >= 0xF1 && u8a[i] <= 0xF3) /* F1..F3 80..BF 80..BF 80..BF */ {
                                                                    if (i + 3 < len) /* Expect a 2nd, 3rd 3th byte */ {
                                                                      if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
                                                                        // *message = "After a first byte of F1, F2, or F3, expecting a 2nd byte between 80 and BF.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 2 other locations - About 6 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 121..203
                                                              packages/util/src/is/utf8.ts on lines 173..203

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

                                                              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

                                                                  } else if (u8a[i] === 0xF4) /* F4 80..8F 80..BF 80..BF */ {
                                                                    if (i + 3 < len) /* Expect a 2nd, 3rd 3th byte */ {
                                                                      if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x8F) {
                                                                        // *message = "After a first byte of F4, expecting 2nd byte between 80 and 8F.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 2 other locations - About 6 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 121..203
                                                              packages/util/src/is/utf8.ts on lines 147..203

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

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

                                                                  } else if (u8a[i] === 0xE0) /* E0 A0..BF 80..BF */ {
                                                                    if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
                                                                      if (u8a[i + 1] < 0xA0 || u8a[i + 1] > 0xBF) {
                                                                        // *message = "After a first byte of E0, expecting a 2nd byte between A0 and BF.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 3 other locations - About 4 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 61..203
                                                              packages/util/src/is/utf8.ts on lines 81..203
                                                              packages/util/src/is/utf8.ts on lines 101..203

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

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

                                                                  } else if (u8a[i] === 0xED) /* ED 80..9F 80..BF */ {
                                                                    if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
                                                                      if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0x9F) {
                                                                        // *message = "After a first byte of ED, expecting 2nd byte between 80 and 9F.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 3 other locations - About 4 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 41..203
                                                              packages/util/src/is/utf8.ts on lines 61..203
                                                              packages/util/src/is/utf8.ts on lines 101..203

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

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

                                                                  } else if (u8a[i] >= 0xE1 && u8a[i] <= 0xEC) /* E1..EC 80..BF 80..BF */ {
                                                                    if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
                                                                      if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
                                                                        // *message = "After a first byte between E1 and EC, expecting the 2nd byte between 80 and BF.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 3 other locations - About 4 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 41..203
                                                              packages/util/src/is/utf8.ts on lines 81..203
                                                              packages/util/src/is/utf8.ts on lines 101..203

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

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

                                                                  } else if (u8a[i] >= 0xEE && u8a[i] <= 0xEF) /* EE..EF 80..BF 80..BF */ {
                                                                    if (i + 2 < len) /* Expect a 2nd and 3rd byte */ {
                                                                      if (u8a[i + 1] < 0x80 || u8a[i + 1] > 0xBF) {
                                                                        // *message = "After a first byte between EE and EF, expecting 2nd byte between 80 and BF.";
                                                                        // *faulty_bytes = 2;
                                                              Severity: Major
                                                              Found in packages/util/src/is/utf8.ts and 3 other locations - About 4 hrs to fix
                                                              packages/util/src/is/utf8.ts on lines 41..203
                                                              packages/util/src/is/utf8.ts on lines 61..203
                                                              packages/util/src/is/utf8.ts on lines 81..203

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

                                                              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