From 900a49f016548093362760728988d379f26b35b6 Mon Sep 17 00:00:00 2001 From: Eric Hanson <5846501+ericphanson@users.noreply.github.com> Date: Wed, 3 Jul 2024 00:37:31 +0200 Subject: [PATCH] support code-generated exports in staleness check (#72) * add test * fix * bump version --- Project.toml | 6 ++++-- src/improper_explicit_imports.jl | 5 +++++ test/runtests.jl | 8 ++++++++ test/test_mods.jl | 8 ++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 635f729..efb4c18 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ExplicitImports" uuid = "7d51a73a-1435-4ff3-83d9-f097790105c7" authors = ["Eric P. Hanson"] -version = "1.7.0" +version = "1.8.0" [deps] AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" @@ -19,6 +19,7 @@ LinearAlgebra = "<0.0.1, 1" Logging = "<0.0.1, 1" Markdown = "<0.0.1, 1" Pkg = "<0.0.1, 1" +Reexport = "1.2.2" TOML = "<0.0.1, 1" Test = "<0.0.1, 1" UUIDs = "<0.0.1, 1" @@ -31,8 +32,9 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +Reexport = "189a3867-3050-52da-a836-e630ba90ab69" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" [targets] -test = ["Aqua", "DataFrames", "LinearAlgebra", "Logging", "Markdown", "Pkg", "UUIDs", "Test"] +test = ["Aqua", "DataFrames", "LinearAlgebra", "Logging", "Markdown", "Pkg", "UUIDs", "Reexport", "Test"] diff --git a/src/improper_explicit_imports.jl b/src/improper_explicit_imports.jl index 8a3d1da..232b660 100644 --- a/src/improper_explicit_imports.jl +++ b/src/improper_explicit_imports.jl @@ -28,6 +28,11 @@ function analyze_explicitly_imported_names(mod::Module, file=pathof(mod); output.importing_from) internal_import = Base.moduleroot(mod) == Base.moduleroot(output.importing_from) stale = (; row.name, row.module_path) in stale_imports + # Cannot be stale if public or exported in the module `mod` + # https://github.com/ericphanson/ExplicitImports.jl/issues/69 + if public_or_exported(mod, row.name) + stale = false + end push!(table, (; output..., importing_from_owns_name, importing_from_submodule_owns_name, stale, internal_import)) diff --git a/test/runtests.jl b/test/runtests.jl index af3340b..7257978 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -109,7 +109,15 @@ end @test owner_mod_for_printing(Core, :println, Core.println) == Core end +# https://github.com/ericphanson/ExplicitImports.jl/issues/69 +@testset "Reexport support" begin + @test check_no_stale_explicit_imports(TestMod15, "test_mods.jl") === nothing + @test isempty(improper_explicit_imports_nonrecursive(TestMod15, "test_mods.jl")) + @test isempty(improper_explicit_imports(TestMod15, "test_mods.jl")[1][2]) +end + if VERSION >= v"1.7-" + # https://github.com/ericphanson/ExplicitImports.jl/issues/70 @testset "Compat skipping" begin @test check_all_explicit_imports_via_owners(TestMod14, "test_mods.jl") === nothing @test check_all_qualified_accesses_via_owners(TestMod14, "test_mods.jl") === nothing diff --git a/test/test_mods.jl b/test/test_mods.jl index aa2c928..c9b5db6 100644 --- a/test/test_mods.jl +++ b/test/test_mods.jl @@ -234,3 +234,11 @@ if VERSION >= v"1.7-" end # TestMod14 end + +# https://github.com/ericphanson/ExplicitImports.jl/issues/69 +module TestMod15 +using Reexport + +@reexport using ..Exporter: exported_a + +end # TestMod15