Skip to content

Commit 7db0983

Browse files
authored
Merge branch 'master' into inclloop
2 parents 12018ff + dec3666 commit 7db0983

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/StaticLint.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ If this is successful it traverses the code associated with the loaded file.
127127
"""
128128
function followinclude(x, state::State)
129129
if typof(x) === Call && typof(x.args[1]) === IDENTIFIER && valof(x.args[1]) == "include"
130-
path = get_path(x)
130+
path = get_path(x, state)
131131
if isempty(path)
132132
elseif hasfile(state.server, path)
133133
elseif canloadfile(state.server, path)
@@ -154,8 +154,7 @@ function followinclude(x, state::State)
154154
state.file = oldfile
155155
pop!(state.included_files)
156156
else
157-
# (printstyled(">>>>Can't follow include", color = :red);printstyled(" $(Expr(x)) from $(dirname(state.path))\n"))
158-
# error handling for broken `include` here
157+
seterror!(x, MissingFile)
159158
end
160159
end
161160
end

src/linting/checks.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ PointlessOR,
99
PointlessAND,
1010
UnusedBinding,
1111
InvalidTypeDeclaration,
12-
IncludeLoop)
12+
IncludeLoop,
13+
MissingFile)
14+
1315

1416
const LintCodeDescriptions = Dict{LintCodes,String}(
1517
IncorrectCallNargs => "An incorrect number of function arguments has been passed.",
@@ -21,7 +23,8 @@ const LintCodeDescriptions = Dict{LintCodes,String}(
2123
PointlessAND => "The first argument of a `&&` call is `false`.",
2224
UnusedBinding => "The variable name has been bound but not used.",
2325
InvalidTypeDeclaration => "A non-DataType has been used in a type declaration statement.",
24-
IncludeLoop => "Loop detected, this file has already been included."
26+
IncludeLoop => "Loop detected, this file has already been included.",
27+
MissingFile => "The included file can not be found."
2528
)
2629

2730
haserror(m::Meta) = m.error !== nothing

src/server.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ end
9494
Usually called on the argument to `include` calls, and attempts to determine
9595
the path of the file to be included. Has limited support for `joinpath` calls.
9696
"""
97-
function get_path(x::EXPR)
97+
function get_path(x::EXPR, state)
9898
if typof(x) === Call && length(x.args) == 4
9999
parg = x.args[3]
100100
if CSTParser.is_lit_string(parg)
@@ -105,6 +105,8 @@ function get_path(x::EXPR)
105105
for i = 2:length(parg.args)
106106
arg = parg.args[i]
107107
if typof(arg) === PUNCTUATION
108+
elseif _is_macrocall_to_BaseDIR(arg) # Assumes @__DIR__ points to Base macro.
109+
path = string(path, "/", dirname(getpath(state.file)))
108110
elseif CSTParser.is_lit_string(arg)
109111
path = string(path, "/", CSTParser.str_value(arg))
110112
else
@@ -116,3 +118,7 @@ function get_path(x::EXPR)
116118
end
117119
return ""
118120
end
121+
122+
_is_macrocall_to_BaseDIR(arg) = typof(arg) === CSTParser.MacroCall && length(arg.args) == 1 &&
123+
typof(arg.args[1]) === CSTParser.MacroName && length(arg.args[1].args) == 2 &&
124+
valof(arg.args[1].args[2]) == "__DIR__"

0 commit comments

Comments
 (0)