i18next/i18next

View on GitHub

Showing 71 of 71 total issues

Function getResource has a Cognitive Complexity of 16 (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 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 interpolate has 95 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 2 hrs to fix

    Function resolve has 93 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

      Function getLastOfPath has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      function getLastOfPath(object, path, Empty) {
        function cleanKey(key) {
          return key && key.indexOf('###') > -1 ? key.replace(lastOfPathSeparatorRegExp, '.') : key;
        }
      
      
      Severity: Minor
      Found in src/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 getSuffixRetroCompatible has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

        getSuffixRetroCompatible(rule, count) {
          const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
          let suffix = rule.numbers[idx];
      
          // special treatment for lngs only having singular and plural
      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 init has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        init(options = {}) {
          if (!options.interpolation) options.interpolation = { escapeValue: true };
      
          const iOpts = options.interpolation;
      
      
      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 read has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

        read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
          if (!lng.length) return callback(null, {}); // noting to load
      
          // Limit parallelism of calls to backend
          // This is needed to prevent trying to open thousands of
      Severity: Minor
      Found in src/BackendConnector.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 getFixedT has a Cognitive Complexity of 13 (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 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 hasLoadedNamespace has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        hasLoadedNamespace(ns, options = {}) {
          if (!this.isInitialized) {
            this.logger.warn('hasLoadedNamespace: i18next was not initialized', this.languages);
            return false;
          }
      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 parseFormatStr has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      function parseFormatStr(formatStr) {
        let formatName = formatStr.toLowerCase().trim();
        const 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 12 (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 extendTranslation has 75 lines of code (exceeds 70 allowed). Consider refactoring.
      Open

        extendTranslation(res, key, options, resolved, lastKey) {
          if (this.i18nFormat && this.i18nFormat.parse) {
            res = this.i18nFormat.parse(
              res,
              { ...this.options.interpolation.defaultVariables, ...options },
      Severity: Major
      Found in src/Translator.js - About 1 hr to fix

        Function use has a Cognitive Complexity of 10 (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 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 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

        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

        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

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

                    if (r && typeof r.then === 'function') {
                      // promise
                      r.then((data) => clb(null, data)).catch(clb);
                    } else {
                      // sync
          Severity: Minor
          Found in src/BackendConnector.js and 1 other location - About 50 mins to fix
          src/BackendConnector.js on lines 175..181

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

          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

                  if (r && typeof r.then === 'function') {
                    // promise
                    r.then((data) => resolver(null, data)).catch(resolver);
                  } else {
                    // sync
          Severity: Minor
          Found in src/BackendConnector.js and 1 other location - About 50 mins to fix
          src/BackendConnector.js on lines 267..273

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

          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

          Severity
          Category
          Status
          Source
          Language