Skip to content

Commit 51c3ea1

Browse files
committed
move main linters to ruff
1 parent 261dc6e commit 51c3ea1

15 files changed

+90
-76
lines changed

nested_diff/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ class Differ:
101101
def __init__(
102102
self,
103103
A=True, # noqa: N803
104-
N=True,
105-
O=True, # noqa: E741
106-
R=True,
107-
U=True,
108-
trimR=False,
104+
N=True, # noqa: N803
105+
O=True, # noqa: E741 N803
106+
R=True, # noqa: N803
107+
U=True, # noqa: N803
108+
trimR=False, # noqa: N803
109109
dumper=None,
110110
handlers=None,
111111
):

nested_diff/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def run(self):
237237
Raises:
238238
NotImplementedError: Must be implemented in derivatives.
239239
240-
""" # noqa: D406
240+
"""
241241
raise NotImplementedError
242242

243243

@@ -257,7 +257,7 @@ def __init__(self, header='', footer=''):
257257
self.header = header
258258
self.footer = footer
259259

260-
def encode(self, data): # noqa U100
260+
def encode(self, data):
261261
"""Encode data.
262262
263263
Args:
@@ -293,7 +293,7 @@ def dump(self, file_, data):
293293
class Loader:
294294
"""Base class for data loaders."""
295295

296-
def decode(self, data): # noqa U100
296+
def decode(self, data):
297297
"""Decode data.
298298
299299
Args:

nested_diff/diff_tool.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,10 @@ def generate_diffs(self):
7272
if self.args.show:
7373
if len(self.args.files) > 1:
7474
headers_enabled = True
75-
else:
76-
if len(self.args.files) < 2:
77-
self.argparser.error('Two or more arguments expected for diff')
78-
elif len(self.args.files) > 2:
79-
headers_enabled = True
75+
elif len(self.args.files) < 2:
76+
self.argparser.error('Two or more arguments expected for diff')
77+
elif len(self.args.files) > 2:
78+
headers_enabled = True
8079

8180
for file_ in self.args.files:
8281
header = ''
@@ -308,7 +307,7 @@ def encode(self, data):
308307
def get_formatter_class(self, base_class, values='repr'):
309308
"""Return formatter class."""
310309

311-
class __Formatter(base_class):
310+
class _Formatter(base_class):
312311
def __init__(self, *args, **kwargs):
313312
super().__init__(*args, **kwargs)
314313

@@ -328,14 +327,14 @@ def __init__(self, *args, **kwargs):
328327

329328
self.generate_value = self.generate_multiline_value
330329

331-
def generate_empty_value(*args): # noqa U101
330+
def generate_empty_value(*args): # noqa: ARG002
332331
yield ''
333332

334333
def generate_multiline_value(self, value, tag, depth):
335334
for line in self.__val_encoder.encode(value).splitlines():
336335
yield from super().generate_string(line, tag, depth)
337336

338-
return __Formatter
337+
return _Formatter
339338

340339
@staticmethod
341340
def get_opts(opts):

nested_diff/formatters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
for handler in handlers:
9999
self.set_handler(handler)
100100

101-
def format(self, diff, **kwargs): # noqa A003
101+
def format(self, diff, **kwargs):
102102
"""Return formatted diff as string."""
103103
return ''.join(self.generate_diff(diff, **kwargs))
104104

nested_diff/handlers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def diff(self, differ, a, b):
5959

6060
return equal, diff
6161

62-
def patch(self, patcher, target, diff): # noqa U100
62+
def patch(self, patcher, target, diff): # noqa: ARG002
6363
"""Patch object.
6464
6565
Args:
@@ -82,7 +82,7 @@ def patch(self, patcher, target, diff): # noqa U100
8282

8383
raise ValueError(diff)
8484

85-
def iterate_diff(self, iterator, diff): # noqa U100
85+
def iterate_diff(self, iterator, diff): # noqa: ARG002
8686
"""Iterate over nested diff.
8787
8888
Args:
@@ -432,7 +432,7 @@ def patch(self, patcher, target, diff):
432432

433433
return target
434434

435-
def iterate_diff(self, iterator, diff): # noqa U100
435+
def iterate_diff(self, iterator, diff): # noqa: ARG002
436436
"""Iterate over nested diff.
437437
438438
Args:
@@ -443,7 +443,7 @@ def iterate_diff(self, iterator, diff): # noqa U100
443443
Tuples with diff, key and subdiff for each nested diff.
444444
445445
"""
446-
idx = 0 # noqa SIM113
446+
idx = 0
447447

448448
for item in diff['D']:
449449
try:
@@ -457,7 +457,7 @@ def iterate_diff(self, iterator, diff): # noqa U100
457457

458458
def generate_formatted_diff(self, formatter, diff, depth):
459459
"""Generate formatted list diff."""
460-
idx = 0 # noqa SIM113
460+
idx = 0
461461

462462
for subdiff in diff['D']:
463463
try:
@@ -583,7 +583,7 @@ def diff(self, differ, a, b):
583583

584584
return equal, {}
585585

586-
def patch(self, patcher, target, diff): # noqa U100
586+
def patch(self, patcher, target, diff): # noqa: ARG002
587587
"""Patch set object.
588588
589589
Args:
@@ -722,7 +722,7 @@ def diff(self, differ, a, b):
722722

723723
return equal, {'U': a} if differ.op_u else {}
724724

725-
def patch(self, patcher, target, diff): # noqa U100
725+
def patch(self, patcher, target, diff): # noqa: ARG002
726726
"""Patch text (multiline string).
727727
728728
Unlike GNU patch, this algorithm does not implement any heuristics and
@@ -775,7 +775,7 @@ def generate_formatted_diff(self, formatter, diff, depth):
775775

776776
if tag == 'I':
777777
yield from formatter.generate_string(
778-
'@@ -{} +{} @@'.format(
778+
'@@ -{} +{} @@'.format( # noqa: UP032
779779
self._get_hunk_range(value[0], value[1]),
780780
self._get_hunk_range(value[2], value[3]),
781781
),

pyproject.toml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,25 +50,12 @@ cli = [
5050
]
5151
lint = [
5252
'darglint',
53-
'flake8 < 5', # temp workaround (https://github.com/tholo/pytest-flake8/issues/87)
54-
'flake8-builtins',
55-
'flake8-bugbear',
56-
'flake8-commas',
57-
'flake8-comprehensions',
58-
'flake8-docstrings',
59-
'flake8-eradicate',
60-
'flake8-pytest-style',
61-
'flake8_quotes',
62-
'flake8-return',
63-
'flake8-unused-arguments',
64-
'pep8-naming',
65-
'pytest-flake8',
6653
]
6754
test = [
6855
'pytest',
6956
'pytest-cov',
70-
'pytest-ruff',
71-
'ruff==0.3.0', # pin for reproducible results
57+
'pytest-ruff==0.3.2',
58+
'ruff==0.4.10',
7259
]
7360

7461
[project.scripts]
@@ -99,22 +86,57 @@ extend-exclude = [
9986
]
10087
line-length = 79
10188

102-
[tool.ruff.extend-per-file-ignores]
103-
'tests/*' = [
104-
'D', # docstrings
105-
]
106-
10789
[tool.ruff.format]
10890
docstring-code-format = true
10991
quote-style = 'single'
11092

11193
[tool.ruff.lint]
11294
select = [
95+
'A',
96+
'ARG',
97+
'B',
98+
'BLE',
99+
'C4',
100+
'COM',
113101
'D',
114-
'E501',
102+
'DTZ',
103+
'E',
104+
'ERA',
105+
'EXE',
106+
# 'FBT', # TODO
107+
'FLY',
108+
'G',
109+
'ICN',
110+
'ISC',
111+
'LOG',
112+
'N',
113+
'PGH',
114+
'PIE',
115+
'PT',
116+
# 'PL', # TODO
117+
'PLE',
118+
'Q',
119+
'RET',
120+
'RSE',
121+
'RUF',
115122
'SIM',
123+
'SLF',
124+
'TD',
125+
'UP',
126+
'W',
116127
]
117128
ignore = [
118129
'D407', # Missing dashed underline after section
119130
'SIM105', # contextlib.suppress is slower than try-except-pass
120131
]
132+
133+
[tool.ruff.lint.extend-per-file-ignores]
134+
'tests/*' = [
135+
'D', # docstrings
136+
]
137+
138+
[tool.ruff.lint.flake8-quotes]
139+
inline-quotes = 'single'
140+
141+
[tool.ruff.lint.pydocstyle]
142+
convention = 'google'

tests/cli/test_diff_tool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_default_diff_with_tty(capsys, expected, rpath):
4141

4242
def test_diff_method_kwargs_override(capsys, expected, rpath):
4343
class TestApp(nested_diff.diff_tool.App):
44-
def diff(self, a, b, **kwargs): # noqa U100
44+
def diff(self, a, b, **kwargs): # noqa: ARG002
4545
return super().diff(a, b, A=0, U=1)
4646

4747
exit_code = TestApp(
@@ -62,7 +62,7 @@ def diff(self, a, b, **kwargs): # noqa U100
6262
assert captured.out == expected
6363

6464

65-
def test_enable_U_ops(capsys, expected, rpath): # noqa N802
65+
def test_enable_U_ops(capsys, expected, rpath): # noqa: N802
6666
exit_code = nested_diff.diff_tool.App(
6767
args=(
6868
rpath('shared.lists.a.json'),
@@ -82,7 +82,7 @@ def test_enable_U_ops(capsys, expected, rpath): # noqa N802
8282
assert captured.out == expected
8383

8484

85-
def test_trimR_ops(capsys, expected, rpath): # noqa N802
85+
def test_trimR_ops(capsys, expected, rpath): # noqa: N802
8686
exit_code = nested_diff.diff_tool.App(
8787
args=(
8888
rpath('shared.lists.b.json'),
@@ -396,13 +396,13 @@ def test_yaml_ofmt(capsys, expected, rpath):
396396
def test_python_yaml_impl(capsys, expected, rpath):
397397
orig_import = builtins.__import__
398398

399-
def overridden_import(name, globals, locals, fromlist, level): # noqa A002
399+
def overridden_import(name, globals, locals, fromlist, level): # noqa: A002
400400
if name == 'yaml' and fromlist is not None:
401401
for sym in ('CSafeDumper', 'CSafeLoader'):
402402
if sym in fromlist:
403403
raise ImportError(f'Mocked import error for yaml.{sym}')
404404

405-
return orig_import(name, globals, locals, fromlist, level) # noqa A002
405+
return orig_import(name, globals, locals, fromlist, level)
406406

407407
with mock.patch('builtins.__import__', overridden_import):
408408
exit_code = nested_diff.diff_tool.App(
@@ -482,7 +482,7 @@ def test_exit_code_diff_absent(rpath):
482482
assert exit_code == 0
483483

484484

485-
def test_exit_code_diff_absent_U_opt_enabled(rpath): # noqa N802
485+
def test_exit_code_diff_absent_U_opt_enabled(rpath): # noqa: N802
486486
exit_code = nested_diff.diff_tool.App(
487487
args=(
488488
rpath('shared.lists.a.json'),

tests/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def iterate_test_suite(tests_map, results_mod, func):
1818
try:
1919
test['result'] = func(test)
2020
results_map[name] = {'result': test['result']}
21-
except Exception as e:
21+
except Exception as e: # noqa: BLE001
2222
results_map[name] = {
2323
'raises': e if type(e) is type else type(e),
2424
}

tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pytest.register_assert_rewrite('tests.common')
88

99

10-
@pytest.fixture
10+
@pytest.fixture()
1111
def content():
1212
def _reader(filename):
1313
with open(filename) as f:
@@ -16,7 +16,7 @@ def _reader(filename):
1616
return _reader
1717

1818

19-
@pytest.fixture
19+
@pytest.fixture()
2020
def expected(request):
2121
filename = os.path.splitext(request.module.__file__)[0]
2222
filename += f'.{request.function.__name__}.exp'
@@ -25,7 +25,7 @@ def expected(request):
2525
return f.read()
2626

2727

28-
@pytest.fixture
28+
@pytest.fixture()
2929
def rpath(request):
3030
def _path_resolver(filename):
3131
path = os.path.join(
@@ -41,7 +41,7 @@ def _path_resolver(filename):
4141
return _path_resolver
4242

4343

44-
@pytest.fixture
44+
@pytest.fixture()
4545
def stringio():
4646
return StringIO()
4747

@@ -51,6 +51,6 @@ def isatty(self):
5151
return True
5252

5353

54-
@pytest.fixture
54+
@pytest.fixture()
5555
def stringio_tty():
5656
return _StringIOTTY()

tests/data/gen_html_compare.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ def main():
2121

2222
try:
2323
txt = TextFormatter(**fmt_obj_opts).format(diff)
24-
except Exception as e:
25-
txt = f'<div class="error">ERROR: {str(e)}</div>'
24+
except Exception as e: # noqa: BLE001
25+
txt = f'<div class="error">ERROR: {e}</div>'
2626
else:
2727
txt = f'<pre>{html.escape(txt)}</pre>'
2828

2929
try:
3030
htm = HtmlFormatter(**fmt_obj_opts).format(diff)
31-
except Exception as e:
32-
htm = f'<div class="error">ERROR: {str(e)}</div>'
31+
except Exception as e: # noqa: BLE001
32+
htm = f'<div class="error">ERROR: {e}</div>'
3333

3434
print(f'<tr><td colspan=2 class="label">{name}</td></tr>')
3535
print(f'<tr><td>{txt}</td>')

0 commit comments

Comments
 (0)