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

--exclude negates the target path #499

Open
robin-zealrobotics opened this issue Aug 6, 2024 · 1 comment
Open

--exclude negates the target path #499

robin-zealrobotics opened this issue Aug 6, 2024 · 1 comment
Labels
more-information-needed Further information is required

Comments

@robin-zealrobotics
Copy link

robin-zealrobotics commented Aug 6, 2024

# 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
Copy link

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

parser.add_argument(
'paths',
nargs='*',
default=[os.curdir],
help='The files or directories to check. For directories files ending '
'in %s will be considered.' %
', '.join(["'.%s'" % e for e in extensions + headers]))
# not using a file handle directly
# in order to prevent leaving an empty file when something fails early

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.

@mjcarroll mjcarroll added the more-information-needed Further information is required label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more-information-needed Further information is required
Projects
None yet
Development

No branches or pull requests

3 participants