From 05e73c0b6e499a45935fc1c2df7bac8f92c3d36b Mon Sep 17 00:00:00 2001 From: jsfehler Date: Tue, 20 Feb 2024 14:18:39 -0500 Subject: [PATCH] chore: Enable more lint rules (#1247) --- ruff.toml | 72 +++++++++++++++++++++++++++ splinter/driver/__init__.py | 10 ++-- splinter/driver/lxmldriver.py | 4 +- splinter/driver/webdriver/__init__.py | 8 +-- tests/test_djangoclient.py | 2 +- tests/test_flaskclient.py | 2 +- tests/test_zopetestbrowser.py | 2 +- 7 files changed, 86 insertions(+), 14 deletions(-) diff --git a/ruff.toml b/ruff.toml index 87535ac00..d371afe04 100644 --- a/ruff.toml +++ b/ruff.toml @@ -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" diff --git a/splinter/driver/__init__.py b/splinter/driver/__init__.py index 5cbab0a37..3689b8352 100644 --- a/splinter/driver/__init__.py +++ b/splinter/driver/__init__.py @@ -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, @@ -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: @@ -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: diff --git a/splinter/driver/lxmldriver.py b/splinter/driver/lxmldriver.py index d642beb5b..ff31dc0df 100644 --- a/splinter/driver/lxmldriver.py +++ b/splinter/driver/lxmldriver.py @@ -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: @@ -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 diff --git a/splinter/driver/webdriver/__init__.py b/splinter/driver/webdriver/__init__.py index a957aabb8..07fd2ed1a 100644 --- a/splinter/driver/webdriver/__init__.py +++ b/splinter/driver/webdriver/__init__.py @@ -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 @@ -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: @@ -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( diff --git a/tests/test_djangoclient.py b/tests/test_djangoclient.py index b43b84715..dad8e691d 100644 --- a/tests/test_djangoclient.py +++ b/tests/test_djangoclient.py @@ -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(): diff --git a/tests/test_flaskclient.py b/tests/test_flaskclient.py index cb16813e2..b999e09b7 100644 --- a/tests/test_flaskclient.py +++ b/tests/test_flaskclient.py @@ -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(): diff --git a/tests/test_zopetestbrowser.py b/tests/test_zopetestbrowser.py index 1b9770843..aa56af3f5 100644 --- a/tests/test_zopetestbrowser.py +++ b/tests/test_zopetestbrowser.py @@ -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():