Skip to content

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

Merged
fsouza merged 2 commits intoPyCQA:mainfrom
bp72:ignore-file-comment
Feb 19, 2024
Merged

Add support of ignore comment on the top of the file#291
fsouza merged 2 commits intoPyCQA:mainfrom
bp72:ignore-file-comment

Conversation

@bp72
Copy link
Copy Markdown
Contributor

@bp72 bp72 commented Feb 10, 2024

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

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

To ignore the file, you can also add a comment to the top of the file:
```python
# autoflake: ignore
Copy link
Copy Markdown
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
Copy Markdown
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
if not source:
return source

if source.lstrip().startswith(IGNORE_COMMENT):
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

@bp72 bp72 force-pushed the ignore-file-comment branch from 3f2ec11 to ba134f9 Compare February 17, 2024 10:31
@bp72 bp72 force-pushed the ignore-file-comment branch from ba134f9 to adeed89 Compare February 17, 2024 10:36
Copy link
Copy Markdown
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
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