Skip to content
Merged
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
24 changes: 12 additions & 12 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,36 @@ jobs:
local has_debug=false
local debug_output=""

# Check for $inspect
if grep -n "\$inspect" "$file" > /dev/null; then
match=$(grep -n "\$inspect.*" "$file" | head -n 1)
# Check for $inspect (not in comments)
if grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*\$inspect' "$file" > /dev/null; then
match=$(grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*\$inspect.*' "$file" | head -n 1)
line_num=$(echo "$match" | cut -d: -f1)
statement=$(echo "$match" | cut -d: -f2-)
echo "::error file=$file::Found \$inspect statement on line $line_num: $statement"
has_debug=true
fi
Comment on lines +75 to 82
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance comment exclusion and DRY the regex

The negative lookahead currently filters out lines starting with //, /*, or *, but:

  1. It doesn’t exclude HTML comment markers (<!--) used in .svelte files, so commented-out debug code in HTML comments will still trigger false positives.
  2. It only skips lines where the comment marker is at the very start (after whitespace), but block comments without leading * on inner lines (e.g., /*\n console.log...\n*/) can still slip through.
  3. The same long regex is duplicated four times.

Proposed diff to address these and reduce duplication:

@@  check_file() {
-   # Check for $inspect (not in comments)
-   if grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*\$inspect' "$file" > /dev/null; then
+   # Define pattern to ignore JavaScript and HTML comment lines
+   local IGNORE_COMMENTS='^(?!\s*(?://|/\*|\*|<!--))'
+
+   # Check for $inspect (not in comments)
+   if grep -n -P "${IGNORE_COMMENTS}.*\\\$inspect" "$file" > /dev/null; then
       match=$(grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*\$inspect.*' "$file" | head -n 1)
       line_num=$(echo "$match" | cut -d: -f1)
       statement=$(echo "$match" | cut -d: -f2-)

You can then replace the other three grep calls to use ${IGNORE_COMMENTS} instead of repeating the full pattern. This will ensure HTML comments are respected and make future updates simpler.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In .github/workflows/npm-publish.yml around lines 75 to 82, the regex used to
exclude comment lines when searching for $inspect statements does not account
for HTML comment markers like <!-- and only excludes comment markers at the
start of the line, missing inner block comment lines. Additionally, the same
complex regex is repeated multiple times. To fix this, define a variable (e.g.,
IGNORE_COMMENTS) that includes an improved negative lookahead pattern covering
//, /*, *, and <!-- comment styles and use this variable in all grep commands to
avoid duplication and ensure all comment types are properly excluded.


# Check for console.log
if grep -n "console\.log" "$file" > /dev/null; then
match=$(grep -n "console\.log.*" "$file" | head -n 1)
# Check for console.log (not in comments)
if grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*console\.log' "$file" > /dev/null; then
match=$(grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*console\.log.*' "$file" | head -n 1)
line_num=$(echo "$match" | cut -d: -f1)
statement=$(echo "$match" | cut -d: -f2-)
echo "::error file=$file::Found console.log statement on line $line_num: $statement"
has_debug=true
fi

# Check for console.debug
if grep -n "console\.debug" "$file" > /dev/null; then
match=$(grep -n "console\.debug.*" "$file" | head -n 1)
# Check for console.debug (not in comments)
if grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*console\.debug' "$file" > /dev/null; then
match=$(grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*console\.debug.*' "$file" | head -n 1)
line_num=$(echo "$match" | cut -d: -f1)
statement=$(echo "$match" | cut -d: -f2-)
echo "::error file=$file::Found console.debug statement on line $line_num: $statement"
has_debug=true
fi

# Check for debugger statements
if grep -n "debugger;" "$file" > /dev/null; then
match=$(grep -n "debugger;" "$file" | head -n 1)
# Check for debugger statements (not in comments)
if grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*debugger;' "$file" > /dev/null; then
match=$(grep -n -P '^(?!\s*//|\s*/\*|\s*\*).*debugger;' "$file" | head -n 1)
line_num=$(echo "$match" | cut -d: -f1)
statement=$(echo "$match" | cut -d: -f2-)
echo "::error file=$file::Found debugger statement on line $line_num: $statement"
Expand Down
Loading