From e93f1ec6dd8891ca1ca6304421be778e168bf4ef Mon Sep 17 00:00:00 2001 From: David Roe Date: Wed, 15 May 2024 11:26:33 +0100 Subject: [PATCH 1/3] feat(python): add shared rules for imports --- rules/python/shared/lang/import1.yml | 22 ++++++++++++++++ rules/python/shared/lang/import2.yml | 38 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 rules/python/shared/lang/import1.yml create mode 100644 rules/python/shared/lang/import2.yml diff --git a/rules/python/shared/lang/import1.yml b/rules/python/shared/lang/import1.yml new file mode 100644 index 00000000..06154399 --- /dev/null +++ b/rules/python/shared/lang/import1.yml @@ -0,0 +1,22 @@ +type: shared +languages: + - python +patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE1 + detection: python_shared_lang_import1_module1 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - from $ import $ as $$<_> + - from $ import $$ +auxiliary: + - id: python_shared_lang_import1_module1 + patterns: + - import $$ + - import $ as $$<_> +metadata: + description: "Python import level 1." + id: python_shared_lang_import1 diff --git a/rules/python/shared/lang/import2.yml b/rules/python/shared/lang/import2.yml new file mode 100644 index 00000000..63c08a76 --- /dev/null +++ b/rules/python/shared/lang/import2.yml @@ -0,0 +1,38 @@ +type: shared +languages: + - python +patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE2 + detection: python_shared_lang_import2_module2 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - variable: MODULE2 + as: MODULE2 + - from $.$ import $ as $$<_> + - from $.$ import $$ +auxiliary: + - id: python_shared_lang_import2_module1 + patterns: + - import $$ + - import $$.$ + - import $ as $$<_> + - id: python_shared_lang_import2_module2 + patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE1 + detection: python_shared_lang_import2_module1 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - import $.$ as $$<_> + - from $ import $$ + - from $ import $ as $$<_> +metadata: + description: "Python import level 2." + id: python_shared_lang_import2 From dc77153c0f12512c6c7e4d972b5b246eab16d664 Mon Sep 17 00:00:00 2001 From: elsapet Date: Wed, 15 May 2024 12:56:13 +0200 Subject: [PATCH 2/3] feat(python): add import rule for 4 --- rules/python/shared/lang/import4.yml | 76 ++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 rules/python/shared/lang/import4.yml diff --git a/rules/python/shared/lang/import4.yml b/rules/python/shared/lang/import4.yml new file mode 100644 index 00000000..492ad60b --- /dev/null +++ b/rules/python/shared/lang/import4.yml @@ -0,0 +1,76 @@ +type: shared +languages: + - python +patterns: + - pattern: $.$ + 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 $.$.$.$ import $ as $$<_> + - from $.$.$.$ import $$ +auxiliary: + - id: python_shared_lang_import4_module1 + patterns: + - import $$ + - import $$.$ + - import $$.$.$ + - import $$.$.$.$ + - import $ as $$<_> + - id: python_shared_lang_import4_module2 + patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE1 + detection: python_shared_lang_import4_module1 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - import $.$ as $$<_> + - from $ import $$ + - from $ import $ as $$<_> + - id: python_shared_lang_import4_module3 + patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE2 + detection: python_shared_lang_import4_module2 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - variable: MODULE2 + as: MODULE2 + - import $.$.$ as $$<_> + - from $.$ import $$ + - from $.$ import $ as $$<_> + - id: python_shared_lang_import4_module4 + patterns: + - pattern: $.$ + 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 $.$.$.$ as $$<_> + - from $.$.$ import $$ + - from $.$.$ import $ as $$<_> +metadata: + description: "Python import level 4." + id: python_shared_lang_import4 From ce18aa1837696614b75b8aa05033da9e7c636e11 Mon Sep 17 00:00:00 2001 From: elsapet Date: Wed, 15 May 2024 12:58:38 +0200 Subject: [PATCH 3/3] feat(python): add import rule for 3 --- rules/python/shared/lang/import3.yml | 56 ++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 rules/python/shared/lang/import3.yml diff --git a/rules/python/shared/lang/import3.yml b/rules/python/shared/lang/import3.yml new file mode 100644 index 00000000..b3279ce6 --- /dev/null +++ b/rules/python/shared/lang/import3.yml @@ -0,0 +1,56 @@ +type: shared +languages: + - python +patterns: + - pattern: $.$ + 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 $.$.$ import $ as $$<_> + - from $.$.$ import $$ +auxiliary: + - id: python_shared_lang_import3_module1 + patterns: + - import $$ + - import $$.$ + - import $$.$.$ + - import $ as $$<_> + - id: python_shared_lang_import3_module2 + patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE1 + detection: python_shared_lang_import3_module1 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - import $.$ as $$<_> + - from $ import $$ + - from $ import $ as $$<_> + - id: python_shared_lang_import3_module3 + patterns: + - pattern: $.$ + filters: + - variable: IMPORTED_MODULE2 + detection: python_shared_lang_import3_module2 + scope: cursor + imports: + - variable: MODULE1 + as: MODULE1 + - variable: MODULE2 + as: MODULE2 + - import $.$.$ as $$<_> + - from $.$ import $$ + - from $.$ import $ as $$<_> +metadata: + description: "Python import level 3." + id: python_shared_lang_import3