-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a new python project for flake8 plugins, currently only containing a plugin to test for unsafe usage of models with visibility
- Loading branch information
Showing
8 changed files
with
69 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .visibility_coding_conventions import VisibilityCodingConventions |
36 changes: 36 additions & 0 deletions
36
flake8_thunderstore/plugins/visibility_coding_conventions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import ast | ||
|
||
from flake8_plugin_utils import Plugin | ||
|
||
|
||
class VisibilityCodingConventions(Plugin): | ||
name = "visibility-coding-conventions" | ||
version = "1.0.3" | ||
|
||
visibility_classes = ["PackageListing", "PackageVersion"] | ||
safe_functions = ["public_list", "system", "get", "create", "get_or_create"] | ||
excluded_filepaths = ["/migrations/", "/tests/", "/commands/", "/conftest.py"] | ||
|
||
def __init__(self, tree: ast.AST, filename: str) -> None: | ||
self.tree = tree | ||
self.filename = filename | ||
|
||
def run(self): | ||
if any(excluded in self.filename for excluded in self.excluded_filepaths): | ||
return | ||
|
||
for node in ast.walk(self.tree): | ||
if ( | ||
isinstance(node, ast.Attribute) | ||
and isinstance(node.value, ast.Attribute) | ||
and node.value.attr == "objects" | ||
and isinstance(node.value.value, ast.Name) | ||
and node.value.value.id in self.visibility_classes | ||
and node.attr not in self.safe_functions | ||
): | ||
yield ( | ||
node.lineno, | ||
node.col_offset, | ||
f"VIS753 {node.value.value.id}.objects.{node.attr} is unsafe; Objects with visibility should always be called with .public_list() or .system())", | ||
type(self), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name="flake8-thunderstore", | ||
version="1.0.0", | ||
description="Custom Flake8 plugins for Thunderstore", | ||
author="Your Name", | ||
packages=find_packages(), | ||
entry_points={ | ||
"flake8.extension": [ | ||
"VIS753 = plugins:VisibilityCodingConventions", | ||
], | ||
}, | ||
) |
Submodule python-packages
updated
from f46745 to bc6e49