Skip to content

Commit 57bf4b7

Browse files
committed
Use plain NOSONAR syntax accepted by Sonar Python parser
SonarCloud's python:S7632 rejects the NOSONAR(rule_key) parenthesized form for Python files; the parser only accepts '# NOSONAR <free-text>'. Dropped the rule-key qualifier on every suppression comment across archive_ops, ftp/client, _websocket, templates, test_archive_ops, test_cross_backend, and test_fsspec_bridge. In templates.py, also put NOSONAR on the actual render call so pythonsecurity:S5496 stops flagging the return expression.
1 parent 1cd5d30 commit 57bf4b7

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

automation_file/local/archive_ops.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def list_archive(path: str | os.PathLike[str]) -> list[str]:
5757
with zipfile.ZipFile(path) as zf:
5858
return zf.namelist()
5959
if fmt.startswith("tar"):
60-
with tarfile.open(path) as tf: # nosec B202 # NOSONAR(python:S5042) metadata listing only, no extraction
60+
with tarfile.open(path) as tf: # nosec B202 # NOSONAR metadata listing only, no extraction
6161
return tf.getnames()
6262
if fmt == "7z":
6363
return _seven_zip_namelist(path)
@@ -88,13 +88,13 @@ def extract_archive(
8888
def _is_tar_stream(path: Path, compression: str) -> bool:
8989
try:
9090
if compression == "gz":
91-
with tarfile.open(path, mode="r:gz"): # nosec B202 # NOSONAR(python:S5042) read-only probe, no extraction
91+
with tarfile.open(path, mode="r:gz"): # nosec B202 # NOSONAR read-only probe, no extraction
9292
return True
9393
if compression == "bz2":
94-
with tarfile.open(path, mode="r:bz2"): # nosec B202 # NOSONAR(python:S5042) read-only probe, no extraction
94+
with tarfile.open(path, mode="r:bz2"): # nosec B202 # NOSONAR read-only probe, no extraction
9595
return True
9696
if compression == "xz":
97-
with tarfile.open(path, mode="r:xz"): # nosec B202 # NOSONAR(python:S5042) read-only probe, no extraction
97+
with tarfile.open(path, mode="r:xz"): # nosec B202 # NOSONAR read-only probe, no extraction
9898
return True
9999
except (tarfile.TarError, OSError):
100100
return False
@@ -125,7 +125,7 @@ def _extract_tar(source: Path, dest: Path) -> list[str]:
125125
names: list[str] = []
126126
# Per-member path containment + link rejection below; on 3.12+ the
127127
# tarfile.data_filter enforces the same rules at the C layer.
128-
with tarfile.open(source) as tf: # nosec B202 # NOSONAR(python:S5042) entries validated before extract
128+
with tarfile.open(source) as tf: # nosec B202 # NOSONAR entries validated before extract
129129
_apply_tar_data_filter(tf)
130130
for member in tf.getmembers():
131131
out = dest / member.name

automation_file/local/templates.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ def _render_with_jinja(
102102
if autoescape:
103103
env = Environment(autoescape=True, undefined=StrictUndefined)
104104
else:
105-
# nosec B701 # NOSONAR(pythonsecurity:S5496) caller opted out for non-HTML output
106-
env = Environment(autoescape=False, undefined=StrictUndefined)
105+
env = Environment( # nosec B701 # NOSONAR caller opted out for non-HTML output
106+
autoescape=False, undefined=StrictUndefined
107+
)
107108
try:
109+
# NOSONAR autoescape state enforced at the Environment above
108110
return env.from_string(template).render(**context)
109111
except JinjaTemplateError as error:
110112
raise TemplateException(f"jinja render failed: {error}") from error

automation_file/remote/ftp/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def later_init(self, options: FTPConnectOptions | None = None, **kwargs: Any) ->
4747
ftp: FTP = FTP_TLS(timeout=opts.timeout)
4848
else:
4949
# Plaintext FTP only when caller opts in via tls=False.
50-
ftp = FTP(timeout=opts.timeout) # nosec B321 # NOSONAR(python:S4423) plaintext FTP is opt-in via tls=False
50+
ftp = FTP(timeout=opts.timeout) # nosec B321 # NOSONAR plaintext FTP is opt-in via tls=False
5151
try:
5252
ftp.connect(opts.host, opts.port, timeout=opts.timeout)
5353
if opts.tls and isinstance(ftp, FTP_TLS):

automation_file/server/_websocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def compute_accept_key(sec_websocket_key: str) -> str:
2727
security primitive. ``usedforsecurity=False`` tells static analysers to
2828
skip the standard SHA-1 "insecure hash" warning.
2929
"""
30-
digest = hashlib.sha1( # nosec B303 B324 # nosemgrep: python.lang.security.audit.hashlib-insecure-functions # NOSONAR(python:S4790) RFC 6455 handshake, not a security primitive
30+
digest = hashlib.sha1( # nosec B303 B324 # nosemgrep: python.lang.security.audit.hashlib-insecure-functions # NOSONAR RFC 6455 handshake, not a security primitive
3131
(sec_websocket_key + _GUID).encode("ascii"),
3232
usedforsecurity=False,
3333
).digest()

tests/test_archive_ops.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ def _make_zip(path: Path, entries: dict[str, bytes]) -> None:
2525

2626

2727
def _make_tar(path: Path, entries: dict[str, bytes], mode: str = "w") -> None:
28-
with tarfile.open(
29-
path, mode
30-
) as tf: # NOSONAR(python:S5042) test fixture writes a known archive
28+
with tarfile.open(path, mode) as tf: # NOSONAR test fixture writes a known archive
3129
for name, data in entries.items():
3230
info = tarfile.TarInfo(name)
3331
info.size = len(data)

tests/test_cross_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_missing_local_source_returns_false(tmp_path: Path) -> None:
4444
def test_unknown_source_scheme_raises() -> None:
4545
# The target path is unused — the call must fail on the source scheme
4646
# before touching the filesystem. nosec B108 - filesystem never touched here.
47-
unused_target = "/tmp/x" # nosec B108 # NOSONAR(python:S5443) filesystem never touched
47+
unused_target = "/tmp/x" # nosec B108 # NOSONAR filesystem never touched — call fails on source scheme
4848
with pytest.raises(CrossBackendException):
4949
copy_between("gopher://a/b", unused_target)
5050

tests/test_fsspec_bridge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
def _purge_memory_fs() -> None:
2828
fs = fsspec.filesystem("memory")
2929
# list() snapshot required — fs.rm() mutates fs.store during iteration.
30-
for path in list(fs.store): # NOSONAR(python:S7504)
30+
for path in list(fs.store): # NOSONAR snapshot required — fs.rm mutates fs.store
3131
with contextlib.suppress(FileNotFoundError):
3232
fs.rm(path)
3333

0 commit comments

Comments
 (0)