From ecaf457f883abb1fd83697551c119af7a570cd18 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Mon, 9 Oct 2023 23:49:02 -0700 Subject: [PATCH] srcfile module check: also allow single line docstrings (#51648) --- base/loading.jl | 8 ++++---- test/loading.jl | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/base/loading.jl b/base/loading.jl index bd6ca229a2465..a10c7b35d0e18 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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.")) diff --git a/test/loading.jl b/test/loading.jl index d55a212490401..d7e967f209eaa 100644 --- a/test/loading.jl +++ b/test/loading.jl @@ -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