localstack/localstack

View on GitHub
localstack-core/localstack/utils/json.py

Summary

Maintainability
C
1 day
Test Coverage

Function extract_from_jsonpointer_path has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

def extract_from_jsonpointer_path(target, path: str, delimiter: str = "/", auto_create=False):
    parts = path.strip(delimiter).split(delimiter)
    for part in parts:
        path_part = int(part) if is_number(part) else part
        if isinstance(target, list) and not is_number(path_part):
Severity: Minor
Found in localstack-core/localstack/utils/json.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 default has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def default(self, o):
        import yaml  # leave import here, to avoid breaking our Lambda tests!

        if isinstance(o, HostAndPort):
            return str(o)
Severity: Minor
Found in localstack-core/localstack/utils/json.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 fix_json_keys has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def fix_json_keys(item: Any):
    """make sure the keys of a JSON are strings (not binary type or other)"""
    item_copy = item
    if isinstance(item, list):
        item_copy = []
Severity: Minor
Found in localstack-core/localstack/utils/json.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

Avoid too many return statements within this function.
Open

                return float(o.value)
Severity: Major
Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                return None
    Severity: Major
    Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return super(CustomEncoder, self).default(o)
      Severity: Major
      Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                        return bool(o.value)
        Severity: Major
        Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                          return int(o.value)
          Severity: Major
          Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                            return to_str(o)
            Severity: Major
            Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return str(o.value)
              Severity: Major
              Found in localstack-core/localstack/utils/json.py - About 30 mins to fix

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

                def parse_json_or_yaml(markup: str) -> Any:
                    import yaml  # leave import here, to avoid breaking our Lambda tests!
                
                    try:
                        return json.loads(markup)
                Severity: Minor
                Found in localstack-core/localstack/utils/json.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