Skip to content

Commit

Permalink
srcfile module check: also allow single line docstrings (#51648)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth authored Oct 10, 2023
1 parent 6da54ce commit ecaf457
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2255,13 +2255,13 @@ function check_src_module_wrap(pkg::PkgId, srcpath::String)
module_rgx = r"^\s*(?:@\w*\s*)*(?:bare)?module\s"
load_rgx = r"\b(?:using|import)\s"
load_seen = false
inside_comment = false
inside_string = false
for s in eachline(srcpath)
if contains(s, "\"\"\"")
if count("\"\"\"", s) == 1
# ignore module docstrings
inside_comment = !inside_comment
inside_string = !inside_string
end
inside_comment && continue
inside_string && continue
if startswith(s, module_rgx)
if load_seen
throw(ErrorException("Package $pkg source file $srcpath has a using/import before a module declaration."))
Expand Down
8 changes: 8 additions & 0 deletions test/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,14 @@ end
""")
@test Base.check_src_module_wrap(p, fpath)

write(fpath, """
\"\"\" Foo \"\"\"
module Foo
using Bar
end
""")
@test Base.check_src_module_wrap(p, fpath)

write(fpath, """
# using foo
module Foo
Expand Down

0 comments on commit ecaf457

Please sign in to comment.