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 check --fix --unsafe-fixes #1997

Merged
merged 3 commits into from
Nov 23, 2024

Conversation

cclauss
Copy link
Contributor

@cclauss cclauss commented Nov 21, 2024

Autofixes are made with ruff, a radical superset of flake8.

Most of these transformations were documented 23 years ago in the Python style guide PEP8.

% ruff check --statistics | grep "\[\*\]" | sort -k2

 32	E711	[*] none-comparison
537	E712	[*] true-false-comparison
128	E713	[*] not-in-test
  2	E731	[*] lambda-assignment
128	F541	[*] f-string-missing-placeholders
  3	F601	[*] multi-value-repeated-key-literal
[*] fixable with `ruff check --fix`

% ruff check --fix --unsafe-fixes

Found 1294 errors (830 fixed, 464 remaining).

% ruff rule E711

none-comparison (E711)

Derived from the pycodestyle linter.

Fix is always available.

What it does

Checks for comparisons to None which are not using the is operator.

Why is this bad?

According to PEP 8, "Comparisons to singletons like None should always be done with
is or is not, never the equality operators."

Example

if arg != None:
    pass
if None == arg:
    pass

Use instead:

if arg is not None:
    pass

Fix safety

This rule's fix is marked as unsafe, as it may alter runtime behavior when
used with libraries that override the ==/__eq__ or !=/__ne__ operators.
In these cases, is/is not may not be equivalent to ==/!=. For more
information, see this issue.

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

Attention: Patch coverage is 92.03354% with 38 lines in your changes missing coverage. Please review.

Project coverage is 93%. Comparing base (2323594) to head (14704ea).

Files with missing lines Patch % Lines
bbot/modules/base.py 57% 7 Missing ⚠️
bbot/scanner/scanner.py 64% 4 Missing ⚠️
bbot/core/helpers/interactsh.py 0% 3 Missing ⚠️
bbot/modules/internal/excavate.py 77% 3 Missing ⚠️
bbot/core/event/base.py 78% 2 Missing ⚠️
bbot/modules/dnsdumpster.py 0% 2 Missing ⚠️
bbot/test/test_step_1/test_modules_basic.py 96% 2 Missing ⚠️
bbot/core/helpers/depsinstaller/installer.py 75% 1 Missing ⚠️
bbot/core/helpers/dns/engine.py 0% 1 Missing ⚠️
bbot/core/helpers/files.py 0% 1 Missing ⚠️
... and 12 more
Additional details and impacted files
@@          Coverage Diff          @@
##             dev   #1997   +/-   ##
=====================================
- Coverage     93%     93%   -0%     
=====================================
  Files        370     370           
  Lines      28312   28313    +1     
=====================================
- Hits       26133   26118   -15     
- Misses      2179    2195   +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@TheTechromancer
Copy link
Collaborator

TheTechromancer commented Nov 23, 2024

This looks good @cclauss. When you rebase, can you also replace black in a few other places:

  • badge in README.md

Ruff

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
  • pyproject.toml
  • dev_environment.md
  • tests.md

Thanks

@cclauss
Copy link
Contributor Author

cclauss commented Nov 23, 2024

I never have much luck with Poetry so perhaps I made ruff a dependency instead of a dev dependency.

@TheTechromancer
Copy link
Collaborator

I never have much luck with Poetry so perhaps I made ruff a dependency instead of a dev dependency.

Ah yeah you have to do poetry add --group=dev

@TheTechromancer TheTechromancer merged commit 5e8148b into blacklanternsecurity:dev Nov 23, 2024
14 checks passed
@cclauss cclauss deleted the ruff-check--fix branch November 23, 2024 17:21
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.

2 participants