Last active
June 6, 2023 16:23
-
-
Save Lockyy/7e0d7736b7d897809e4b88b6114f8f12 to your computer and use it in GitHub Desktop.
Run Rubocop on files that've changed in Git
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
#!/bin/bash | |
rubocop $(git diff --name-only --diff-filter=d main...) --force-exclusion "$@" |
I should consider using something like git diff --name-only --diff-filter=d develop...
to diff off of develop for this. So that I can see issues with my whole branch rather than just the current staging area.
Would be good if it was off of the parent branch rather than just develop however.
I've updated this to use the contents of files-diff for gathering the changed files. Typically I have that as a separate script that I use instead:
#!/bin/bash
rubocop $(files-diff) --force-exclusion "$@"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--porcelain creates a future proof short list of changed files, sed then cuts out the first three characters of each line to ensure we don't have the actual status of each file. This leaves a nice set of changed files to pass into rubocop.
--force-exclusion means that even if the list of files includes files that are listed as excluded in your rubocop config file you won't get output for those files.
We then use "$@" to pass through all other parameters. This allows you to use this as your base rubocop command with modifiers if you want.