axelson
I’m working on a library that uses compiler tracing to detect calls to @moduledoc false and @doc false modules/functions. But if code was generated in a macro within a dependency I do not want to generate a warning for that call/reference even if that code is calling a module that would typically be private.
Here is an example of a macro that creates a function that calls a module (ExampleDep.Private) that is @moduledoc false but should not generate a warning from your application (PrivCheckExample):
defmodule ExampleDep.PubMacros do
...
defmacro expand_funcs do
quote location: :keep, unquote: false do
def good_func do
ExampleDep.Private.add(1, 2)
end
end
end
...
end
I’m trying to disambiguate the :alias_reference check first. Here is all the data that I am receiving:
ref: {:alias_reference, [line: 13, counter: {PrivCheckExample, 3}, alias: false],
ExampleDep.Private}
env: #Macro.Env<
aliases: [],
context: nil,
context_modules: [PrivCheckExample],
file: "lib/example_dep/pub_macros.ex",
function: {:good_func, 0},
functions: [{Kernel, [!=: 2, !==: 2, *: 2, ...]}],
lexical_tracker: #PID<0.179.0>,
line: 36,
macro_aliases: [],
macros: [{Kernel, ...}],
module: PrivCheckExample,
requires: [...],
...
>
Currently the only possibility that I see is that the file path in the Macro.Env is relative rather absolute, and the file name doesn’t match the current module (but since the file name could be anything that is not reliable). Can I depend on the fact that the file path is not absolute to know that the call was generated within a macro?
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
josevalim
No, unfortunately that’s not possible today. The file path in Macro.Env doesn’t guarantee it either, as it only changes when using
location: :keep.axelson
I get around macros without
location: :keepby not checking them (if there’s a:remote_macrocall at the same line in the file then errors on that line are ignored).Could I say that a relative path in
Macro.Envindicates thatlocation: :keepwas used? Maybe as a heuristic I could ignore those as well.For my tool I’m trying to avoid any false positives, but false negatives are okay (since it appears impossible to account for them in an automated tool).