Created
August 8, 2012 19:20
-
-
Save davidmfoley/3297812 to your computer and use it in GitHub Desktop.
Detect indentation errors in mocha coffeescript specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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