Skip to content

Commit e036fb7

Browse files
hyperpolymathclaude
andcommitted
fix(tests): resolve 5 SonarCloud issues + replace python3 with awk in build-all.sh
Tests (4 SonarCloud issues): - TextTransform_test.js: remove unused `assertNotEquals` import; replace `assertEquals(x.length > 0, true)` with `assert(x.length > 0)` for the three check_constraints tests (S1128 + boolean-literal smell) - ByteDetector_test.js: remove tautological `|| report.length > 0` clause from the generate_report assertion (always true for non-empty output) Build script: - Replace `python3 - << PYEOF` heredoc with awk + POSIX shell; python3 is banned in this repo (CLAUDE.md) and unavailable in the Deno deploy env Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e49bdfd commit e036fb7

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

scripts/build-all.sh

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@ done
2323
# cross-module dependencies into TextTransform.deno.js. Inject missing symbols
2424
# after compilation: LF/CRLF/CR (zero-arg enum constructors), is_invisible
2525
# (private helper from SafeWhitespace), concat (string stdlib fn).
26-
python3 - << 'PYEOF'
27-
PATCH = """\
28-
const LF={tag:"LF"};const CRLF={tag:"CRLF"};const CR={tag:"CR"};
29-
function is_invisible(c){return(c===0||c===160||c===8203||c===65279||c===173||c===8206||c===8207||c===8204||c===8205||c===8288);}
30-
function concat(a,b){return __as_concat(a,b);}
31-
"""
32-
MARKER = "// ---- end runtime ----"
33-
path = "src/core/TextTransform.deno.js"
34-
with open(path) as fh:
35-
content = fh.read()
36-
if PATCH.strip().split("\n")[0] not in content:
37-
content = content.replace(MARKER, MARKER + "\n" + PATCH, 1)
38-
with open(path, "w") as fh:
39-
fh.write(content)
40-
PYEOF
26+
TARGET="src/core/TextTransform.deno.js"
27+
MARKER="// ---- end runtime ----"
28+
PATCH='const LF={tag:"LF"};const CRLF={tag:"CRLF"};const CR={tag:"CR"};\nfunction is_invisible(c){return(c===0||c===160||c===8203||c===65279||c===173||c===8206||c===8207||c===8204||c===8205||c===8288);}\nfunction concat(a,b){return __as_concat(a,b);}'
29+
if [ -f "$TARGET" ] && ! grep -qF 'const LF={tag:"LF"}' "$TARGET"; then
30+
awk -v marker="$MARKER" -v patch="$PATCH" '
31+
{ print }
32+
$0 == marker { printf "%s\n", patch }
33+
' "$TARGET" > "$TARGET.tmp" && mv "$TARGET.tmp" "$TARGET"
34+
fi
4135

4236
echo "build-all complete"

tests/ByteDetector_test.js

-21 Bytes
Binary file not shown.

tests/TextTransform_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// SPDX-License-Identifier: MPL-2.0
22
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
3-
import { assertEquals, assertNotEquals } from "jsr:@std/assert";
3+
import { assert, assertEquals } from "jsr:@std/assert";
44
import {
55
default_options, transform, transform_default,
66
get_metrics, metrics_to_string,
@@ -70,7 +70,7 @@ Deno.test("TextTransform: metrics_to_string includes char count", () => {
7070
Deno.test("TextTransform: check_constraints detects char limit exceeded", () => {
7171
const c = { max_chars: { tag: "Some", value: 5 }, max_words: { tag: "None" }, max_lines: { tag: "None" }, max_bytes: { tag: "None" } };
7272
const violations = check_constraints("This is a long string", c);
73-
assertEquals(violations.length > 0, true);
73+
assert(violations.length > 0);
7474
});
7575

7676
Deno.test("TextTransform: check_constraints passes when within limit", () => {
@@ -81,13 +81,13 @@ Deno.test("TextTransform: check_constraints passes when within limit", () => {
8181
Deno.test("TextTransform: check_constraints detects word limit exceeded", () => {
8282
const c = { max_chars: { tag: "None" }, max_words: { tag: "Some", value: 3 }, max_lines: { tag: "None" }, max_bytes: { tag: "None" } };
8383
const violations = check_constraints("one two three four five", c);
84-
assertEquals(violations.length > 0, true);
84+
assert(violations.length > 0);
8585
});
8686

8787
Deno.test("TextTransform: check_constraints detects line limit exceeded", () => {
8888
const c = { max_chars: { tag: "None" }, max_words: { tag: "None" }, max_lines: { tag: "Some", value: 2 }, max_bytes: { tag: "None" } };
8989
const violations = check_constraints("a\nb\nc\nd", c);
90-
assertEquals(violations.length > 0, true);
90+
assert(violations.length > 0);
9191
});
9292

9393
Deno.test("TextTransform: format_for_html escapes < and >", () => {

0 commit comments

Comments
 (0)