equal
deleted
inserted
replaced
1 # |
|
2 # Style Fixup Rake Tasks |
|
3 # |
|
4 # |
|
5 # |
|
6 |
|
7 ### Coding style checks and fixes |
|
8 namespace :style do |
|
9 |
|
10 BLANK_LINE = /^\s*$/ |
|
11 GOOD_INDENT = /^(\t\s*)?\S/ |
|
12 |
|
13 # A list of the files that have legitimate leading whitespace, etc. |
|
14 PROBLEM_FILES = [ SPECDIR + 'config_spec.rb' ] |
|
15 |
|
16 desc "Check source files for inconsistent indent and fix them" |
|
17 task :fix_indent do |
|
18 files = LIB_FILES + SPEC_FILES |
|
19 |
|
20 badfiles = Hash.new {|h,k| h[k] = [] } |
|
21 |
|
22 trace "Checking files for indentation" |
|
23 files.each do |file| |
|
24 if PROBLEM_FILES.include?( file ) |
|
25 trace " skipping problem file #{file}..." |
|
26 next |
|
27 end |
|
28 |
|
29 trace " #{file}" |
|
30 linecount = 0 |
|
31 file.each_line do |line| |
|
32 linecount += 1 |
|
33 |
|
34 # Skip blank lines |
|
35 next if line =~ BLANK_LINE |
|
36 |
|
37 # If there's a line with incorrect indent, note it and skip to the |
|
38 # next file |
|
39 if line !~ GOOD_INDENT |
|
40 trace " Bad line %d: %p" % [ linecount, line ] |
|
41 badfiles[file] << [ linecount, line ] |
|
42 end |
|
43 end |
|
44 end |
|
45 |
|
46 if badfiles.empty? |
|
47 log "No indentation problems found." |
|
48 else |
|
49 log "Found incorrect indent in #{badfiles.length} files:\n " |
|
50 badfiles.each do |file, badlines| |
|
51 log " #{file}:\n" + |
|
52 " " + badlines.collect {|badline| "%5d: %p" % badline }.join( "\n " ) |
|
53 end |
|
54 end |
|
55 end |
|
56 |
|
57 end |
|
58 |
|
59 |
|