Skip to content

Commit 44fdc0f

Browse files
committed
switch from deny listing to allow listing
This ensures the linter will catch violations on newly added models.
1 parent 4aa4f09 commit 44fdc0f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

scripts/lint_model_usage_in_views.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
"""Simple linter to spot denylisted model usage within Django view modules."""
2+
"""Check for model usage without provider scoping within Django view modules."""
33

44
import argparse
55
import re
@@ -9,13 +9,16 @@
99

1010
REPO_ROOT = Path(__file__).parent.parent
1111

12-
DENYLISTED_MODELS = (
13-
"Appointment",
14-
"Clinic",
15-
"Participant",
16-
"Symptom",
17-
"BreastCancerHistoryItem",
12+
ALLOWLISTED_MODELS = (
13+
"User",
14+
"Provider",
15+
"BreastAugmentationHistoryItem", # Temporarily allowed
16+
"CystHistoryItem", # Temporarily allowed
17+
"ImplantedMedicalDeviceHistoryItem", # Temporarily allowed
18+
"MastectomyOrLumpectomyHistoryItem", # Temporarily allowed
19+
"ParticipantReportedMammogram", # Temporarily allowed
1820
)
21+
1922
TARGETS = {
2023
"model.objects": re.compile(r"(?P<model_name>\w+)\.objects"),
2124
"model.get_object_or_404": re.compile(r"(?P<model_name>\w+)\.get_object_or_404"),
@@ -75,7 +78,7 @@ def find_matches(paths):
7578
for label, regex in TARGETS.items():
7679
if match := regex.search(line):
7780
model_name = match.group("model_name")
78-
if model_name in DENYLISTED_MODELS:
81+
if model_name not in ALLOWLISTED_MODELS:
7982
yield Match(
8083
path=path,
8184
line_number=line_number,

0 commit comments

Comments
 (0)