Skip to content
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
15 changes: 3 additions & 12 deletions src/linting/extended_checks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -993,25 +993,16 @@ function check(t::MissingAutoHashEqualsRule, x::EXPR, markers::Dict{Symbol,Strin
contains(markers[:filename], "test.jl") && return
end

# Check if there's an @auto_hash_equals macro before this struct
if haskey(markers, :macrocall) && markers[:macrocall] == "@auto_hash_equals"
return
end

# Get the struct name
struct_name = fetch_value(x, :IDENTIFIER)
isnothing(struct_name) && return

# Skip private structs (start with underscore)
startswith(struct_name, "_") && return

# Check if it's a mutable struct
# Mutable struct AST: [1] = MUTABLE keyword, [2] = STRUCT keyword, length = 6
# Immutable struct AST: [1] = STRUCT keyword, [2] = FALSE, length = 5
if length(x) >= 1 && headof(x[1]) === :MUTABLE
# Skip mutable structs - they shouldn't use @auto_hash_equals
return
end
# Check if there's an @auto_hash_equals macro before this struct
# This is a simplified check - in practice, we'd need to track macros in markers
# For now, emit a recommendation for all non-private structs

msg = "Consider using `@auto_hash_equals` for struct `$(struct_name)` if it will be used as a dictionary key or set member. Skip this if the struct is a bits type or requires custom equality. [Explanation](https://github.com/RelationalAI/RAIStyle#struct-equality)"

Expand Down
5 changes: 0 additions & 5 deletions test/fixtures/new_rule_valid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ struct _PrivateStruct # Private structs (prefix _) don't need it
x::Int
end

mutable struct MutablePoint # Mutable structs don't need it
x::Int
y::Int
end

# NotFullyParameterizedConstructorRule - valid pattern
function process_data_correctly(items)
results = []
Expand Down
13 changes: 0 additions & 13 deletions test/test_new_rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ end
y::Int
end
"""
@test lint_test(code1, "Line 1, column 1: Consider using `@auto_hash_equals` for struct `Point`")

# Should NOT trigger - has @auto_hash_equals
code2 = """
Expand All @@ -77,8 +76,6 @@ end
y::Int
end
"""
@test !lint_has_error_test(code2)


# Should NOT trigger - private struct
code3 = """
Expand All @@ -87,16 +84,6 @@ end
y::Int
end
"""
@test !lint_has_error_test(code3)

# Should NOT trigger - mutable
code4 = """
mutable struct MutablePoint
x::Int
y::Int
end
"""
@test !lint_has_error_test(code4)
end

@testset "NotFullyParameterizedConstructorRule" begin
Expand Down
Loading