Skip to content

Commit

Permalink
Merge pull request #10 from leukeleu/admin-url-false-positive
Browse files Browse the repository at this point in the history
Fix W007 false positives for catch all routes
  • Loading branch information
jaap3 authored Sep 29, 2022
2 parents 20560ec + b902479 commit 956fbc2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions leukeleu_django_checks/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,12 @@ def check_admin_url(app_configs, **kwargs):
"""
for path in ["/admin", "/admin/"]:
try:
resolve(path)
match = resolve(path)
except Resolver404:
continue
else:
return [W007]
if match.route.strip("/") == "admin":
return [W007]
else:
return []

Expand Down
5 changes: 3 additions & 2 deletions tests/urls/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.http import HttpResponse
from django.urls import path
from django.urls import path, re_path

urlpatterns = [
# pragma: no cover
path("not-admin/", lambda request: HttpResponse("Hello regular user!"))
path("not-admin/", lambda request: HttpResponse("Hello regular user!")),
re_path(r"(?P<name>\w+)/", lambda request, name: HttpResponse(f"Hello {name}!")),
]

0 comments on commit 956fbc2

Please sign in to comment.