danhper/python-i18n

View on GitHub

Showing 8 of 8 total issues

Function pluralize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

def pluralize(key, translation, count):
    return_value = key
    try:
        if type(translation) != dict:
            return_value = translation
Severity: Minor
Found in i18n/translator.py - 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 t has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def t(key, **kwargs):
    locale = kwargs.pop('locale', config.get('locale'))
    if translations.has(key, locale):
        return translate(key, locale=locale, **kwargs)
    else:
Severity: Minor
Found in i18n/translator.py - 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

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

def load_translation_dic(dic, namespace, locale):
    if namespace:
        namespace += config.get('namespace_delimiter')
    for key, value in dic.items():
        if type(value) == dict and len(set(PLURALS).intersection(value)) < 2:
Severity: Minor
Found in i18n/resource_loader.py - 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

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

def search_translation(key, locale=config.get('locale')):
    splitted_key = key.split(config.get('namespace_delimiter'))
    if not splitted_key:
        return
    namespace = splitted_key[:-1]
Severity: Minor
Found in i18n/resource_loader.py - 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

            return translation['many']
Severity: Major
Found in i18n/translator.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                return return_value
    Severity: Major
    Found in i18n/translator.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return key
      Severity: Major
      Found in i18n/translator.py - About 30 mins to fix

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

        def load_directory(directory, locale=config.get('locale')):
            for f in os.listdir(directory):
                path = os.path.join(directory, f)
                if os.path.isfile(path) and path.endswith(config.get('file_format')):
                    if '{locale}' in config.get('filename_format') and not locale in f:
        Severity: Minor
        Found in i18n/resource_loader.py - 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

        Severity
        Category
        Status
        Source
        Language