diff options
Diffstat (limited to 'src/tools/clippy/tests/ui-toml/functions_maxlines')
3 files changed, 104 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui-toml/functions_maxlines/clippy.toml b/src/tools/clippy/tests/ui-toml/functions_maxlines/clippy.toml new file mode 100644 index 000000000..951dbb523 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/functions_maxlines/clippy.toml @@ -0,0 +1 @@ +too-many-lines-threshold = 1 diff --git a/src/tools/clippy/tests/ui-toml/functions_maxlines/test.rs b/src/tools/clippy/tests/ui-toml/functions_maxlines/test.rs new file mode 100644 index 000000000..4ac037854 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/functions_maxlines/test.rs @@ -0,0 +1,60 @@ +#![warn(clippy::too_many_lines)] +#![allow(clippy::let_unit_value)] + +// This function should be considered one line. +fn many_comments_but_one_line_of_code() { + /* println!("This is good."); */ + // println!("This is good."); + /* */ // println!("This is good."); + /* */ // println!("This is good."); + /* */ // println!("This is good."); + /* */ // println!("This is good."); + /* println!("This is good."); + println!("This is good."); + println!("This is good."); */ + println!("This is good."); +} + +// This should be considered two and a fail. +fn too_many_lines() { + println!("This is bad."); + println!("This is bad."); +} + +// This should only fail once (#7517). +async fn async_too_many_lines() { + println!("This is bad."); + println!("This is bad."); +} + +// This should fail only once, without failing on the closure. +fn closure_too_many_lines() { + let _ = { + println!("This is bad."); + println!("This is bad."); + }; +} + +// This should be considered one line. +#[rustfmt::skip] +fn comment_starts_after_code() { + let _ = 5; /* closing comment. */ /* + this line shouldn't be counted theoretically. + */ +} + +// This should be considered one line. +fn comment_after_code() { + let _ = 5; /* this line should get counted once. */ +} + +// This should fail since it is technically two lines. +#[rustfmt::skip] +fn comment_before_code() { + let _ = "test"; + /* This comment extends to the front of + the code but this line should still count. */ let _ = 5; +} + +// This should be considered one line. +fn main() {} diff --git a/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr b/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr new file mode 100644 index 000000000..dc255bdca --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/functions_maxlines/test.stderr @@ -0,0 +1,43 @@ +error: this function has too many lines (2/1) + --> $DIR/test.rs:19:1 + | +LL | / fn too_many_lines() { +LL | | println!("This is bad."); +LL | | println!("This is bad."); +LL | | } + | |_^ + | + = note: `-D clippy::too-many-lines` implied by `-D warnings` + +error: this function has too many lines (4/1) + --> $DIR/test.rs:25:1 + | +LL | / async fn async_too_many_lines() { +LL | | println!("This is bad."); +LL | | println!("This is bad."); +LL | | } + | |_^ + +error: this function has too many lines (4/1) + --> $DIR/test.rs:31:1 + | +LL | / fn closure_too_many_lines() { +LL | | let _ = { +LL | | println!("This is bad."); +LL | | println!("This is bad."); +LL | | }; +LL | | } + | |_^ + +error: this function has too many lines (2/1) + --> $DIR/test.rs:53:1 + | +LL | / fn comment_before_code() { +LL | | let _ = "test"; +LL | | /* This comment extends to the front of +LL | | the code but this line should still count. */ let _ = 5; +LL | | } + | |_^ + +error: aborting due to 4 previous errors + |