Skip to content

single_call_function #10861

@JonathanWoollett-Light

Description

@JonathanWoollett-Light

What it does

Checks for functions which are only called in 1 location.

Enabling this lint can guard against segmentation which can occur stealthily over a long period of development, when a function is split purposefully for testing or readability this lint can be allowed for these specific cases.

Advantage

Functions that are only called once, may be better suited as scopes or in-lined.

Premature abstraction can occur in development leading to segmentation with many small functions that are only called once, this can introduce significant additional complexity and indirection that makes the code-base less readable.

Drawbacks

It can be useful to split a large function into sub-functions even when these are only called once each, this can improve test-ability and readability. This is often done purposefully.

Example

fn main() {
    one();
}
fn one() {
    // [...]
}

Could be written as:

fn main() {
    // [...]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions