Skip to content

Commit 4068880

Browse files
committed
Add new lint rules
1 parent c89e1e3 commit 4068880

4 files changed

Lines changed: 16 additions & 14 deletions

File tree

cssselect2/tree.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,14 +305,14 @@ def etree_children(self):
305305
def local_name(self):
306306
"""The local name of this element, as a string."""
307307
namespace_url, local_name = _split_etree_tag(self.etree_element.tag)
308-
self.__dict__[str('namespace_url')] = namespace_url
308+
self.__dict__['namespace_url'] = namespace_url
309309
return local_name
310310

311311
@cached_property
312312
def namespace_url(self):
313313
"""The namespace URL of this element, as a string."""
314314
namespace_url, local_name = _split_etree_tag(self.etree_element.tag)
315-
self.__dict__[str('local_name')] = local_name
315+
self.__dict__['local_name'] = local_name
316316
return namespace_url
317317

318318
@cached_property

docs/example.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@
3434
wrapper = cssselect2.ElementWrapper.from_html_root(html_tree)
3535
for element in wrapper.iter_subtree():
3636
tag = element.etree_element.tag.split('}')[-1]
37-
print('Found tag "{}" in HTML'.format(tag))
37+
print(f'Found tag "{tag}" in HTML')
3838

3939
matches = matcher.match(element)
4040
if matches:
4141
for match in matches:
4242
specificity, order, pseudo, payload = match
4343
selector_string, content_string = payload
44-
print('Matching selector "{}" ({})'.format(
45-
selector_string, content_string))
44+
print(f'Matching selector "{selector_string}" ({content_string})')
4645
else:
4746
print('No rule matching this tag')
4847
print()

pyproject.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ exclude_lines = ['pragma: no cover', 'def __repr__', 'raise NotImplementedError'
5555
omit = ['.*']
5656

5757
[tool.ruff.lint]
58-
select = ['E', 'W', 'F', 'I', 'N', 'RUF']
58+
select = ['E', 'W', 'F', 'I', 'N', 'RUF', 'T20', 'PIE', 'PT', 'RSE', 'UP', 'Q']
5959
ignore = ['RUF001', 'RUF002', 'RUF003']
6060

61+
[tool.ruff.lint.flake8-quotes]
62+
inline-quotes = 'single'
63+
multiline-quotes = 'single'
64+
6165
[tool.ruff.lint.extend-per-file-ignores]
62-
'docs/example.py' = ['I001']
66+
'docs/example.py' = ['I001', 'T201']

tests/test_cssselect2.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def test_lang():
119119
assert not root.matches(':lang(en)')
120120

121121

122-
@pytest.mark.parametrize('selector, result', (
122+
@pytest.mark.parametrize(('selector', 'result'), [
123123
('*', ALL_IDS),
124124
('div', ['outer-div', 'li-div', 'foobar-div']),
125125
('div div', ['li-div']),
@@ -228,7 +228,6 @@ def test_lang():
228228
('*#first-li', ['first-li']),
229229
('li div', ['li-div']),
230230
('li > div', ['li-div']),
231-
('div div', ['li-div']),
232231
('div > div', []),
233232
('div>.c', ['first-ol']),
234233
('div > .c', ['first-ol']),
@@ -320,7 +319,7 @@ def test_lang():
320319
('/* test */a:not([href])/* test */,div div', ['name-anchor', 'li-div']),
321320
('/* test */ a:not([href]), div/* test */ div', ['name-anchor', 'li-div']),
322321
('a:not([href]) /* test */,/* test */div div', ['name-anchor', 'li-div']),
323-
))
322+
])
324323
def test_select(selector, result):
325324
xml_ids = [
326325
element.etree_element.get('id', 'nil') for element in
@@ -331,12 +330,12 @@ def test_select(selector, result):
331330
assert xml_ids == html_ids == result
332331

333332

334-
@pytest.mark.parametrize('selector, result', (
333+
@pytest.mark.parametrize(('selector', 'result'), [
335334
('DIV', ['outer-div', 'li-div', 'foobar-div']),
336335
('a[NAme]', ['name-anchor']),
337336
('HTML :link', [
338337
'link-href', 'tag-anchor', 'nofollow-anchor', 'area-href']),
339-
))
338+
])
340339
def test_html_select(selector, result):
341340
assert not [
342341
element.etree_element.get('id', 'nil') for element in
@@ -347,7 +346,7 @@ def test_html_select(selector, result):
347346

348347

349348
# Data borrowed from http://mootools.net/slickspeed/
350-
@pytest.mark.parametrize('selector, result', (
349+
@pytest.mark.parametrize(('selector', 'result'), [
351350
# Changed from original because we’re only searching the body.
352351
# ('*', 252),
353352
('*', 246),
@@ -396,6 +395,6 @@ def test_html_select(selector, result):
396395
('div[class|=dialog]', 50), # ? Seems right
397396
# assert count('div[class!=madeup]', 243), # ? Seems right
398397
('div[class~=dialog]', 51), # ? Seems right
399-
))
398+
])
400399
def test_select_shakespeare(selector, result):
401400
assert sum(1 for _ in SHAKESPEARE_BODY.query_all(selector)) == result

0 commit comments

Comments
 (0)