Last active
November 18, 2024 17:36
-
-
Save wteuber/c435bafcd79beb91b65e354fc907efe8 to your computer and use it in GitHub Desktop.
Apply Ruby's keyword argument and hash value omission in a git repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://gist.github.com/wteuber/c435bafcd79beb91b65e354fc907efe8 | |
# macOS/zsh | |
# Apply Ruby's keyword argument and hash value omission in a git repo | |
# First occurence only | |
git grep -lP '\b([A-Za-z0-9_]+): \1\b[,\)]' -- '*.rb' | head -1 | xargs -I {} sed -i -E 's/\b([A-Za-z0-9_]+): \1\b([,\)])/\1:\2/g' "{}" | |
# Apply for "<var>: <var>," and "<var>: <var>)" | |
git grep -lP '\b([A-Za-z0-9_]+): \1\b[,\)]' -- '*.rb' | xargs -I {} sed -i -E 's/\b([A-Za-z0-9_]+): \1\b([,\)])/\1:\2/g' "{}" | |
# Apply for "<var>: <var> }" | |
git grep -lP '\b([A-Za-z0-9_]+): \1\b \}' -- '*.rb' | xargs -I {} sed -i -E 's/\b([A-Za-z0-9_]+): \1\b \}/\1: }/g' "{}" | |
# List other occurences of "<var>: <var>" except "<var>: <var>.", "<var>: <var>(", "<var>: <var>?", "<var>: <var>&" | |
git grep -nP '\b([A-Za-z0-9_]+): \1\b[^.(?&]' -- '*.rb' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prefer using https://docs.rubocop.org/rubocop/cops_style.html#enforcedshorthandsyntax_-always-stylehashsyntax instead.