Skip to content

(WIP) Test missing logging call linter #764

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions vex.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[vex]
version = "1"

[files]
ignore = [ "vex.toml", "vexes/", ".git/", ".gitignore", ".idea/", "lib/", "tests/", "venv/" ]

[python]
use-for = [ "*.star" ]
42 changes: 42 additions & 0 deletions vexes/logging.star
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
def init():
vex.observe('open_project', on_open_project)

def find_logging_call(node):
for previous_sibling in node.previous_siblings():
if str(previous_sibling).startswith('logger.'):
return previous_sibling
return None

def find_parent(node, predicate):
parent = node.parent().parent()
if predicate(parent):
return parent
return None

def on_open_project(_):
vex.search(
'python',
'(return_statement) @return_statement',
on_match,
)

def on_match(event):
return_statement = event.captures['return_statement']

parent = find_parent(
return_statement,
lambda node: node.kind == 'if_statement',
)

if type(parent) == type(None):
return

logging_call = find_logging_call(return_statement)
if logging_call:
return

vex.warn(
'logging',
'return statement without logging call',
at=(parent, 'consider adding the logging call')
)
Loading