Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent XRef issue when analysis runs on generated code #2829

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

kivra-pauoli
Copy link
Contributor

@kivra-pauoli kivra-pauoli commented Sep 12, 2023

Motivation

It is not guaranteed that a generated module contains a file attribute. I've seen erlydtl-generated modules that don't have it.

It's potentially possible to not see the error by making use of xref_queries (?) though I didn't test that thoroughly (I will have to eventually use it though, since some generated modules do appear to have the file attribute, but I'm still to understand where it's coming from).

On the other hand, instead of simply removing the analysis (as per the code comment) we could also output a special

module <module>: ...

with the error.

Review notes

Probably best seen with "Hide whitespace" enabled.

@kivra-pauoli
Copy link
Contributor Author

For reference, the query to prevent analysis of e.g. exports_not_used over erlydtl-issued modules can be something like

{xref_queries, [
    {"X - XU - (\".*_dtl_.*\":\".*\"/\".*\")" % exports not used (except *_dtl_* modules)
    , []
    }
]}.

Copy link
Collaborator

@ferd ferd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems pretty alright. Turns a crash into a returned error and the substitution of module_not_found is probably good enough to go on with this.

@ferd ferd merged commit a16f41a into erlang:main Sep 29, 2023
5 of 6 checks passed
@ferd
Copy link
Collaborator

ferd commented Sep 29, 2023

Thanks for the contribution, and sorry for the slow review!

@kivra-pauoli kivra-pauoli deleted the fix/xref-for-generated-code branch September 29, 2023 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants