Skip to content

Commit f057f3c

Browse files
authored
Merge pull request #153 from non-Jedi/config-defaults
Add constructor for LintOptions that coalesces nothing
2 parents 14fdb10 + 3376b9e commit f057f3c

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/linting/checks.jl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,9 @@ function check_farg_unused(x::EXPR)
442442
end
443443
end
444444

445+
const default_options = (false, true, false, true, true, false, true, true, true, true)
445446

446-
mutable struct LintOptions
447+
struct LintOptions
447448
call::Bool
448449
iter::Bool
449450
nothingcomp::Bool
@@ -455,7 +456,11 @@ mutable struct LintOptions
455456
pirates::Bool
456457
useoffuncargs::Bool
457458
end
458-
LintOptions() = LintOptions(true, true, true, true, true, false, true, true, true, true)
459+
LintOptions() = LintOptions(default_options...)
460+
LintOptions(::Colon) = LintOptions(fill(true, length(default_options))...)
461+
462+
LintOptions(options::Vararg{Union{Bool,Nothing},length(default_options)}) =
463+
LintOptions(something.(options, default_options)...)
459464

460465
function check_all(x::EXPR, opts::LintOptions, server)
461466
# Do checks

test/runtests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ f(arg) = arg
287287
let cst = parse_and_pass("""
288288
sin(1,2,3)
289289
""")
290-
check_all(cst, StaticLint.LintOptions(),server)
290+
check_all(cst, StaticLint.LintOptions(:),server)
291291
@test errorof(cst[1]) === StaticLint.IncorrectCallArgs
292292
end
293293
let cst = parse_and_pass("""
@@ -296,7 +296,7 @@ f(arg) = arg
296296
for i in 1 end
297297
for i in 1:1 end
298298
""")
299-
check_all(cst, StaticLint.LintOptions(),server)
299+
check_all(cst, StaticLint.LintOptions(:),server)
300300
@test errorof(cst[1][2]) === StaticLint.IncorrectIterSpec
301301
@test errorof(cst[2][2]) === StaticLint.IncorrectIterSpec
302302
@test errorof(cst[3][2]) === StaticLint.IncorrectIterSpec
@@ -309,15 +309,15 @@ f(arg) = arg
309309
[i for i in 1 end]
310310
[i for i in 1:1 end]
311311
""")
312-
check_all(cst, StaticLint.LintOptions(),server)
312+
check_all(cst, StaticLint.LintOptions(:),server)
313313
@test errorof(cst[1][2][3]) === StaticLint.IncorrectIterSpec
314314
@test errorof(cst[2][2][3]) === StaticLint.IncorrectIterSpec
315315
@test errorof(cst[3][2][3]) === StaticLint.IncorrectIterSpec
316316
@test errorof(cst[4][2][3]) === nothing
317317
end
318318

319319
let cst = parse_and_pass("a == nothing")
320-
check_all(cst, StaticLint.LintOptions(),server)
320+
check_all(cst, StaticLint.LintOptions(:),server)
321321
@test errorof(cst[1][2]) === StaticLint.NothingEquality
322322
end
323323

@@ -406,7 +406,7 @@ end
406406
f() where {T,S}
407407
f() where {T<:Any}
408408
""")
409-
StaticLint.check_all(cst, StaticLint.LintOptions(), server)
409+
StaticLint.check_all(cst, StaticLint.LintOptions(:), server)
410410
@test StaticLint.errorof(cst[1][3]) == StaticLint.UnusedTypeParameter
411411
@test StaticLint.errorof(cst[2][4]) == StaticLint.UnusedTypeParameter
412412
@test StaticLint.errorof(cst[2][6]) == StaticLint.UnusedTypeParameter
@@ -417,7 +417,7 @@ end
417417
f(x::T,y::S) where {T,S}
418418
f(x::T) where {T<:Any}
419419
""")
420-
StaticLint.check_all(cst, StaticLint.LintOptions(), server)
420+
StaticLint.check_all(cst, StaticLint.LintOptions(:), server)
421421
@test !StaticLint.haserror(cst[1][3])
422422
@test !StaticLint.haserror(cst[2][4])
423423
@test !StaticLint.haserror(cst[2][6])

0 commit comments

Comments
 (0)