i18next/i18next

View on GitHub
src/i18next.js

Summary

Maintainability
F
4 days
Test Coverage

Function init has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

  init(options = {}, callback) {
    this.isInitializing = true;
    if (typeof options === 'function') {
      callback = options;
      options = {};
Severity: Minor
Found in src/i18next.js - About 7 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

File i18next.js has 522 lines of code (exceeds 300 allowed). Consider refactoring.
Open

import baseLogger from './logger.js';
import EventEmitter from './EventEmitter.js';
import ResourceStore from './ResourceStore.js';
import Translator from './Translator.js';
import LanguageUtils from './LanguageUtils.js';
Severity: Major
Found in src/i18next.js - About 7 hrs to fix

    Function changeLanguage has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

      changeLanguage(lng, callback) {
        this.isLanguageChangingTo = lng;
        const deferred = defer();
        this.emit('languageChanging', lng);
    
    
    Severity: Minor
    Found in src/i18next.js - About 3 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 init has 135 lines of code (exceeds 70 allowed). Consider refactoring.
    Open

      init(options = {}, callback) {
        this.isInitializing = true;
        if (typeof options === 'function') {
          callback = options;
          options = {};
    Severity: Major
    Found in src/i18next.js - About 3 hrs to fix

      Function loadResources has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        loadResources(language, callback = noop) {
          let usedCallback = callback;
          const usedLng = typeof language === 'string' ? language : this.language;
          if (typeof language === 'function') usedCallback = language;
      
      
      Severity: Minor
      Found in src/i18next.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 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 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 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 dir has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        dir(lng) {
          if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
          if (!lng) return 'rtl';
      
          const rtlLngs = [
      Severity: Minor
      Found in src/i18next.js - About 35 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Avoid too many return statements within this function.
      Open

          if (!this.services.backendConnector.backend || (this.options.resources && !this.options.partialBundledLanguages)) return true;
      Severity: Major
      Found in src/i18next.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

            return false;
        Severity: Major
        Found in src/i18next.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              if (this.hasResourceBundle(lng, ns)) return true;
          Severity: Major
          Found in src/i18next.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
            Severity: Major
            Found in src/i18next.js - About 30 mins to fix

              There are no issues that match your filters.

              Category
              Status