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

feat(python): add shared rules for imports #400

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading