From a345f308fa6590c4a3ee0ea402dadc27aabf5c46 Mon Sep 17 00:00:00 2001 From: Christopher Chang <51393127+chriscerie@users.noreply.github.com> Date: Wed, 18 Oct 2023 18:13:29 -0700 Subject: [PATCH] Change ` to better message --- selene-lib/src/lints.rs | 9 ++++++++- .../tests/lints/empty_loop/empty_loop.stderr | 18 +++++++++--------- .../empty_loop/empty_loop_comments.stderr | 14 +++++++------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/selene-lib/src/lints.rs b/selene-lib/src/lints.rs index 2704ccfa..d3ba8989 100644 --- a/selene-lib/src/lints.rs +++ b/selene-lib/src/lints.rs @@ -132,7 +132,14 @@ impl Diagnostic { let mut label = primary_label; if let Some(ref suggestion_str) = suggestion { if label.message.is_none() { - label = Label::new_with_message(label.range, format!("try: `{}`", suggestion_str)); + label = Label::new_with_message( + label.range, + if suggestion_str.is_empty() { + "consider removing this".to_string() + } else { + format!("try: `{}`", suggestion_str) + }, + ); } }; diff --git a/selene-lib/tests/lints/empty_loop/empty_loop.stderr b/selene-lib/tests/lints/empty_loop/empty_loop.stderr index d06bdde0..a7ae85a5 100644 --- a/selene-lib/tests/lints/empty_loop/empty_loop.stderr +++ b/selene-lib/tests/lints/empty_loop/empty_loop.stderr @@ -4,7 +4,7 @@ error[empty_loop]: empty loop block 9 │ ╭ for _ = 1, 10 do 10 │ │ -- Should warn 11 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:13:1 @@ -14,7 +14,7 @@ error[empty_loop]: empty loop block 15 │ │ Should warn 16 │ │ ]] 17 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:19:1 @@ -24,47 +24,47 @@ error[empty_loop]: empty loop block 21 │ │ 22 │ │ 23 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:29:1 │ 29 │ ╭ for _ in pairs({}) do 30 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:36:1 │ 36 │ ╭ for _ in ipairs({}) do 37 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:43:1 │ 43 │ ╭ for _ in {} do 44 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:50:1 │ 50 │ ╭ for _ in a() do 51 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:57:1 │ 57 │ ╭ while true do 58 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop.lua:64:1 │ 64 │ ╭ repeat 65 │ │ until true - │ ╰──────────^ try: `` + │ ╰──────────^ consider removing this diff --git a/selene-lib/tests/lints/empty_loop/empty_loop_comments.stderr b/selene-lib/tests/lints/empty_loop/empty_loop_comments.stderr index 5c244a27..07a7f053 100644 --- a/selene-lib/tests/lints/empty_loop/empty_loop_comments.stderr +++ b/selene-lib/tests/lints/empty_loop/empty_loop_comments.stderr @@ -6,47 +6,47 @@ error[empty_loop]: empty loop block 21 │ │ 22 │ │ 23 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop_comments.lua:29:1 │ 29 │ ╭ for _ in pairs({}) do 30 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop_comments.lua:36:1 │ 36 │ ╭ for _ in ipairs({}) do 37 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop_comments.lua:43:1 │ 43 │ ╭ for _ in {} do 44 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop_comments.lua:50:1 │ 50 │ ╭ for _ in a() do 51 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop_comments.lua:57:1 │ 57 │ ╭ while true do 58 │ │ end - │ ╰───^ try: `` + │ ╰───^ consider removing this error[empty_loop]: empty loop block ┌─ empty_loop_comments.lua:64:1 │ 64 │ ╭ repeat 65 │ │ until true - │ ╰──────────^ try: `` + │ ╰──────────^ consider removing this