Skip to content

Commit

Permalink
feat(python): add shared rules for imports (#400)
Browse files Browse the repository at this point in the history
Co-authored-by: elsapet <[email protected]>
  • Loading branch information
didroe and elsapet authored May 15, 2024
1 parent 9200e49 commit d084574
Show file tree
Hide file tree
Showing 4 changed files with 192 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
56 changes: 56 additions & 0 deletions rules/python/shared/lang/import3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
type: shared
languages:
- python
patterns:
- pattern: $<IMPORTED_MODULE3>.$<NAME>
filters:
- variable: IMPORTED_MODULE3
detection: python_shared_lang_import3_module3
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- variable: MODULE2
as: MODULE2
- variable: MODULE3
as: MODULE3
- from $<MODULE1>.$<MODULE2>.$<MODULE3> import $<NAME> as $<!>$<_>
- from $<MODULE1>.$<MODULE2>.$<MODULE3> import $<!>$<NAME>
auxiliary:
- id: python_shared_lang_import3_module1
patterns:
- import $<!>$<MODULE1>
- import $<!>$<MODULE1>.$<MODULE2>
- import $<!>$<MODULE1>.$<MODULE2>.$<MODULE3>
- import $<MODULE1> as $<!>$<_>
- id: python_shared_lang_import3_module2
patterns:
- pattern: $<IMPORTED_MODULE1>.$<MODULE2>
filters:
- variable: IMPORTED_MODULE1
detection: python_shared_lang_import3_module1
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- import $<MODULE1>.$<MODULE2> as $<!>$<_>
- from $<MODULE1> import $<!>$<MODULE2>
- from $<MODULE1> import $<MODULE2> as $<!>$<_>
- id: python_shared_lang_import3_module3
patterns:
- pattern: $<IMPORTED_MODULE2>.$<MODULE3>
filters:
- variable: IMPORTED_MODULE2
detection: python_shared_lang_import3_module2
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- variable: MODULE2
as: MODULE2
- import $<MODULE1>.$<MODULE2>.$<MODULE3> as $<!>$<_>
- from $<MODULE1>.$<MODULE2> import $<!>$<MODULE3>
- from $<MODULE1>.$<MODULE2> import $<MODULE3> as $<!>$<_>
metadata:
description: "Python import level 3."
id: python_shared_lang_import3
76 changes: 76 additions & 0 deletions rules/python/shared/lang/import4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
type: shared
languages:
- python
patterns:
- pattern: $<IMPORTED_MODULE4>.$<NAME>
filters:
- variable: IMPORTED_MODULE4
detection: python_shared_lang_import4_module4
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- variable: MODULE2
as: MODULE2
- variable: MODULE3
as: MODULE3
- variable: MODULE4
as: MODULE4
- from $<MODULE1>.$<MODULE2>.$<MODULE3>.$<MODULE4> import $<NAME> as $<!>$<_>
- from $<MODULE1>.$<MODULE2>.$<MODULE3>.$<MODULE4> import $<!>$<NAME>
auxiliary:
- id: python_shared_lang_import4_module1
patterns:
- import $<!>$<MODULE1>
- import $<!>$<MODULE1>.$<MODULE2>
- import $<!>$<MODULE1>.$<MODULE2>.$<MODULE3>
- import $<!>$<MODULE1>.$<MODULE2>.$<MODULE3>.$<MODULE4>
- import $<MODULE1> as $<!>$<_>
- id: python_shared_lang_import4_module2
patterns:
- pattern: $<IMPORTED_MODULE1>.$<MODULE2>
filters:
- variable: IMPORTED_MODULE1
detection: python_shared_lang_import4_module1
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- import $<MODULE1>.$<MODULE2> as $<!>$<_>
- from $<MODULE1> import $<!>$<MODULE2>
- from $<MODULE1> import $<MODULE2> as $<!>$<_>
- id: python_shared_lang_import4_module3
patterns:
- pattern: $<IMPORTED_MODULE2>.$<MODULE3>
filters:
- variable: IMPORTED_MODULE2
detection: python_shared_lang_import4_module2
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- variable: MODULE2
as: MODULE2
- import $<MODULE1>.$<MODULE2>.$<MODULE3> as $<!>$<_>
- from $<MODULE1>.$<MODULE2> import $<!>$<MODULE3>
- from $<MODULE1>.$<MODULE2> import $<MODULE3> as $<!>$<_>
- id: python_shared_lang_import4_module4
patterns:
- pattern: $<IMPORTED_MODULE3>.$<MODULE4>
filters:
- variable: IMPORTED_MODULE3
detection: python_shared_lang_import4_module3
scope: cursor
imports:
- variable: MODULE1
as: MODULE1
- variable: MODULE2
as: MODULE2
- variable: MODULE3
as: MODULE3
- import $<MODULE1>.$<MODULE2>.$<MODULE3>.$<MODULE4> as $<!>$<_>
- from $<MODULE1>.$<MODULE2>.$<MODULE3> import $<!>$<MODULE4>
- from $<MODULE1>.$<MODULE2>.$<MODULE3> import $<MODULE4> as $<!>$<_>
metadata:
description: "Python import level 4."
id: python_shared_lang_import4

0 comments on commit d084574

Please sign in to comment.