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

[DO NOT MERGE] Improving local Lint disabling, per rule #31

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d584d1a
Adding `uv_` checks
bergel Mar 7, 2024
01f8997
Improving local Lint disabling, per rule
bergel Mar 8, 2024
c26fc82
Merge pull request #30 from RelationalAI/adding-uv-checks
bergel Mar 8, 2024
59440d7
fixing msg
bergel Mar 8, 2024
ddce961
Improving method call error
bergel Mar 8, 2024
548103b
Improved method call error.
bergel Mar 11, 2024
e4ac5b9
Adding support for Splatting
bergel Mar 11, 2024
98c1b28
Fixed english
bergel Mar 11, 2024
48c631c
Merge pull request #33 from RelationalAI/adding-splatting
bergel Mar 11, 2024
a54fe37
Merge pull request #32 from RelationalAI/improving-method-call-error
bergel Mar 11, 2024
b52135f
Improved Splatting
bergel Mar 11, 2024
443e240
Merge pull request #34 from RelationalAI/improved-splatting
bergel Mar 11, 2024
0a1732f
Improved checks for arrays
bergel Mar 11, 2024
e5f2db8
Merge pull request #35 from RelationalAI/improved-array
bergel Mar 11, 2024
51b45c5
Improves the splatting error msg
bergel Mar 13, 2024
efcf5f8
fixed test
bergel Mar 13, 2024
f90a0d8
Merge pull request #36 from RelationalAI/improved-splatting-error-msg
bergel Mar 13, 2024
0d5460e
Unreachable branches
bergel Mar 15, 2024
5afe908
Merge pull request #37 from RelationalAI/axb-unreachable-branch
bergel Mar 15, 2024
9b74097
Improving local Lint disabling, per rule
bergel Mar 8, 2024
91bcc18
Merge branch 'improving-local-disabling' of github.com:RelationalAI/S…
bergel Mar 15, 2024
ff57d4e
Fixing
bergel Jun 20, 2024
9e7f9ed
get modified lines
bergel Jun 20, 2024
8bfc51d
modified lines
bergel Jun 20, 2024
2a3a0fe
fix
bergel Jun 20, 2024
b9e2910
removing unnecessary GHAction
bergel Jun 20, 2024
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
29 changes: 25 additions & 4 deletions src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,32 @@ function filter_and_print_hint(hint_as_string::String, io::IO=stdout, filters::V
# +1 is because CSTParser gives offset starting at 0.
offset = Base.parse(Int64, offset_as_string) + 1

line_number, column, annotation_line = convert_offset_to_line_from_filename(offset, filename)
# Remove the offset from the result. No need for this.
cleaned_hint = replace(hint_as_string, (" at offset $offset_as_string of" => ""))
try
line_number, column, annotation_line = convert_offset_to_line_from_filename(offset, filename)

# isdefined(Man, :Infiltrator) && Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
local error_type
cleaned_hint_without_filename = cleaned_hint[1:end-length(filename)-1]
if !(cleaned_hint_without_filename in keys(error_msg2type))
error_type = string(StaticLint.error_msg2type[cleaned_hint_without_filename])
else
error_type = nothing
end

if isnothing(annotation_line)
print_hint(formatter, io, "Line $(line_number), column $(column):", hint_as_string)
return true
function typestring_from_annotation(annotation::String)
isnothing(annotation) && return nothing
contains(annotation, ":") || return nothing
return split(annotation, ":")[2]
end
if isnothing(annotation_line) || typestring_from_annotation(annotation_line) !== error_type
print_hint(formatter, io, "Line $(line_number), column $(column):", cleaned_hint)
return true
end
catch e
# isdefined(Main, :Infiltrator) && Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
@error "Cannot retreive offset=$offset in file $filename error=$e"
end
return false
end
Expand Down
32 changes: 29 additions & 3 deletions src/linting/checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ LintOptions(options::Vararg{Union{Bool,Nothing},length(default_options)}) =
LintOptions(something.(options, default_options)...)


function fetch_value(x::SymbolServer.VarRef, tag::Symbol)
return x.name
end

function fetch_value(x::EXPR, tag::Symbol)
if headof(x) == tag
return x.val
Expand All @@ -136,14 +140,21 @@ function check_all(x::EXPR, opts::LintOptions, env::ExternalEnv, markers::Dict{S
markers[:function] = fetch_value(x, :IDENTIFIER)
end

if headof(x) === :macrocall
id = fetch_value(x, :IDENTIFIER)
if !isnothing(id)
markers[:macrocall] = id
end
end

# Do checks
opts.call && check_call(x, env)
opts.iter && check_loop_iter(x, env)
opts.nothingcomp && check_nothing_equality(x, env)
opts.constif && check_if_conds(x)
opts.lazy && check_lazy(x)
opts.datadecl && check_datatype_decl(x, env)
opts.typeparam && check_typeparams(x)
opts.typeparam && check_typeparams(x, markers)
opts.modname && check_modulename(x)
opts.pirates && check_for_pirates(x)
opts.useoffuncargs && check_farg_unused(x)
Expand All @@ -167,6 +178,7 @@ function check_all(x::EXPR, opts::LintOptions, env::ExternalEnv, markers::Dict{S
# Do some cleaning
headof(x) === :const && delete!(markers, :const)
headof(x) === :function && delete!(markers, :function)
headof(x) === :macrocall && delete!(markers, :macrocall)
end

function _typeof(x, state)
Expand Down Expand Up @@ -341,7 +353,18 @@ function check_call(x, env::ExternalEnv)
tls = retrieve_toplevel_scope(x)
tls === nothing && return @warn "Couldn't get top-level scope." # General check, this means something has gone wrong.
func_ref === nothing && return
!sig_match_any(func_ref, x, call_counts, tls, env) && seterror!(x, IncorrectCallArgs)
if !sig_match_any(func_ref, x, call_counts, tls, env)
if func_ref.name isa SymbolServer.VarRef &&
!isnothing(func_ref.name.parent) &&
func_ref.name.parent.name == :Base &&
!isnothing(func_ref.name.name)

func_ref.name.name in [:copy] && return
end
function_name = fetch_value(func_ref.name, :IDENTIFIER)
function_name in ["delete!", "copy", "copy!", "write", "hash", "iterate"] && return
seterror!(x, "Possible method call error: $(function_name).")
end
end
end

Expand Down Expand Up @@ -778,7 +801,10 @@ end

isunionfaketype(t::SymbolServer.FakeTypeName) = t.name.name === :Union && t.name.parent isa SymbolServer.VarRef && t.name.parent.name === :Core

function check_typeparams(x::EXPR)
function check_typeparams(x::EXPR, markers::Dict{Symbol,String})
haskey(markers, :macrocall) && markers[:macrocall] == "@match" && return
haskey(markers, :macrocall) && markers[:macrocall] == "@matchrule" && return

if iswhere(x)
for i in 2:length(x.args)
a = x.args[i]
Expand Down
Loading
Loading