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

Add support of ignore comment on the top of the file #291

Merged
merged 2 commits into from Feb 19, 2024

Conversation

bp72
Copy link
Contributor

@bp72 bp72 commented Feb 10, 2024

Autoflake can now ignore files with the # autoflake: ignore comment on top.
Closes #97

Copy link
Collaborator

@fsouza fsouza left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!

README.md Outdated
@@ -127,6 +127,11 @@ options:
-s, --stdout print changed text to stdout. defaults to true when formatting stdin, or to false otherwise
```

To ignore the file, you can also add a comment to the top of the file:
```python
# autoflake: ignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you make it skip_file instead?

It's more explicit. ignore can be a bit vague (is it ignoring the next line? the whole file?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with skip_file, thank you!

autoflake.py Outdated
@@ -904,6 +906,9 @@ def fix_code(
if not source:
return source

if source.lstrip().startswith(IGNORE_COMMENT):
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please make sure this works with shebangs too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, what do you mean by shebangs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Something like:

#!/usr/bin/env python3

# autoflake: skip_file

...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, thank you!

Copy link
Collaborator

@fsouza fsouza left a comment

Choose a reason for hiding this comment

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

Thanks for contributing!

@fsouza fsouza merged commit d90f8f4 into PyCQA:main Feb 19, 2024
17 checks passed
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.

Exclude entire file?
2 participants