Skip to content

Commit 2578a33

Browse files
k-ibarakiclaude
andcommitted
feat(lint): Add automatic detection for function-level imports
Add ruff PLC (pylint conventions) rule to automatically detect function-level imports, which violates PEP 8 guidelines. Changes: - Add PLC rule group to ruff select (includes PLC0415: import-outside-toplevel) - Move urllib.parse import to top-level in src/sharepoint_auth.py - Exclude PLC0415 from tests/** for legitimate test isolation needs (e.g., config reload, mock ordering) This prevents future violations like the one caught by Gemini Code Assist. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 71e4687 commit 2578a33

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

pyproject.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,14 @@ target-version = "py312"
7272

7373
[tool.ruff.lint]
7474
select = [
75-
"E", # pycodestyle errors
76-
"W", # pycodestyle warnings
77-
"F", # pyflakes
78-
"I", # isort
79-
"B", # flake8-bugbear
80-
"C4", # flake8-comprehensions
81-
"UP", # pyupgrade
75+
"E", # pycodestyle errors
76+
"W", # pycodestyle warnings
77+
"F", # pyflakes
78+
"I", # isort
79+
"B", # flake8-bugbear
80+
"C4", # flake8-comprehensions
81+
"UP", # pyupgrade
82+
"PLC", # pylint conventions (includes PLC0415: import-outside-toplevel)
8283
]
8384
ignore = [
8485
"E501", # line too long, handled by black
@@ -89,6 +90,7 @@ ignore = [
8990

9091
[tool.ruff.lint.per-file-ignores]
9192
"__init__.py" = ["F401"]
93+
"tests/**/*.py" = ["PLC0415"] # Allow function-level imports in tests for mocking/isolation
9294

9395
[tool.ruff.format]
9496
quote-style = "double"

src/sharepoint_auth.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time
88
import uuid
99
from pathlib import Path
10+
from urllib.parse import urlparse
1011

1112
import jwt
1213
import requests
@@ -132,8 +133,6 @@ def _request_access_token(self) -> dict[str, str]:
132133
)
133134

134135
# SharePointサイトのテナント名を取得
135-
from urllib.parse import urlparse
136-
137136
parsed_url = urlparse(self.site_url)
138137
tenant_name = parsed_url.netloc.split(".sharepoint.com")[0]
139138
scope = f"https://{tenant_name}.sharepoint.com/.default"

0 commit comments

Comments
 (0)