Skip to content

Instantly share code, notes, and snippets.

@derigible
Created March 23, 2023 00:06
Show Gist options
  • Save derigible/3000033fed8fb306965e66b3cae00377 to your computer and use it in GitHub Desktop.
Save derigible/3000033fed8fb306965e66b3cae00377 to your computer and use it in GitHub Desktop.
Update files that don't have the frozen_string_literal comment
#! /bin/zsh
set -e
rubocop | grep FrozenStringLiteralComment | awk '{ print $1 }' | awk -F ':' '{ print $1 }' | awk '{$1=$1};1' | xargs sed -i "" '1s/^/# frozen_string_literal: true\n\n/'
@derigible
Copy link
Author

derigible commented Mar 23, 2023

This also works (and is probably the better way to do it):

git diff --diff-filter=d --name-only $(git merge-base master HEAD) | grep -e ".rb$" -e ".rake$" | xargs -t bundle exec rubocop --enable-pending-cops --autocorrect-all --display-style-guide --force-exclusion

Note that this will only work on projects that use git. The benefit of this approach though is it narrows the scope of changes to only those files that have been updated during a commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment