Skip to content

Instantly share code, notes, and snippets.

@davidmfoley
Created August 8, 2012 19:20
Show Gist options
  • Save davidmfoley/3297812 to your computer and use it in GitHub Desktop.
Save davidmfoley/3297812 to your computer and use it in GitHub Desktop.
Detect indentation errors in mocha coffeescript specs
#! /usr/bin/env ruby
current_filename = ''
allowed_indent = 0
def indent_of line
line.index /[a-z]/
end
ARGF.lines do |line|
if current_filename != ARGF.filename
#puts ARGF.filename
current_filename = ARGF.filename
allowed_indent = 0
end
if line =~ /describe/
allowed_indent = indent_of(line) + 2
elsif line =~ /^ *(it|before)/
if allowed_indent < indent_of(line)
puts "Indentation Error: #{ARGF.filename}:#{ARGF.lineno}\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment