From b9a119d335ae88891a402f571d0614a95aaa472d Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 7 Nov 2022 14:50:43 -0500 Subject: [PATCH] Add an example ast-grep rule (sg scan resources/test/cpython/) --- resources/test/fixtures/A001.py | 3 +++ rules/no-os.yml | 10 ++++++++++ sgconfig.yml | 2 ++ 3 files changed, 15 insertions(+) create mode 100644 rules/no-os.yml create mode 100644 sgconfig.yml diff --git a/resources/test/fixtures/A001.py b/resources/test/fixtures/A001.py index a1a16f954b..2c3ba56300 100644 --- a/resources/test/fixtures/A001.py +++ b/resources/test/fixtures/A001.py @@ -1,3 +1,6 @@ +import os.path +import ospath +from os import path import some as sum from some import other as int diff --git a/rules/no-os.yml b/rules/no-os.yml new file mode 100644 index 0000000000..1f1581ea5d --- /dev/null +++ b/rules/no-os.yml @@ -0,0 +1,10 @@ +id: C001 +message: Don't import os +severity: warning +language: Python +rule: + any: + - pattern: import os + - pattern: import os.$_ + - pattern: from os import $_ + - pattern: from os.$_ import $_ diff --git a/sgconfig.yml b/sgconfig.yml new file mode 100644 index 0000000000..2dd8e538b4 --- /dev/null +++ b/sgconfig.yml @@ -0,0 +1,2 @@ +ruleDirs: + - rules