Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff rules: Stricter code quality rules #438

Merged
merged 11 commits into from
Aug 20, 2023
Merged

Ruff rules: Stricter code quality rules #438

merged 11 commits into from
Aug 20, 2023

Conversation

tony
Copy link
Member

@tony tony commented Jul 8, 2023

Docs:

Adds:

  • "E", # pycodestyle
  • "F", # pyflakes
  • "I", # isort
  • "UP", # pyupgrade
  • "B", # flake8-bugbear
  • "C4", # flake8-comprehensions
  • "Q", # flake8-quotes
  • "PTH", # flake8-use-pathlib
  • "ERA", # eradicate
  • "SIM", # flake8-simplify
  • "TRY", # Trycertatops
  • "PERF", # Perflint
  • "RUF" # Ruff-specific rules

See also: vcs-python/vcspull#417

@tony tony force-pushed the ruff-rules branch 2 times, most recently from 0e64bb6 to b66da15 Compare August 11, 2023 23:19
@tony tony force-pushed the ruff-rules branch 9 times, most recently from 8c6bfb8 to b0dfa5b Compare August 20, 2023 15:36
src/libvcs/pytest_plugin.py:176:19: TRY002 Create your own exception
src/libvcs/pytest_plugin.py:176:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/pytest_plugin.py:210:34: B006 [*] Do not use mutable data structures for argument defaults
src/libvcs/pytest_plugin.py:234:38: B006 [*] Do not use mutable data structures for argument defaults
src/libvcs/_internal/query_list.py:87:9: TRY300 Consider moving this statement to an `else` block
src/libvcs/_internal/query_list.py:119:9: SIM102 Use a single `if` statement instead of nested `if` statements
src/libvcs/_internal/query_list.py:451:19: TRY002 Create your own exception
src/libvcs/_internal/query_list.py:451:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/_internal/query_list.py:489:25: TRY301 Abstract `raise` to an inner function
src/libvcs/_internal/query_list.py:489:31: TRY003 Avoid specifying long messages outside the exception class
Fixed 105 errors:
- conftest.py:
     1 × UP006 (non-pep585-annotation)
- docs/conf.py:
     1 × RUF100 (unused-noqa)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × I001 (unsorted-imports)
- src/libvcs/_internal/query_list.py:
     6 × ERA001 (commented-out-code)
     1 × SIM118 (in-dict-keys)
- src/libvcs/_internal/run.py:
     3 × ERA001 (commented-out-code)
- src/libvcs/_internal/types.py:
     1 × RUF100 (unused-noqa)
- src/libvcs/cmd/git.py:
     8 × RUF005 (collection-literal-concatenation)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × SIM102 (collapsible-if)
- src/libvcs/cmd/hg.py:
     1 × SIM108 (if-else-block-instead-of-if-exp)
- src/libvcs/cmd/svn.py:
     2 × UP006 (non-pep585-annotation)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × F401 (unused-import)
- src/libvcs/sync/base.py:
     1 × UP031 (printf-string-formatting)
     1 × UP032 (f-string)
- src/libvcs/sync/git.py:
     1 × UP031 (printf-string-formatting)
     1 × SIM102 (collapsible-if)
     1 × ERA001 (commented-out-code)
     1 × SIM108 (if-else-block-instead-of-if-exp)
- src/libvcs/sync/hg.py:
     1 × RUF100 (unused-noqa)
- src/libvcs/sync/svn.py:
     1 × RUF100 (unused-noqa)
     1 × ERA001 (commented-out-code)
     1 × SIM108 (if-else-block-instead-of-if-exp)
     1 × B007 (unused-loop-control-variable)
- src/libvcs/url/git.py:
     1 × RUF100 (unused-noqa)
     1 × C416 (unnecessary-comprehension)
     1 × B010 (set-attr-with-constant)
- src/libvcs/url/hg.py:
     1 × RUF100 (unused-noqa)
     1 × B010 (set-attr-with-constant)
- src/libvcs/url/registry.py:
     6 × UP006 (non-pep585-annotation)
- src/libvcs/url/svn.py:
     2 × RUF100 (unused-noqa)
     1 × ERA001 (commented-out-code)
     1 × B010 (set-attr-with-constant)
- tests/_internal/test_query_list.py:
    28 × C408 (unnecessary-collection-call)
     2 × SIM300 (yoda-conditions)
- tests/sync/test_base.py:
     2 × SIM300 (yoda-conditions)
     1 × RUF010 (explicit-f-string-type-conversion)
- tests/sync/test_git.py:
     3 × SIM300 (yoda-conditions)
     1 × C416 (unnecessary-comprehension)
     1 × I001 (unsorted-imports)
- tests/test_pytest_plugin.py:
     1 × ERA001 (commented-out-code)
     1 × RUF015 (unnecessary-iterable-allocation-for-first-element)
- tests/url/test_git.py:
     1 × ERA001 (commented-out-code)
- tests/url/test_hg.py:
     1 × ERA001 (commented-out-code)
- tests/url/test_registry.py:
     3 × UP006 (non-pep585-annotation)
     1 × B007 (unused-loop-control-variable)
- tests/url/test_svn.py:
     1 × ERA001 (commented-out-code)
@codecov
Copy link

codecov bot commented Aug 20, 2023

Codecov Report

Merging #438 (e16a5d4) into master (ee67166) will increase coverage by 0.34%.
The diff coverage is 58.26%.

@@            Coverage Diff             @@
##           master     #438      +/-   ##
==========================================
+ Coverage   62.18%   62.52%   +0.34%     
==========================================
  Files          39       39              
  Lines        3403     3437      +34     
  Branches      936      928       -8     
==========================================
+ Hits         2116     2149      +33     
- Misses        765      771       +6     
+ Partials      522      517       -5     
Files Changed Coverage Δ
conftest.py 100.00% <ø> (ø)
src/libvcs/_internal/run.py 81.25% <ø> (ø)
src/libvcs/_internal/types.py 100.00% <ø> (ø)
src/libvcs/sync/base.py 83.82% <ø> (ø)
src/libvcs/sync/hg.py 100.00% <ø> (ø)
tests/_internal/test_query_list.py 72.72% <ø> (ø)
tests/test_exc.py 100.00% <ø> (ø)
tests/url/test_git.py 100.00% <ø> (ø)
tests/url/test_hg.py 100.00% <ø> (ø)
tests/url/test_svn.py 100.00% <ø> (ø)
... and 19 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

docs/conf.py:208:9: PERF203 `try`-`except` within a loop incurs performance overhead
src/libvcs/_internal/shortcuts.py:108:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/_internal/shortcuts.py:108:19: F821 Undefined name `LibVCSException`
src/libvcs/_internal/shortcuts.py:110:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/_internal/shortcuts.py:110:19: F821 Undefined name `LibVCSException`
src/libvcs/_internal/shortcuts.py:120:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/_internal/subprocess.py:437:15: TRY002 Create your own exception
src/libvcs/_internal/subprocess.py:437:15: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/cmd/svn.py:822:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/sync/git.py:143:19: TRY002 Create your own exception
src/libvcs/sync/git.py:143:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/sync/git.py:275:19: TRY002 Create your own exception
src/libvcs/sync/git.py:275:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/sync/git.py:385:13: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:410:23: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/sync/git.py:439:13: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:447:17: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:459:21: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:465:17: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:473:21: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:480:21: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:498:25: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:498:25: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:509:17: TRY400 Use `logging.exception` instead of `logging.error`
src/libvcs/sync/git.py:589:19: TRY002 Create your own exception
src/libvcs/sync/git.py:589:19: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/sync/git.py:676:23: TRY002 Create your own exception
src/libvcs/sync/git.py:676:23: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/sync/svn.py:107:12: PTH110 `os.path.exists()` should be replaced by `Path.exists()`
src/libvcs/sync/svn.py:107:45: PTH112 `os.path.isdir()` should be replaced by `Path.is_dir()`
src/libvcs/sync/svn.py:118:26: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
src/libvcs/sync/svn.py:119:20: PTH110 `os.path.exists()` should be replaced by `Path.exists()`
src/libvcs/sync/svn.py:159:24: PTH118 `os.path.join()` should be replaced by `Path` with `/` operator
src/libvcs/sync/svn.py:160:12: PTH110 `os.path.exists()` should be replaced by `Path.exists()`
src/libvcs/sync/svn.py:161:18: PTH123 `open()` should be replaced by `Path.open()`
src/libvcs/sync/svn.py:175:23: TRY003 Avoid specifying long messages outside the exception class
src/libvcs/url/git.py:291:20: B007 Loop control variable `v` not used within loop body
src/libvcs/url/hg.py:220:20: B007 Loop control variable `v` not used within loop body
src/libvcs/url/svn.py:204:20: B007 Loop control variable `v` not used within loop body
tests/sync/test_git.py:110:12: PTH110 `os.path.exists()` should be replaced by `Path.exists()`
tests/sync/test_hg.py:55:10: B017 `pytest.raises(Exception)` should be considered evil
tests/sync/test_svn.py:29:12: PTH110 `os.path.exists()` should be replaced by `Path.exists()`
tests/test_exc.py:12:15: TRY003 Avoid specifying long messages outside the exception class
tests/test_exc.py:38:15: TRY003 Avoid specifying long messages outside the exception class
@tony tony merged commit 1eb1259 into master Aug 20, 2023
6 checks passed
@tony tony deleted the ruff-rules branch August 20, 2023 16:24
tony added a commit that referenced this pull request Aug 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant