rust-lang / rust-lang/rust-clippy
too_few_lines
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Checks for functions with a small amount of lines.
The counter-part to too_many_lines.
It should have a configuration variable too-few-lines-threshold: u64 which should default to 1.
It should be a pedantic lint (presuming a default threshold of 1).
Advantage
- Very small functions may increase lines of code by their usage. Their signature and calls may outweigh the code duplication they remove.
Drawbacks
- Set at anything above very small (e.g 1) it can produce many unreasonable warnings.
Example
fn main() {
let a = add(1, 2);
}
fn add(rhs: u8, lhs: u8) -> u8 {
rhs + lhs
}
Could be written as:
fn main() {
let a = 1 + 2;
}
fn main() {
let a = line(4, 3, 2, 1);
}
fn line(x: u8, a: u8, b: u8, c: u8) -> u8 {
add(add(x.pow(a), mul(x, b)), c)
}
fn mul(rhs: u8, lhs: u8) -> u8 {
rhs * lhs
}
fn add(rhs: u8, lhs: u8) -> u8 {
rhs + lhs
}
Could be written as:
fn main() {
let a = 4u8.pow(3) + (4*2) + 1;
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the existing too_many_lines lint linked in the issue and tracing how its threshold configuration and tests are organized. Define the corresponding small-function lint with a default threshold of 1 and pedantic level, then verify that the examples and configuration behavior are covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100