Skip to content

Commit 57eb02e

Browse files
authored
refactor: enable simplification linter (#56)
1 parent 366d918 commit 57eb02e

File tree

5 files changed

+21
-26
lines changed

5 files changed

+21
-26
lines changed

pyproject.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,6 @@ sequence = [
7575

7676
# Other tools
7777

78-
[tool.black]
79-
line-length = 79
80-
include = '\.py$'
81-
8278
[tool.coverage.run]
8379
branch = true
8480
command_line = "-m pytest"
@@ -98,8 +94,8 @@ log_level = "DEBUG"
9894
line-length = 79
9995

10096
[tool.ruff.lint]
101-
select = ["D", "E", "F", "I"]
102-
ignore = ["D102", "D103", "D105", "D107", "D415"]
97+
select = ["D", "E", "F", "I", "N", "PL", "RUF", "SIM"]
98+
ignore = ["D102", "D103", "D105", "D107", "D415", "PLR2004"]
10399

104100
[tool.ruff.lint.isort]
105101
force-sort-within-sections = true

src/git_draft/__main__.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -147,27 +147,26 @@ def on_delete_file(self, path: PurePosixPath, _reason: str | None) -> None:
147147
def edit(*, path: Path | None = None, text: str | None = None) -> str:
148148
if sys.stdin.isatty():
149149
return open_editor(text or "", path)
150+
# We exit with a custom code to allow the caller to act accordingly.
151+
# For example we can handle this from Vim by opening the returned path
152+
# or text in a buffer, to then continue to another command on save.
153+
# https://unix.stackexchange.com/q/604260
154+
elif path is None:
155+
assert text, "Empty path and text"
156+
print(text)
157+
sys.exit(198)
150158
else:
151-
# We exit with a custom code to allow the caller to act accordingly.
152-
# For example we can handle this from Vim by opening the returned path
153-
# or text in a buffer, to then continue to another command on save.
154-
# https://unix.stackexchange.com/q/604260
155-
if path is None:
156-
assert text, "Empty path and text"
157-
print(text)
158-
sys.exit(198)
159-
else:
160-
if text is not None:
161-
with open(path, "w") as f:
162-
f.write(text)
163-
print(path)
164-
sys.exit(199)
159+
if text is not None:
160+
with open(path, "w") as f:
161+
f.write(text)
162+
print(path)
163+
sys.exit(199)
165164

166165

167166
_PROMPT_PLACEHOLDER = "Enter your prompt here..."
168167

169168

170-
def main() -> None:
169+
def main() -> None: # noqa: PLR0912 PLR0915
171170
config = Config.load()
172171
(opts, args) = new_parser().parse_args()
173172

src/git_draft/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import string
1212
import textwrap
1313
import tomllib
14-
from typing import Any, Mapping, Self, Sequence, Type
14+
from typing import Any, ClassVar, Mapping, Self, Sequence, Type
1515

1616
import prettytable
1717
import xdg_base_dirs
@@ -104,7 +104,7 @@ def qualified_class_name(cls: Type) -> str:
104104
class Table:
105105
"""Pretty-printable table"""
106106

107-
_kwargs = dict(border=False) # Shared options
107+
_kwargs: ClassVar[Mapping[str, Any]] = dict(border=False) # Shared options
108108

109109
def __init__(self, data: prettytable.PrettyTable) -> None:
110110
self.data = data

src/git_draft/drafter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def create(cls, store: Store, path: str | None = None) -> Drafter:
7373
except git.NoSuchPathError:
7474
raise ValueError(f"No git repository at {path}")
7575

76-
def generate_draft(
76+
def generate_draft( # noqa: PLR0913
7777
self,
7878
prompt: str | TemplatedPrompt,
7979
bot: Bot,
@@ -126,7 +126,7 @@ def generate_draft(
126126
# Trigger code generation.
127127
_logger.debug("Running bot... [bot=%s]", bot)
128128
operation_recorder = _OperationRecorder()
129-
tool_visitors = [operation_recorder] + list(tool_visitors or [])
129+
tool_visitors = [operation_recorder, *list(tool_visitors or [])]
130130
toolbox = StagingToolbox(self._repo, tool_visitors)
131131
start_time = time.perf_counter()
132132
goal = Goal(prompt_contents, timeout)

src/git_draft/store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def cursor(self) -> Iterator[sqlite3.Cursor]:
3838
with contextlib.closing(self._connection.cursor()) as cursor:
3939
try:
4040
yield cursor
41-
except: # noqa
41+
except:
4242
self._connection.rollback()
4343
raise
4444
else:

0 commit comments

Comments
 (0)