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

Adding splatting #33

Merged
merged 2 commits into from
Mar 11, 2024
Merged
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
8 changes: 8 additions & 0 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct In_Extension <: ExtendedRule end
struct HasKey_Extension <: ExtendedRule end
struct Equal_Extension <: ExtendedRule end
struct Uv_Extension <: ExtendedRule end
struct Splatting_Extension <: ExtendedRule end


const all_extended_rule_types = Ref{Any}(InteractiveUtils.subtypes(ExtendedRule))
Expand Down Expand Up @@ -280,3 +281,10 @@ function check(::Uv_Extension, x::EXPR)
"uv_QQQ(hole_variable_star)",
"`uv_` functions should be used with extreme caution.")
end

function check(::Splatting_Extension, x::EXPR)
generic_check(
x,
"hole_variable(hole_variable_star...)",
"Splatting (`...`) should be used with extreme caution. Splatting from dynamically sized containers could result in severe performance degradation.")
end
7 changes: 7 additions & 0 deletions test/rai_rules_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ end
@test lint_test(source,
"Line 6, column 9: `uv_` functions should be used with extreme caution.")
end

@testset "Splatting" begin
@test lint_test("hcat([f(x) for x in r]...)",
"Line 1, column 1: Splatting (`...`) should be used with extreme caution. Splatting from dynamically sized containers could result in severe performance degradation.")
end
end

@testset "Comparing AST to templates" begin
Expand Down Expand Up @@ -558,6 +563,8 @@ end
@test t("in(hole_variable,hole_variable)", "in(x,y)")
@test t("x in y", "hole_variable in hole_variable")

# Splatting
@test t("f(a...)", "hole_variable(hole_variable_star...)")
end

@testset "unsafe functions" begin
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,8 @@ f(arg) = arg
""")
m_counts = StaticLint.func_nargs(cst.args[1])
call_counts = StaticLint.call_nargs(cst.args[1].args[2].args[1])
@test StaticLint.errorof(cst.args[1].args[2].args[1]) === nothing
@test StaticLint.errorof(cst.args[1].args[2].args[1]) ===
"Splatting (`...`) should be used with extreme caution. Splatting from dynamically sized containers could result in severe performance degradation."
end
let cst = parse_and_pass("""
function func(@nospecialize args...) end
Expand Down
Loading