Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignoring backquote in local disabling #47

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,28 @@ function reset_static_lint_caches()
end

function retrieve_full_msg_from_prefix(msg_prefix::String)
the_keys = collect(keys(StaticLint.is_recommendation))
is = findall(startswith(msg_prefix), the_keys)
function _tmp(msg::String, should_remove_backquote::Bool)
the_keys = collect(keys(StaticLint.is_recommendation))
if should_remove_backquote
the_keys = map(l->replace(l, "`" => ""), the_keys)
end
is = findall(startswith(msg_prefix), the_keys)

length(is) == 0 && return is

if length(is) != 1
isdefined(Main, :Infiltrator) && Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
end
@assert length(is) == 1
return the_keys[first(is)]
end

length(is) == 0 && return is
isdefined(Main, :Infiltrator) && Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
t = _tmp(msg_prefix, false)
isempty(t) || return t

if length(is) != 1
isdefined(Main, :Infiltrator) && Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
end
@assert length(is) == 1
return the_keys[first(is)]
t = _tmp(replace(msg_prefix, "`" => ""), true)
return t
end

function get_recommendation(msg_prefix)
Expand Down
26 changes: 26 additions & 0 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,21 @@ end

@test !lint_has_error_test(source)
end


@testset "Locally disabling rule 06: ignoring backquotes" begin
source = """
function f()
# lint-disable-next-line: Macro @spawn should be used instead of @async.
@async 1 + 1
end
"""
source_lines = split(source, "\n")
@test convert_offset_to_line_from_lines(30, source_lines) == (2, 17, nothing)
@test convert_offset_to_line_from_lines(97, source_lines) == (3, 6, "lint-disable-line Macro @spawn should be used instead of @async.")

@test !lint_has_error_test(source)
end
end

@testset "Relaxing unused bindings" begin
Expand Down Expand Up @@ -1530,9 +1545,20 @@ end
@test !rule_is_violation("`@lock` should be used with extreme caution.")
@test !rule_is_violation("`@lock` ")

# Ignoring backquoting
@test rule_is_violation("Macro @spawn should be used instead of `@async.")
@test rule_is_violation("Macro @spawn")
@test !rule_is_violation("@lock should be used with extreme caution.")
@test !rule_is_violation("`@lock ")

@test rule_is_recommendation("Splatting (`...`) should be used with extreme caution.")


# Ignoring backquoting
@test StaticLint.retrieve_full_msg_from_prefix("@lock ") ==
"`@lock` should be used with extreme caution."


@test StaticLint.retrieve_full_msg_from_prefix("`@lock` ") ==
"`@lock` should be used with extreme caution."
@test StaticLint.retrieve_full_msg_from_prefix("Macro `@spawn`") ==
Expand Down