Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: fail only if autocorrectable offenses #12702

Open
PatrickF1 opened this issue Feb 17, 2024 · 2 comments
Open

Question: fail only if autocorrectable offenses #12702

PatrickF1 opened this issue Feb 17, 2024 · 2 comments
Labels

Comments

@PatrickF1
Copy link

Hi, thanks for making Rubocop so awesome!
I want to make sure all the devs on my repo are running Rubocop autocorrect (automatically through their editors) before committing. What is a rubocop command I can run in CI that will fail if there are any autocorrectable offenses but will not fail if there are only info/convention offenses that are not autocorrectable?

Thanks!

PatrickF1 added a commit to PatrickF1/GraceTunes that referenced this issue Feb 17, 2024
I want to require everyone to properly lint their files before merging to master to reduce bugs. Ideally, we would also automatically run `rubocop --autocorrect` on file save (easily achievable through an editor integration) so all our code has consistent style and conventions.

So, this PR
- updates to and requires the current latest RuboCop
- removed some annoying code metric cops
- turned on a few disabled cops I found useful
- rubocop autocorrected all our Ruby files to fix our current warnings and prevent autocorrect from producing out-of-scope diffs in subsequent PRs
- updated CI to fail builds if there are warning-level offenses detected

Ideally, CI would also fail if there are autocorrectable offenses, even if not warning level, but I couldn't figure out how. I asked in rubocop/rubocop#12702 and will follow up once I get the answer.
I will update our dev docs to make it clear we should be using RuboCop.
@jonas054
Copy link
Collaborator

If the jq command is available in your environment you could do something like

rubocop --format json | \
jq '.files[].offenses[] | select(.correctable) | length > 0' | \
grep --quiet true && \
echo "Found correctable offenses!"

Otherwise you could write a Ruby program to do the parsing. Anyway, I think outputting JSON from RuboCop and then using some other tool to detect "correctable": true is the best way.

@PatrickF1
Copy link
Author

Thank you Jonas, I'll just do that. So it sounds like this isn't a feature? If so, then I'd like to make it a feature request then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants