ActivityWatch/aw-core

View on GitHub
aw_query/query2.py

Summary

Maintainability
D
1 day
Test Coverage

File query2.py has 343 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
from typing import Union, List, Dict, Sequence, Callable, Type, Any, Tuple
from datetime import datetime

from aw_core.models import Event
Severity: Minor
Found in aw_query/query2.py - About 4 hrs to fix

    Function check has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def check(string: str):
            i = 0
            # Find opening bracket
            found = False
            for char in string:
    Severity: Minor
    Found in aw_query/query2.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 check has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def check(string: str):
            if string[0] != "{":
                return None, string
            # Find closing bracket
            i = 1
    Severity: Minor
    Found in aw_query/query2.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 check has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def check(string: str):
            if string[0] != "[":
                return None, string
            # Find closing bracket
            i = 1
    Severity: Minor
    Found in aw_query/query2.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

    Consider simplifying this complex logical expression.
    Open

                if char == "'" and prev_char != "\\" and not double_quote:
                    single_quote = not single_quote
                elif char == '"' and prev_char != "\\" and not single_quote:
                    double_quote = not double_quote
                elif single_quote or double_quote:
    Severity: Major
    Found in aw_query/query2.py - About 1 hr to fix

      Function parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse(string: str, namespace: dict) -> QToken:
              entries_str = string[1:-1]
              d: Dict[str, QToken] = {}
              while len(entries_str) > 0:
                  entries_str = entries_str.strip()
      Severity: Minor
      Found in aw_query/query2.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

      Consider simplifying this complex logical expression.
      Open

                  if char == "'" and prev_char != "\\" and not double_quote:
                      single_quote = not single_quote
                  elif char == '"' and prev_char != "\\" and not single_quote:
                      double_quote = not double_quote
                  elif double_quote or single_quote:
      Severity: Major
      Found in aw_query/query2.py - About 40 mins to fix

        Consider simplifying this complex logical expression.
        Open

                    if char == "'" and prev_char != "\\" and not double_quote:
                        single_quote = not single_quote
                    elif char == '"' and prev_char != "\\" and not single_quote:
                        double_quote = not double_quote
                    elif single_quote or double_quote:
        Severity: Major
        Found in aw_query/query2.py - About 40 mins to fix

          Function query has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def query(
          Severity: Minor
          Found in aw_query/query2.py - About 35 mins to fix

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

                def check(string: str):
                    token = ""
                    quotes_type = string[0]
                    if quotes_type != '"' and quotes_type != "'":
                        return token, string
            Severity: Minor
            Found in aw_query/query2.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 check has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def check(string: str):
                    token = ""
                    for i, char in enumerate(string):
                        if char.isalpha() or char == "_":
                            token += char
            Severity: Minor
            Found in aw_query/query2.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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def parse(string: str, namespace: dict) -> QToken:
                    entries_str = string[1:-1]
                    l: List[QToken] = []
                    while len(entries_str) > 0:
                        entries_str = entries_str.strip()
            Severity: Minor
            Found in aw_query/query2.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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                def parse(string: str, namespace: dict) -> QToken:
                    arg_start = 0
                    arg_end = len(string) - 1
                    # Find opening bracket
                    for char in string:
            Severity: Minor
            Found in aw_query/query2.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 _parse_token has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            def _parse_token(string: str, namespace: dict) -> Tuple[Tuple[Any, str], str]:
                # TODO: The whole parsing thing is shoddily written, needs a rewrite from ground-up
                if not isinstance(string, str):
                    raise QueryParseException(
                        "Reached unreachable, cannot parse something that isn't a string"
            Severity: Minor
            Found in aw_query/query2.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

            There are no issues that match your filters.

            Category
            Status