Skip to content
Kavachकवच

Small Files

Also known as: file length limit lines maintainability large codebase split deprecated refactor

● Intermediate3 minBefore this: ModulesSpec 12

A file may have at most 500 lines, and a function about 80: small files are easier to read, review, test and give to an AI.

The limits are set in kavach.toml. This project sets a tiny one, to show what happens:

[package]
name = "shop"
version = "0.1.0"

# A small limit, so this sample stays short; the default is 500.
[limits]
file_lines = 12
kavach.toml: TOML code
type Order {
    id: Int
    paid: Bool
}

fn paid_count(orders: [Order]) -> Int {
    orders.count(o => o.paid)
}

fn main() {
    const orders = [Order(id: 1, paid: true)]
    print(paid_count(orders))
}

The compiler refused the program:

kavach run

error: main.kav has 13 lines (limit 12)
src/main.kav: Kavach code, then what running it prints
WhatLimit or sizeSource
A .kav file500 lines, counting every line: an error by default12-maintainability.md
A function body80 lines: a warning12-maintainability.md

Every limit in Kavach, on one page: Limits and Sizes.

Every line counts, comments and blank lines too: a rule that skipped comments would push people to delete useful ones. Generated files are never counted. See Settings for the [limits] keys.