markusressel/telegram-click

View on GitHub

Showing 17 of 17 total issues

Function parse_command_args has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
Open

def parse_command_args(arguments: str or None, expected_args: List[Argument]) -> dict:
    """
    Parses the given argument text
    :param arguments: the argument text
    :param expected_args: a list of expected arguments
Severity: Minor
Found in telegram_click/parser.py - About 1 day 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 split_into_tokens has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

def split_into_tokens(text: str) -> List[str]:
    """
    This is a simple shell-style tokenizer for command arguments.
    The goal was to emulate posix behaviour, while maintaining quotation characters,
    to be able to differentiate quoted and non-quoted tokens even after tokenization.
Severity: Minor
Found in telegram_click/parser.py - About 4 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 _create_callback_wrapper has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

def _create_callback_wrapper(func: callable, help_message: str,
                             arguments: [Argument],
                             permissions: Permission,
                             command_target: bytes,
                             error_handlers: List[ErrorHandler]) -> callable:
Severity: Minor
Found in telegram_click/decorator.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 __init__ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def __init__(self, name: str or [str], description: str, example: str, type: type = str, converter: callable = None,
                 flag: bool = False, optional: bool = False, default: any = None, validator: callable = None):
        """
        Creates a command argument object
        :param name: the name (or names) of the argument
Severity: Minor
Found in telegram_click/argument.py - 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 starts_with_naming_prefix has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def starts_with_naming_prefix(arg: str, abbreviated: bool or None = None) -> bool:
    """
    Checks if the given string starts
    :param arg: the arg to check
    :param abbreviated: whether to look for a prefix used for abbreviated argument keys
Severity: Minor
Found in telegram_click/parser.py - 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 9 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def __init__(self, name: str or [str], description: str, example: str, type: type = str, converter: callable = None,
Severity: Major
Found in telegram_click/argument.py - About 1 hr to fix

    Function command has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def command(name: str or [str], description: str = None,
    Severity: Major
    Found in telegram_click/decorator.py - About 50 mins to fix

      Function __init__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, name: str, description: str, allowed_values: [any], type: type = str, converter: callable = None,
      Severity: Major
      Found in telegram_click/argument.py - About 50 mins to fix

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

        def find_duplicates(l: list) -> []:
            """
            Finds duplicate entries in the given list
            :param l: the list to check
            :return: map of (value -> list of indexes)
        Severity: Minor
        Found in telegram_click/util.py - 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 _create_callback_wrapper has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def _create_callback_wrapper(func: callable, help_message: str,
        Severity: Minor
        Found in telegram_click/decorator.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if len(current_token) > 0:
                                  tokens.append(current_token)
                              current_token = ""
          Severity: Major
          Found in telegram_click/parser.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                for name in arg.names:
                                    arg_name_map.pop(name)
                            continue
            Severity: Major
            Found in telegram_click/parser.py - About 45 mins to fix

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

                  def parse_arg_value(self, arg: str) -> any:
                      """
                      Tries to parse the given value
                      :param arg: the string value
                      :return: the parsed value
              Severity: Minor
              Found in telegram_click/argument.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 wrapper
              Severity: Major
              Found in telegram_click/decorator.py - About 30 mins to fix

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

                def is_quoted(text: str or any) -> bool:
                    """
                    Checks if the given text is quoted.
                    Note: This method expects a stripped text!
                          When passing something other than a str, the result will always be False.
                Severity: Minor
                Found in telegram_click/parser.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

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

                def generate_synopsis(names: [str], args: List[Argument]) -> str:
                    """
                    Generates the synopsis for a command
                    :param names: command names
                    :param args: arguments
                Severity: Minor
                Found in telegram_click/help.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

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

                def check_optional_argument_after_other(command_name: str, arguments: List[Argument]):
                    """
                    Checks the order of arguments to make sure no required argument is defined after an optional one
                    :param command_name: command name the arguments belong to
                    :param arguments: arguments to check
                Severity: Minor
                Found in telegram_click/decorator.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