BuildDoctor

Build Doctor

Continuous Integration, Delivery and Devops Consulting

Contact Us

(+44) 207 183 0323
hello@build-doctor.com
@builddoctor

Get in touch!

Zero tolerance

Posted on by Julian Simpson

This has been surprisingly useful at keeping my JS code clean.


desc "Check for tabs and trailing spaces"
task :crapcheck do
  Dir["public/**/*.js"].each do |f|
    next if f.match(/^lib|resources/)
    text = File.read(f)
    raise "Tabs found in #{f}" if text.match(/\t/)
    raise "Trailing spaces found in #{f}" if text.match(/ $|    $/)
  end
end

The tab check is useful because I hate them, and they mess with JSLint; the trailing spaces mess up my diffs. Take that.


About Julian Simpson

Founder and Editor of The Build Doctor. Drinks Flat Whites. View all posts by Julian Simpson →

3 Responses to Zero tolerance

Oliver says: April 1, 2011 at 6:04 pm

I’ve been doing exactly the same thing with my Puppet modules/manifests for at least a year now – it certainly raises the ire of those who prefer hard tabs but I think the sheer benefit of readable diffs is enough justification.

I also check for windows line endings (you can never be sure who is developing on the devil’s platform), files in the right place but with incorrect suffices (e.g. ERB templates) and so on. A good idea all round.

Will says: April 5, 2011 at 7:39 am

While I’m all for clean code, this reminds me of something that long irritated me with code-check tools like this that were mandated at a previous job.

Instead of raising errors when things like whitespace or tabs occur, why not just modify the file to correct it?

What benefit is there to processes which ‘raise the ire’ of co-workers, when a less aggravating and time-consuming option exists?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

The Build Doctor Ltd, Suite 17189, Lower Ground Floor, 145-157 St John Street, London, EC1V 4PW

© Build Doctor 2007-2012