i18next/i18next

View on GitHub

Showing 101 of 101 total issues

Function parseFormatStr has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function parseFormatStr(formatStr) {
  let formatName = formatStr.toLowerCase().trim();
  let formatOptions = {};
  if (formatStr.indexOf('(') > -1) {
    const p = formatStr.split('(');
Severity: Minor
Found in src/Formatter.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 interpolate has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  interpolate(str, data, lng, options) {
    let match;
    let value;
    let replaces;

Severity: Minor
Found in src/Interpolator.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 extractFromKey has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  extractFromKey(key, options) {
    let nsSeparator =
      options.nsSeparator !== undefined ? options.nsSeparator : this.options.nsSeparator;
    if (nsSeparator === undefined) nsSeparator = ':';

Severity: Minor
Found in src/Translator.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 resolve has 82 lines of code (exceeds 70 allowed). Consider refactoring.
Open

  resolve(keys, options = {}) {
    let found;
    let usedKey; // plain key
    let exactUsedKey; // key with context / plural
    let usedLng;
Severity: Major
Found in src/Translator.js - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

        } else if (
          handleAsObjectInI18nFormat &&
          typeof joinArrays === 'string' &&
          resType === '[object Array]'
        ) {
    Severity: Critical
    Found in src/Translator.js - About 1 hr to fix

      Function interpolate has 78 lines of code (exceeds 70 allowed). Consider refactoring.
      Open

        interpolate(str, data, lng, options) {
          let match;
          let value;
          let replaces;
      
      
      Severity: Major
      Found in src/Interpolator.js - About 1 hr to fix

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

          use(module) {
            if (!module) throw new Error('You are passing an undefined module! Please check the object you are passing to i18next.use()')
            if (!module.type) throw new Error('You are passing a wrong module! Please check the object you are passing to i18next.use()')
        
            if (module.type === 'backend') {
        Severity: Minor
        Found in src/i18next.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 getResource has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          getResource(lng, ns, key, options = {}) {
            const keySeparator =
              options.keySeparator !== undefined ? options.keySeparator : this.options.keySeparator;
        
            const ignoreJSONStructure =
        Severity: Minor
        Found in src/ResourceStore.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 getFallbackCodes has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          getFallbackCodes(fallbacks, code) {
            if (!fallbacks) return [];
            if (typeof fallbacks === 'function') fallbacks = fallbacks(code);
            if (typeof fallbacks === 'string') fallbacks = [fallbacks];
            if (Object.prototype.toString.apply(fallbacks) === '[object Array]') return fallbacks;
        Severity: Minor
        Found in src/LanguageUtils.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 10 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

          10: function(n) {return Number(n==1 ? 0 : n==2 ? 1 : n<7 ? 2 : n<11 ? 3 : 4) ;},
        Severity: Minor
        Found in src/PluralResolver.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 get has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        export function get() {
          return {
            debug: false,
            initImmediate: true,
        
        
        Severity: Minor
        Found in src/defaults.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

        Consider simplifying this complex logical expression.
        Open

              if (this.formats[formatName]) {
                let formatted = mem;
                try {
                  // options passed explicit for that formatted value
                  const valOptions =
        Severity: Critical
        Found in src/Formatter.js - About 1 hr to fix

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

          export function looksLikeObjectPath(key, nsSeparator, keySeparator) {
            nsSeparator = nsSeparator || '';
            keySeparator = keySeparator || '';
            const possibleChars = chars.filter(
              (c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0,
          Severity: Minor
          Found in src/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 11 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            11: function(n) {return Number((n==1 || n==11) ? 0 : (n==2 || n==12) ? 1 : (n > 2 && n < 20) ? 2 : 3);},
          Severity: Minor
          Found in src/PluralResolver.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 19 has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            19: function(n) {return Number(n==1 ? 0 : n==0 || ( n%100>1 && n%100<11) ? 1 : (n%100>10 && n%100<20 ) ? 2 : 3);},
          Severity: Minor
          Found in src/PluralResolver.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 setResolvedLanguage has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            setResolvedLanguage(l) {
              if (!l || !this.languages) return;
              if (['cimode', 'dev'].indexOf(l) > -1) return;
              for (let li = 0; li < this.languages.length; li++) {
                const lngInLngs = this.languages[li];
          Severity: Minor
          Found in src/i18next.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 format has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            format(value, format, lng, options) {
              const formats = format.split(this.formatSeparator);
          
              const result = formats.reduce((mem, f) => {
                const { formatName, formatOptions } = parseFormatStr(f);
          Severity: Minor
          Found in src/Formatter.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 getFixedT has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            getFixedT(lng, ns, keyPrefix) {
              const fixedT = (key, opts, ...rest) => {
                let options;
                if (typeof opts !== 'object') {
                  options = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
          Severity: Minor
          Found in src/i18next.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 handle has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            handle(processors, value, key, options, translator) {
          Severity: Minor
          Found in src/postProcessor.js - About 35 mins to fix

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

              saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}) {
                if (
                  this.services.utils &&
                  this.services.utils.hasLoadedNamespace &&
                  !this.services.utils.hasLoadedNamespace(namespace)
            Severity: Minor
            Found in src/BackendConnector.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

            Severity
            Category
            Status
            Source
            Language