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

Fix ruff rules FAST002,FLY002,N805,RSE102,RUF019,RUF022 #2038

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@
scan_name = ""


async def _main():
async def _main(): # noqa: C901,PLR0911,PLR0915
"""
Future modifications should consider refactoring to reduce complexity.
* The McCabe cyclomatiic complexity is currently 43 vs 10 recommended.
* There are currently 13 return statements vs 6 recommended.
* There are currently 148 statements vs 50 recommended.
"""
import asyncio
import traceback
from contextlib import suppress
Expand Down
2 changes: 1 addition & 1 deletion bbot/core/helpers/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ def clean_old(d, keep=10, filter=lambda x: True, key=latest_mtime, reverse=True,
except Exception as e:
msg = f"Failed to delete directory: {path}, {e}"
if raise_error:
raise errors.DirectoryDeletionError()
raise errors.DirectoryDeletionError
log.warning(msg)


Expand Down
6 changes: 5 additions & 1 deletion bbot/core/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def find_and_replace(self, **kwargs):
def check_type(self, module, type):
return self._preloaded[module]["type"] == type

def preload_module(self, module_file):
def preload_module(self, module_file): # noqa: C901,PLR0912
"""
Preloads a BBOT module to gather its meta-information and dependencies.

Expand Down Expand Up @@ -315,6 +315,10 @@ def preload_module(self, module_file):
},
"sudo": false
}

Future modifications should consider refactoring to reduce complexity.
* The McCabe cyclomatiic complexity is currently 43 vs 10 recommended.
* There are currently 42 branches vs 12 recommended.
"""
watched_events = set()
produced_events = set()
Expand Down
2 changes: 1 addition & 1 deletion bbot/modules/bucket_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def build_url(self, bucket_name, base_domain, region):
async def check_bucket_open(self, bucket_name, url):
bad_permissions = []
try:
list_permissions = "&".join(["=".join(("permissions", p)) for p in self.bad_permissions])
list_permissions = "&".join(f"permissions={p}" for p in self.bad_permissions)
url = f"https://www.googleapis.com/storage/v1/b/{bucket_name}/iam/testPermissions?" + list_permissions
response = await self.helpers.request(url)
permissions = response.json()
Expand Down
2 changes: 1 addition & 1 deletion bbot/modules/docker_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class docker_pull(BaseModule):

async def setup(self):
self.headers = {
"Accept": ",".join(
"Accept": ",".join( # noqa: FLY002
[
"application/vnd.docker.distribution.manifest.v2+json",
"application/vnd.docker.distribution.manifest.list.v2+json",
Expand Down
2 changes: 1 addition & 1 deletion bbot/modules/filedownload.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def setup(self):
with open(self.mime_db_file) as f:
mime_db = json.load(f)
for content_type, attrs in mime_db.items():
if "extensions" in attrs and attrs["extensions"]:
if attrs.get("extensions"):
self.mime_db[content_type] = attrs["extensions"][0].lower()
return True

Expand Down
2 changes: 1 addition & 1 deletion bbot/modules/url_manipulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def handle_event(self, event):

try:
if not await compare_helper.canary_check(event.data, mode="getparam"):
raise HttpCompareError()
raise HttpCompareError
except HttpCompareError:
self.verbose(f'Aborting "{event.data}" due to failed canary check')
return
Expand Down
2 changes: 1 addition & 1 deletion bbot/scanner/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def get_incoming_event(self):
return q.get_nowait()
except (asyncio.queues.QueueEmpty, AttributeError):
continue
raise asyncio.queues.QueueEmpty()
raise asyncio.queues.QueueEmpty

def is_incoming_duplicate(self, event, add=False):
"""
Expand Down
4 changes: 2 additions & 2 deletions bbot/test/fastapi_test.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import List
from typing import Annotated, List
from bbot import Scanner
from fastapi import FastAPI, Query

app = FastAPI()


@app.get("/start")
async def start(targets: List[str] = Query(...)):
async def start(targets: Annotated[List[str], Query(...)]):
scanner = Scanner(*targets, modules=["httpx"])
events = [e async for e in scanner.async_start()]
return [e.json() for e in events]
Expand Down
2 changes: 1 addition & 1 deletion bbot/test/test_step_2/module_tests/test_module_baddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BaseTestBaddns(ModuleTestBase):
targets = ["bad.dns"]
config_overrides = {"dns": {"minimal": False}}

async def dispatchWHOIS(x):
async def dispatchWHOIS(self):
return None

def select_modules(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BaseTestBaddns_zone(ModuleTestBase):
targets = ["bad.dns"]
config_overrides = {"dns": {"minimal": False}}

async def dispatchWHOIS(x):
async def dispatchWHOIS(self):
return None


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .base import ModuleTestBase
from bbot.core.helpers.misc import rand_string

__all__ = ["random_bucket_name_1", "random_bucket_name_2", "random_bucket_name_3", "Bucket_Amazon_Base"]
__all__ = ["Bucket_Amazon_Base", "random_bucket_name_1", "random_bucket_name_2", "random_bucket_name_3"]

# first one is a normal bucket
random_bucket_name_1 = rand_string(15, digits=False)
Expand Down
4 changes: 2 additions & 2 deletions bbot/test/test_step_2/module_tests/test_module_neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def setup_before_prep(self, module_test):
self.neo4j_used = False

class MockResult:
async def data(s):
async def data(s): # noqa: N805
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does changing s to self cause this test to fail?

self.neo4j_used = True
return [
{
Expand All @@ -22,7 +22,7 @@ async def data(s):
]

class MockSession:
async def run(s, *args, **kwargs):
async def run(self, *args, **kwargs):
return MockResult()

async def close(self):
Expand Down
77 changes: 76 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,82 @@ skip = "./docs/javascripts/vega*.js,./bbot/wordlists/*"
[tool.ruff]
line-length = 119
format.exclude = ["bbot/test/test_step_1/test_manager_*"]
lint.ignore = ["E402", "E721", "E741", "F401", "F403", "F405"]

[tool.ruff.lint]
ignore = ["E402", "E501", "E721", "E741", "F401", "F403", "F405"]
mccabe.max-complexity = 31
select = [
"AIR", # Airflow
"C4", # flake8-comprehensions
"C90", # McCabe cyclomatic complexity
"DJ", # flake8-django
"E", # pycodestyle
"F", # Pyflakes
"FAST", # FastAPI
"FLY", # flynt
"ICN", # flake8-import-conventions
"INT", # flake8-gettext
"LOG", # flake8-logging
"NPY", # NumPy-specific rules
"PD", # pandas-vet
"PLR091", # Pylint Refactor just for max-args, max-branches, etc.
"PYI", # flake8-pyi
"RSE", # flake8-raise
"SLOT", # flake8-slots
"T10", # flake8-debugger
"TC", # flake8-type-checking
"W", # pycodestyle
"YTT", # flake8-2020
# "A", # flake8-builtins
# "ANN", # flake8-annotations
# "ARG", # flake8-unused-arguments
# "ASYNC", # flake8-async
# "B", # flake8-bugbear
# "BLE", # flake8-blind-except
# "COM", # flake8-commas
# "CPY", # flake8-copyright
# "D", # pydocstyle
# "DOC", # pydoclint
# "DTZ", # flake8-datetimez
# "EM", # flake8-errmsg
# "ERA", # eradicate
# "EXE", # flake8-executable
# "FA", # flake8-future-annotations
# "FBT", # flake8-boolean-trap
# "FIX", # flake8-fixme
# "FURB", # refurb
# "G", # flake8-logging-format
# "I", # isort
# "INP", # flake8-no-pep420
# "ISC", # flake8-implicit-str-concat
# "N", # pep8-naming
# "PERF", # Perflint
# "PGH", # pygrep-hooks
# "PIE", # flake8-pie
# "PL", # Pylint
# "PT", # flake8-pytest-style
# "PTH", # flake8-use-pathlib
# "Q", # flake8-quotes
# "RET", # flake8-return
# "RUF", # Ruff-specific rules
# "S", # flake8-bandit
# "SIM", # flake8-simplify
# "SLF", # flake8-self
# "T20", # flake8-print
# "TD", # flake8-todos
# "TID", # flake8-tidy-imports
# "TRY", # tryceratops
# "UP", # pyupgrade
]

[tool.ruff.lint.per-file-ignores]
"bbot/test/test_step_1/test_*" = ["PLR0915"]

[tool.ruff.lint.pylint]
max-args = 21 # Default is 5
max-branches = 31 # Default is 12
max-returns = 10 # Default is 6
max-statements = 100 # Default is 50

[tool.poetry-dynamic-versioning]
enable = true
Expand Down
Loading