Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

single_call_function #10861

Closed
JonathanWoollett-Light opened this issue Jun 1, 2023 · 1 comment · Fixed by #10951
Closed

single_call_function #10861

JonathanWoollett-Light opened this issue Jun 1, 2023 · 1 comment · Fixed by #10951
Labels
A-lint Area: New lints

Comments

@JonathanWoollett-Light
Copy link

JonathanWoollett-Light commented Jun 1, 2023

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() {
    // [...]
}
@JonathanWoollett-Light JonathanWoollett-Light added the A-lint Area: New lints label Jun 1, 2023
@blyxyas
Copy link
Member

blyxyas commented Jun 2, 2023

Some additional notes:

  • This should probably be a restriction, as the drawbacks are just too big (But it does have its use-cases).
  • It should ignore tests

bors added a commit that referenced this issue Jun 19, 2023
new lint [`single_call_fn`]

Closes #10861

changelog: New lint [`single_call_fn`]
@bors bors closed this as completed in 06b444b Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants