Skip to content

Commit

Permalink
Bracket applicability
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Oct 15, 2023
1 parent d2bc397 commit 935dfbb
Show file tree
Hide file tree
Showing 16 changed files with 383 additions and 383 deletions.
10 changes: 5 additions & 5 deletions selene-lib/src/lints/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,22 @@ fn generate_diff(source1: &str, source2: &str, diagnostics: &[&Diagnostic]) -> S
let mut result = String::new();
let mut has_changes = false;
let mut byte_offset = 0;
let mut prev_non_insert_applicability_prefix = " ";
let mut prev_non_insert_applicability_prefix = " ";

for change in TextDiff::from_lines(source1, source2).iter_all_changes() {
let change_length = change.value().len() as u32;

let change_end_byte = byte_offset + change_length as u32;

let mut applicability_prefix = " ";
let mut applicability_prefix = " ";
for diagnostic in diagnostics {
let (start, end) = diagnostic.primary_label.range;
if start < change_end_byte && end > byte_offset {
if diagnostic.applicability == Applicability::MachineApplicable {
applicability_prefix = "MA";
applicability_prefix = "[MA]";
break;
} else if diagnostic.applicability == Applicability::MaybeIncorrect {
applicability_prefix = "MI";
applicability_prefix = "[MI]";
break;
}
}
Expand All @@ -132,7 +132,7 @@ fn generate_diff(source1: &str, source2: &str, diagnostics: &[&Diagnostic]) -> S
has_changes = true;
format!("+{}", applicability_prefix)
}
ChangeTag::Equal => " ".to_string(),
ChangeTag::Equal => " ".to_string(),
};

result.push_str(&format!("{} {}", sign, change.value()));
Expand Down
68 changes: 34 additions & 34 deletions selene-lib/tests/lints/compare_nan/compare_nan_if.fixed.diff
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
-MI if x == 0/0 then
+MI if x ~= x then
end

-MI if x ~= 0/0 then
+MI if x == x then
end

if x ~= x then
end

if x >= 0/0 then
end

if 1 == 0/0 then
end

if 1 ~= 0/0 then
end

if 1 + 0/0 then
end

if y.foo() == 0/0 then
end

if y.bar() ~= 0/0 then
end

if x == 1 then
end

if 1 == 0 then
end
-[MI] if x == 0/0 then
+[MI] if x ~= x then
end
-[MI] if x ~= 0/0 then
+[MI] if x == x then
end
if x ~= x then
end
if x >= 0/0 then
end
if 1 == 0/0 then
end
if 1 ~= 0/0 then
end
if 1 + 0/0 then
end
if y.foo() == 0/0 then
end
if y.bar() ~= 0/0 then
end
if x == 1 then
end
if 1 == 0 then
end
30 changes: 15 additions & 15 deletions selene-lib/tests/lints/compare_nan/compare_nan_variables.fixed.diff
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
local _ = 0/0
local _ = 1 ~= 0/0
local _ = 2 == 0/0
local _ = 3 + 0/0
local _ = 4 >= 0/0
-MI local _ = x ~= 0/0
-MI local _ = x == 0/0
+MI local _ = x == x
+MI local _ = x ~= x
local _ = x >= 0/0
local _ = y.foo() == 0/0
local _ = y.bar() ~= 0/0

local _ = x == 1
local _ = 1 == 0
local _ = 0/0
local _ = 1 ~= 0/0
local _ = 2 == 0/0
local _ = 3 + 0/0
local _ = 4 >= 0/0
-[MI] local _ = x ~= 0/0
-[MI] local _ = x == 0/0
+[MI] local _ = x == x
+[MI] local _ = x ~= x
local _ = x >= 0/0
local _ = y.foo() == 0/0
local _ = y.bar() ~= 0/0
local _ = x == 1
local _ = 1 == 0
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
print(x == { "a", "b", "c" })
print({ "a", "b", "c" } == x)

-MI print(x == {})
-MI print({} == x)
-MI print(x ~= {})
-MI print({} ~= x)
+MI print(next(x) == nil)
+MI print(next(x) == nil)
+MI print(next(x) ~= nil)
+MI print(next(x) ~= nil)

print({ "a", "b", "c" } == { "a", "b", "c" })
print({ "a", "b", "c" } == {})
print({} == {})

print( -- my cool table
-MI t == {}
+MI next(t) == nil
)
print(x == { "a", "b", "c" })
print({ "a", "b", "c" } == x)
-[MI] print(x == {})
-[MI] print({} == x)
-[MI] print(x ~= {})
-[MI] print({} ~= x)
+[MI] print(next(x) == nil)
+[MI] print(next(x) == nil)
+[MI] print(next(x) ~= nil)
+[MI] print(next(x) ~= nil)
print({ "a", "b", "c" } == { "a", "b", "c" })
print({ "a", "b", "c" } == {})
print({} == {})
print( -- my cool table
-[MI] t == {}
+[MI] next(t) == nil
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
table.foreach({}, function(k, v) end)
-MA print(table.getn(x))
+MA print(#x)

table.foreach({}, 3)
table.foreach({}, function(k, v) end)
-[MA] print(table.getn(x))
+[MA] print(#x)
table.foreach({}, 3)
146 changes: 73 additions & 73 deletions selene-lib/tests/lints/empty_loop/empty_loop.fixed.diff
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
for _ = 1, 10 do
return "Should not warn"
end

for _ = 1, 10 do
print("Should not warn")
end

-MI for _ = 1, 10 do
-MI -- Should warn
-MI end

-MI for _ = 1, 10 do
-MI --[[
-MI Should warn
-MI ]]
-MI end

-MI for _ = 1, 10 do


-MI
-MI end

+
for _ in pairs({}) do
return "Should not warn"
end

-MI for _ in pairs({}) do
-MI end

+
for _ in ipairs({}) do
return "Should not warn"
end

-MI for _ in ipairs({}) do
-MI end

+
for _ in {} do
return "Should not warn"
end

-MI for _ in {} do
-MI end

+
for _ in a() do
return "Should not warn"
end

-MI for _ in a() do
-MI end

+
while true do
return "Should not warn"
end

-MI while true do
-MI end

+
repeat
return "Should not warn"
until true

-MI repeat
-MI until true
+MI
-- comment here shouldn't break anything
for _ = 1, 10 do
return "Should not warn"
end
for _ = 1, 10 do
print("Should not warn")
end
-[MI] for _ = 1, 10 do
-[MI] -- Should warn
-[MI] end
-[MI] for _ = 1, 10 do
-[MI] --[[
-[MI] Should warn
-[MI] ]]
-[MI] end
-[MI] for _ = 1, 10 do
-[MI]
-[MI] end
+
for _ in pairs({}) do
return "Should not warn"
end
-[MI] for _ in pairs({}) do
-[MI] end
+
for _ in ipairs({}) do
return "Should not warn"
end
-[MI] for _ in ipairs({}) do
-[MI] end
+
for _ in {} do
return "Should not warn"
end
-[MI] for _ in {} do
-[MI] end
+
for _ in a() do
return "Should not warn"
end
-[MI] for _ in a() do
-[MI] end
+
while true do
return "Should not warn"
end
-[MI] while true do
-[MI] end
+
repeat
return "Should not warn"
until true
-[MI] repeat
-[MI] until true
+[MI]
-- comment here shouldn't break anything
Loading

0 comments on commit 935dfbb

Please sign in to comment.