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

False positives when detecting unused imports (RabbitMQ codebase) #30

Open
mkuratczyk opened this issue May 22, 2024 · 4 comments
Open
Labels
bug Something isn't working prio-high

Comments

@mkuratczyk
Copy link
Contributor

mkuratczyk commented May 22, 2024

Describe the bug

I tried to use elp to remove unused imports across RabbitMQ codebase.
However, there are two imports that I need to restore afterwards, for RabbitMQ to start.

To Reproduce**

git clone https://github.com/rabbitmq/rabbitmq-server.git
cd rabbitmq-server
elp lint --diagnostic-filter W0020 --apply-fix --in-place --include-tests
make start-cluster

The imports that are incorrectly removed are here:

  1. https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbit/src/rabbit_amqp_util.erl#L9
    Here the problem I think is related to the fact that amqp10_framing.hrl is a generated file.
    rabbit_amqp_util.erl includes rabbit_amqp.hrl which in turn includes amqp10_common/include/amqp10_framing.hrl but this file doesn't exist if you start from a fresh repo. If you run make start-cluster first and then run the same elp command, rabbit_amqp_uti.erl is not modified by elp.

  2. https://github.com/rabbitmq/rabbitmq-server/blob/main/deps/rabbitmq_peer_discovery_consul/src/rabbitmq_peer_discovery_consul_health_check_helper.erl#L18
    In this case, the need for the removed include file is "hidden" by a macro -?CONFIG_MAPPING expands to code that uses the peer_discovery_config_entry_meta record.

Context

  • ELP Version (output of elp version): elp 1.1.0+build-2024-05-17

Thank you!

@robertoaloi
Copy link
Contributor

@mkuratczyk Thanks for reporting! While we work on a fix, you can prepend the problematic line with something like:

% elp:ignore L1500 W0020 - false positive (see https://github.com/WhatsApp/erlang-language-platform/issues/30)

Which will silent the linter (so you can run it from CLI periodically or in CI)

@alanz L1500 was the old error code for the diagnostic. It looks like we still report both.

@alanz
Copy link
Member

alanz commented May 23, 2024

L1500 is long gone, make sure you are using a recent version of ELP

@michalmuskala
Copy link
Member

ELP generally assumes header files are self-contained - this is violated in the 2nd case you describe since rabbit_peer_discovery_consul.hrl can't be included independently.

The "proper" fix from the view point of ELP and self-contained headers would be to move -include_lib("rabbitmq_peer_discovery_common/include/rabbit_peer_discovery.hrl"). into the header that defines the macro using the records from there, notably rabbit_peer_discovery_consul.hrl. The include_lib can be later removed from modules including rabbit_peer_discovery_consul.hrl.

@mkuratczyk
Copy link
Contributor Author

yeah, that makes sense. we can solve the second case on our side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working prio-high
Projects
None yet
Development

No branches or pull requests

4 participants