Skip to content

Instantly share code, notes, and snippets.

@kaosf
Created August 21, 2026 12:33
Show Gist options
  • Select an option

  • Save kaosf/acdd981d68d620bd75d5b1d230f27f84 to your computer and use it in GitHub Desktop.

Select an option

Save kaosf/acdd981d68d620bd75d5b1d230f27f84 to your computer and use it in GitHub Desktop.
SimpleCov `# :nocov:` -> `# simplecov:disable` `# simplecov:enable` migration script
find . -type f -name '*.rb' -print0 |
while IFS= read -r -d '' file; do
count=$(grep -cF '# :nocov:' "$file")
if (( count % 2 != 0 )); then
echo "ERROR: unmatched # :nocov: in $file" >&2
exit 1
fi
awk '
/# :nocov:/ {
if (n % 2 == 0)
sub(/# :nocov:/, "# simplecov:disable")
else
sub(/# :nocov:/, "# simplecov:enable")
n++
}
{ print }
' "$file" > "$file.tmp" &&
mv "$file.tmp" "$file"
done
# ref.
# https://github.com/simplecov-ruby/simplecov/blob/d145158bdc67f6034dce98c40a9c82147b291364/docs/Configuration.md#ignoring-implicit-else-branches
# deprecation warning message:
# [DEPRECATION] `# :nocov:` is deprecated and will be removed in a future release. Replace with `# simplecov:disable` / `# simplecov:enable` block comments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment