Skip to main content

Module one_function

Module one_function 

Source
Expand description

The unit one-function-per-file check.

A source file holds at most one module-scope function whose body runs longer than the configured threshold. Functions at or under the threshold are trivial — an expression with a name — and share a file freely.

Detection is AST-based, one arm per language, each reading the same shape:

  • Pythondef / async def at module level (rustpython_parser).
  • TypeScript — top-level function declarations and a top-level const / let / var bound to an arrow or function expression, export or not (oxc).
  • Rustfn items at the top level of the file (syn).

Methods, nested functions, and callbacks belong to their owner and are never counted on their own; the walk reads the same source tree the colocated-test presence rule does, so no test file is a subject.

Re-exports§

pub use crate::violation::Violation;

Functions§

find_violations
Scan the source files under root for language and return a violation for every module-scope function past the first whose body runs longer than max_lines, sorted by (file, line).