Skip to content

Commit

Permalink
Change ` to better message
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Oct 19, 2023
1 parent 0acb630 commit a345f30
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
9 changes: 8 additions & 1 deletion selene-lib/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
);
}
};

Expand Down
18 changes: 9 additions & 9 deletions selene-lib/tests/lints/empty_loop/empty_loop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

14 changes: 7 additions & 7 deletions selene-lib/tests/lints/empty_loop/empty_loop_comments.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a345f30

Please sign in to comment.