airbnb/superset

View on GitHub
superset/migrations/versions/2018-07-22_11-59_bebcf3fed1fe_convert_dashboard_v1_positions.py

Summary

Maintainability
F
4 days
Test Coverage

Function convert has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
Open

def convert(positions, level, parent, root):
    if len(positions) == 0:
        return

    if len(positions) == 1 or level >= MAX_RECURSIVE_LEVEL:

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 2018-07-22_11-59_bebcf3fed1fe_convert_dashboard_v1_positions.py has 483 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the

    Function convert_to_layout has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    def convert_to_layout(positions):
        root = get_empty_layout()
    
        convert(positions, 0, root[DASHBOARD_GRID_ID], root)
    
    

    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 upgrade has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

    def upgrade():
        bind = op.get_bind()
        session = db.Session(bind=bind)
    
        dashboards = session.query(Dashboard).all()

    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 scan_dashboard_positions_data has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def scan_dashboard_positions_data(positions):
        positions_by_row_id = {}
        for position in positions:
            row = position["row"]
            position["col"] = min(position["col"], TOTAL_COLUMNS)

    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 has_overlap has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def has_overlap(positions, xAxis=True):
        sorted_positions = (
            sorted(positions[:], key=lambda pos: pos["col"])
            if xAxis
            else sorted(positions[:], key=lambda pos: pos["row"])

    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 deeply nested control flow statements.
    Open

                        while has_wide_columns:
                            col_ids = get_wide_column_ids(item["children"], root)
                            idx = 0
                            # need 2nd loop since same column may reduce multiple times
                            while idx < len(col_ids) and current_width > GRID_COLUMN_COUNT:

      Avoid deeply nested control flow statements.
      Open

                          if len(lower) == 1:
                              chart_holder = get_chart_holder(lower[0])
                              root[chart_holder["id"]] = chart_holder
                              row_container["children"].append(chart_holder["id"])
                          else:

        Avoid deeply nested control flow statements.
        Open

                            if col + size_x <= current_col:
                                lower.append(position)
                                continue
                            elif col >= current_col:
                                upper.append(position)

          There are no issues that match your filters.

          Category
          Status