deep-nesting

A line indented deeper than its project allows.

Group
Text
Runs
Optional: run it with ur lint --rule deep-nesting
Level
warning
Reads
Every file
Fix
None: how to restructure the code is the author's choice

Why

The line is indented more levels than max-depth in the [lint.deep-nesting] table allows, 8 unless the table says, counting a level for each tab and for each four spaces, as Straitjacket counts them. Code nested that deep is hard to follow: return early, or move the inner part into a function of its own. The rule reads every text file, whatever its language, reports each run of deep lines once, and runs where [lint.deep-nesting] turns it on.

The fix, as Ur suggests it: return early, or move the nested part into a function of its own.

For agents

Keep code within its project's nesting limit: return early, or move a deeply nested part into a function of its own.

Example

.ur/ur.toml
[lint.deep-nesting]
max-depth = 3
app/stock.py
def reserve(warehouses, order):
    for line in order.lines:
        for warehouse in warehouses:
            if warehouse.region == order.region:
                stock = warehouse.stock.get(line.sku, 0)
                if stock >= line.quantity:
                    warehouse.stock[line.sku] = stock - line.quantity
                    line.warehouse = warehouse.name
                    break
    return order
What Ur prints
$ ur lint --rule deep-nesting
warning[deep-nesting]: indented 4 levels deep, more than the 3 the project allows
  --> ./app/stock.py:5:1 4 levels
  = hint: return early, or move the nested part into a function of its own
0 clone classes and 1 text finding in 1 file

Try it in the playground →