long-file
A file longer than its project allows.
- Group
- Text
- Runs
- Optional: run it with
ur lint --rule long-file - Level
- warning
- Reads
- Every file
- Fix
- None: where to split a file is the author's choice
Why
The file has more lines than max-lines in the [lint.long-file] table allows, 1500 unless the table says. A long file is hard to read whole and to change safely, and an agent that edits it reads far more than the change needs. Split it into files that each hold one concern. The rule reads every text file a search finds, whatever its language; generated and data files a project keeps whole are left out with exclude globs in the same table, not ur-allow comments. The rule runs where [lint.long-file] turns it on.
The fix, as Ur suggests it: split the file into files that each hold one concern, or leave out generated data with exclude in [lint.long-file].
For agents
Keep each file within its project's line limit, and split a file that grows past it into files that each hold one concern.
Example
.ur/ur.toml[lint.long-file]
max-lines = 20
app/orders.pyfrom decimal import Decimal
def subtotal(items):
return sum(item.price * item.quantity for item in items)
def shipping(order):
if order.country == "US":
return Decimal("5.00")
return Decimal("15.00")
def tax(order):
return subtotal(order.items) * order.tax_rate
def total(order):
return subtotal(order.items) + shipping(order) + tax(order)
def refund(order, item):
order.items.remove(item)
return item.price * item.quantity
$ ur lint --rule long-file
warning[long-file]: 24 lines, more than the 20 the project allows
--> ./app/orders.py:1:1 file of 24 lines
= hint: split the file into files that each hold one concern, or leave out generated data with `exclude` in `[lint.long-file]`
0 clone classes and 1 long file in 1 file