As a Ruby developer, I’ve spent my fair share of time wrestling with code style tools like RuboCop and Pronto. They’re fantastic for keeping code clean, but let’s be honest—manually fixing linting errors across a codebase can feel like a slog. Worse, when bad style slips into your develop
branch because CI only catches it post-merge, you’re stuck playing cleanup. I wanted a better way: a tool that automates style corrections with precision and safety, whether I’m linting a pull request’s changes or the whole project. So, I wrote (with the help of AI) ProntoAutocorrect
.
Here’s the scoop on this Ruby script—what it does, how it works, and why it might save you (and your team) some headaches.
What Is ProntoAutocorrect?
ProntoAutocorrect
is a command-line tool that combines Pronto’s diff-based linting with RuboCop’s auto-correction magic. It scans your Ruby files for style issues and fixes them in one go, offering both a “safe” mode for low-risk tweaks and an “aggressive” mode for deeper cleanups. You can run it against a base branch (like origin/develop
) to catch changes in a PR, or sweep through all Ruby files in your current branch with the --all
flag.
Here’s the script in action:
./pronto_autocorrect.rb origin/main -A
That’ll compare your current branch to origin/main
and apply aggressive auto-corrections. Want to see it for yourself? Check out the full code at the end of this post.
Features
Here’s what it brings to the table:
- Flexible Targeting: Compare against any branch (default:
origin/develop
) or lint all Ruby files—both Git-tracked and untracked—with--all
, automatically ignoring files in.gitignore
. - Safe vs. Aggressive Modes: Use
-a
(default) for safe fixes that won’t break logic, or-A
for RuboCop’s full auto-correct power (watch out—semantics might shift!). - Batch Processing: Corrects files in chunks of 50 to avoid command-line length limits.
- Real-Time Output: See Pronto’s linting and RuboCop’s fixes as they happen.
- Smart Summaries: Get a rundown of files processed, time taken, and any lingering issues with next-step tips.
Run it with -h
for the full usage guide:
./pronto_autocorrect.rb --help