Skip to content

Commit

Permalink
feat(python): add shared rules for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
didroe committed May 15, 2024
1 parent 9200e49 commit e93f1ec
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
22 changes: 22 additions & 0 deletions rules/python/shared/lang/import1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type: shared
languages:
- python
patterns:
- pattern: $<IMPORTED_MODULE1>.$<NAME>
filters:
- variable: IMPORTED_MODULE1
detection: python_shared_lang_import1_module1
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- from $<MODULE1> import $<NAME> as $<!>$<_>
- from $<MODULE1> import $<!>$<NAME>
auxiliary:
- id: python_shared_lang_import1_module1
patterns:
- import $<!>$<MODULE1>
- import $<MODULE1> as $<!>$<_>
metadata:
description: "Python import level 1."
id: python_shared_lang_import1
38 changes: 38 additions & 0 deletions rules/python/shared/lang/import2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
type: shared
languages:
- python
patterns:
- pattern: $<IMPORTED_MODULE2>.$<NAME>
filters:
- variable: IMPORTED_MODULE2
detection: python_shared_lang_import2_module2
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- variable: MODULE2
as: MODULE2
- from $<MODULE1>.$<MODULE2> import $<NAME> as $<!>$<_>
- from $<MODULE1>.$<MODULE2> import $<!>$<NAME>
auxiliary:
- id: python_shared_lang_import2_module1
patterns:
- import $<!>$<MODULE1>
- import $<!>$<MODULE1>.$<MODULE2>
- import $<MODULE1> as $<!>$<_>
- id: python_shared_lang_import2_module2
patterns:
- pattern: $<IMPORTED_MODULE1>.$<MODULE2>
filters:
- variable: IMPORTED_MODULE1
detection: python_shared_lang_import2_module1
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- import $<MODULE1>.$<MODULE2> as $<!>$<_>
- from $<MODULE1> import $<!>$<MODULE2>
- from $<MODULE1> import $<MODULE2> as $<!>$<_>
metadata:
description: "Python import level 2."
id: python_shared_lang_import2

0 comments on commit e93f1ec

Please sign in to comment.