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

[bug] Unable to suppress errors for rule based on Python module kind #1541

Open
1 task done
seamuswn opened this issue Oct 21, 2024 · 2 comments
Open
1 task done

[bug] Unable to suppress errors for rule based on Python module kind #1541

seamuswn opened this issue Oct 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@seamuswn
Copy link

Please read the FAQ for the bug you encountered.

  • I have read the existing FAQ

⏯ Playground Link

https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6InB5dGhvbiIsInF1ZXJ5IjoiY29uc29sZS5sb2coJE1BVENIKSIsInJld3JpdGUiOiJsb2dnZXIubG9nKCRNQVRDSCkiLCJzdHJpY3RuZXNzIjoic21hcnQiLCJzZWxlY3RvciI6IiIsImNvbmZpZyI6Ii0tLVxuaWQ6IGVtcHR5X2luaXRfZmlsZXNcbmxhbmd1YWdlOiBQeXRob25cbnNldmVyaXR5OiBlcnJvclxubWVzc2FnZTogfFxuICBgX19pbml0X18ucHlgIGZpbGVzIHNob3VsZCBiZSBlbXB0eSBhc2lkZSBmcm9tIGltcG9ydHNcblxucnVsZTpcbiAga2luZDogbW9kdWxlXG4gIGhhczpcbiAgICBub3Q6XG4gICAgICBhbnk6XG4gICAgICAgIC0ga2luZDogaW1wb3J0X2Zyb21fc3RhdGVtZW50XG4gICAgICAgIC0ga2luZDogaW1wb3J0X3N0YXRlbWVudFxuXG5maWxlczpcbiAgLSAnKiovX19pbml0X18ucHknXG4iLCJzb3VyY2UiOiIjIGFzdC1ncmVwLWlnbm9yZTogZW1wdHlfaW5pdF9maWxlc1xuZnJvbSBmb28gaW1wb3J0IGJhclxuaW1wb3J0IGZvb1xuXG5mb28gPSBiYXIifQ==

💻 Code

---
id: empty_init_files
language: Python
severity: error
message: |
  `__init__.py` files should be empty aside from imports

rule:
  kind: module
  has:
    not:
      any:
        - kind: import_from_statement
        - kind: import_statement

files:
 - '**/__init__.py'

🙁 Actual behavior

With rule above, and # ast-grep-ignore: empty_init_files as first line in the module, ast-grep complains about /my/path/__init__.py:1:1: error[empty_init_files]: init.py files should be empty aside from imports but also /my/path/__init__.py:1:1: help[unused-suppression]: Unused '@ast-grep-ignore' directive.

🙂 Expected behavior

Placing module suppression on very first line should result in this rule being ignored and ast-grep scan passing.

Additional information about the issue

No response

@seamuswn seamuswn added the bug Something isn't working label Oct 21, 2024
@HerringtonDarkholme
Copy link
Member

At the moment ast-grep does not support file level suppression.
You can try using exclude to suppress warning.

Another issue here is that comment suppression seems to be unable suppress module, the root AST. I will investigate it later.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Oct 22, 2024

The issue here is how ast-grep handle ignore comment

# ast-grep-ignore
'this only ignores the next line'
'this only ignores the current line' # ast-grep-ignore

So the leading comment does not ignore the module ast node, instead it ignore the next line

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

No branches or pull requests

2 participants