Skip to content

Commit

Permalink
chore: Enable more lint rules (#1247)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfehler authored Feb 20, 2024
1 parent 0004201 commit 05e73c0
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 14 deletions.
72 changes: 72 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,74 @@
exclude = ["docs"]
line-length = 120

[lint.mccabe]
max-complexity = 9

[lint]
select = [
"A",
"B",
"BLE",
"C4",
"COM",
"C90",
"DTZ",
"E",
"F",
"ICN",
"N",
"PL",
"PTH",
"RUF",
"S",
"SLOT",
"T20",
"TRY",
"W",
"YTT",
]
ignore = [
"A002",
"B007",
"B009",
"B026",
"B028",
"B904",
"N804",
"N818",
"PLR0913",
"PLR2004",
"PTH123",
"RUF100",
"TRY003",
"TRY300",
]

[lint.per-file-ignores]
"tests/**" = [
"B015",
"B018",
"BLE001",
"C901",
"S101",
"S105",
"S310",
"PLR0911",
"PLW0603",
"PTH100",
"PTH113",
"PTH118",
"PTH120",
"T201",
"TRY002",
]
"samples/**" = [
"S101",
"S106",
"PTH100",
"PTH118",
"PTH120",
]

[lint.pydocstyle]
convention = "google"
10 changes: 5 additions & 5 deletions splinter/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __enter__(self) -> Any:
"%s doesn't support use by 'with' statement." % self.driver_name,
)

def __exit__(self) -> None:
def __exit__(self, exc_type, exc_value, traceback) -> None:
"""Context manager to use the browser safely."""
raise NotImplementedError(
"%s doesn't support use by 'with' statement." % self.driver_name,
Expand Down Expand Up @@ -635,9 +635,9 @@ def is_element_not_present_by_text(

def is_element_present_by_id(
self,
id: str,
id: str, # NOQA: A002
wait_time: Optional[int] = None,
) -> bool: # NOQA: A002
) -> bool:
"""Verify if an element is present in the current page.
Arguments:
Expand All @@ -653,9 +653,9 @@ def is_element_present_by_id(

def is_element_not_present_by_id(
self,
id: str,
id: str, # NOQA: A002
wait_time: Optional[int] = None,
) -> bool: # NOQA: A002
) -> bool:
"""Verify if an element is not present in the current page.
Arguments:
Expand Down
4 changes: 2 additions & 2 deletions splinter/driver/lxmldriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def fill(self, name, value):
)
self.find(name).fill(value)

def fill_form(self, field_values, form_id=None, name=None, ignore_missing=False):
def fill_form(self, field_values, form_id=None, name=None, ignore_missing=False): # NOQA C901
form = None

if name is not None:
Expand Down Expand Up @@ -303,7 +303,7 @@ def fill_form(self, field_values, form_id=None, name=None, ignore_missing=False)
control.value = value
except ElementDoesNotExist as e:
if not ignore_missing:
raise ElementDoesNotExist(e)
raise ElementDoesNotExist(e) # NOQA: TRY200

def choose(self, name, value):
self.find_by_name(name).first._control.value = value
Expand Down
8 changes: 4 additions & 4 deletions splinter/driver/webdriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def __getitem__(self, key):
window_handles = self._browser.driver.window_handles
try:
return Window(self._browser, window_handles[key])
except TypeError:
except TypeError as err:
if key not in window_handles:
raise KeyError(key)
raise KeyError(key) from err
return Window(self._browser, key)

@property
Expand Down Expand Up @@ -552,7 +552,7 @@ def fill(self, name, value):

attach_file = fill

def fill_form(self, field_values, form_id=None, name=None, ignore_missing=False):
def fill_form(self, field_values, form_id=None, name=None, ignore_missing=False): # NOQA C901
form = None

if name is not None:
Expand Down Expand Up @@ -584,7 +584,7 @@ def fill_form(self, field_values, form_id=None, name=None, ignore_missing=False)
element.value = value
except ElementDoesNotExist as e:
if not ignore_missing:
raise ElementDoesNotExist(e)
raise ElementDoesNotExist(e) # NOQA: TRY200

def type(self, name, value, slowly=False): # NOQA: A003
warnings.warn(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_djangoclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_finding_all_links_by_non_ascii_text(self):
non_ascii_encodings = {
"pangram_pl": "Jeżu klątw, spłódź Finom część gry hańb!",
"pangram_ja": "天 地 星 空",
"pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!",
"pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", # NOQA RUF001
"pangram_eo": "Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.",
}
for key, text in non_ascii_encodings.items():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flaskclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def test_finding_all_links_by_non_ascii_text(self):
non_ascii_encodings = {
"pangram_pl": "Jeżu klątw, spłódź Finom część gry hańb!",
"pangram_ja": "天 地 星 空",
"pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!",
"pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", # NOQA RUF001
"pangram_eo": "Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.",
}
for key, text in non_ascii_encodings.items():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_zopetestbrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_finding_all_links_by_non_ascii_text(self):
non_ascii_encodings = {
"pangram_pl": "Jeżu klątw, spłódź Finom część gry hańb!",
"pangram_ja": "天 地 星 空",
"pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!",
"pangram_ru": "В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!", # NOQA RUF001
"pangram_eo": "Laŭ Ludoviko Zamenhof bongustas freŝa ĉeĥa manĝaĵo kun spicoj.",
}
for key, text in non_ascii_encodings.items():
Expand Down

0 comments on commit 05e73c0

Please sign in to comment.