ament / ament_lint

Apache License 2.0
37 stars 107 forks source link

--exclude negates the target path #499

Open robin-zealrobotics opened 1 month ago

robin-zealrobotics commented 1 month ago
# Correct: lints all files in src
ament_cpplint src 

# Bug: lints all files in current directory (possibly still excluding some things, I didn't verify that)
ament_cpplint --exclude "some/path.cpp" src

# Correct: workaround that does lint all files in src, excluding the path
ament_cpplint --exclude "some/path.cpp" -- src

I assume the way argparse is used to define 'exclude' is defaulting the 'paths' to '.' I wouldn't be surprised if similar problems exist for other linters.

Only tested this on Iron.

MichaelOrlov commented 4 weeks ago

Hi, @robin-zealrobotics. That is not a bug, but rather a specific of the Python's args parser and how it parsers positional arguments. There is no way to distinguish positional argument in this concrete case src from the list entity if it goes right after the explicit list entity. The known workaround is only, as you mentioned, to put the -- separator before the positional argument.

To mitigate this issue, the explicit "paths" argument could be added in addition to the existent positional "paths" argument defined here https://github.com/ament/ament_lint/blob/2e54ed347731357c510273b3d4328eaabe6825d6/ament_cpplint/ament_cpplint/main.py#L88-L96 We can't just simply change the positional argument "paths" to be a non-explicit argument since it will break backward compatibility. Also, the documentation could be updated to point out that a workaround with a -- separator should be used when a positional argument needs to be used after the list. However, help is needed with all of these proposals to be implemented.