How to check entire rails project for compilation errors How to check entire rails project for compilation errors ruby-on-rails ruby-on-rails

How to check entire rails project for compilation errors


If you're on Linux or Mac or some funny windows box with the gnu find command, you can do something like:

find /your/application_directory -name=*.rb -exec ruby -c {} \;

This will find all ruby scripts in the app directory and run ruby -c on them, which will run a syntax check and respond with Syntax OK or an error message if there is an error in the script.

You can also create a macro of this to your editor, so that when you save or press a key combination it will run ruby -c on the file and give you the results. In vim you can use this in your .vimrc :

map <Leader>c :w !ruby -c<cr>

Which maps Leader-c to write the file and check it's syntax using ruby -c.

Verifying your rake-tasks and views for syntax errors might be a little trickier, but many of the templating engines like haml have similiar -c syntax check parameter.


This a one-line answer from @Zac comment, I have included it as an answer as not all the time we do read the comments:

find . | grep ".*\.rb$" | xargs -L 1 ruby -c


Why can't you continue to use an IDE like RubyMine (or its father, IntelliJ)?

There are also plugins for text editors that will highlight syntax issues, but who knows what you're using. I use Sublime Text 2 for non-IDE development and it supports several varieties of automatic linting. As does Emacs, but I'm guessing you won't go there.

Whether you use "real" TDD or not, you need to tighten your code-writing cycles and work more incrementally so you don't have a chance to accumulate such high-level (low-level?) errors in the first place, though. That's true regardless of the language or environment.