Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 63 lines (48 sloc) 1.337 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#
# Style Fixup Rake Tasks
# $Id$
#
# Authors:
# * Michael Granger <ged@FaerieMUD.org>
#


### Coding style checks and fixes
namespace :style do

BLANK_LINE = /^\s*$/
GOOD_INDENT = /^(\t\s*)?\S/

# A list of the files that have legitimate leading whitespace, etc.
PROBLEM_FILES = [ SPECDIR + 'config_spec.rb' ]

desc "Check source files for inconsistent indent and fix them"
task :fix_indent do
files = LIB_FILES + SPEC_FILES

badfiles = Hash.new {|h,k| h[k] = [] }

trace "Checking files for indentation"
files.each do |file|
if PROBLEM_FILES.include?( file )
trace " skipping problem file #{file}..."
next
end

trace " #{file}"
linecount = 0
file.each_line do |line|
linecount += 1

# Skip blank lines
next if line =~ BLANK_LINE

# If there's a line with incorrect indent, note it and skip to the
# next file
if line !~ GOOD_INDENT
trace " Bad line %d: %p" % [ linecount, line ]
badfiles[file] << [ linecount, line ]
end
end
end

if badfiles.empty?
log "No indentation problems found."
else
log "Found incorrect indent in #{badfiles.length} files:\n "
badfiles.each do |file, badlines|
log " #{file}:\n" +
" " + badlines.collect {|badline| "%5d: %p" % badline }.join( "\n " )
end
end
end

end


Something went wrong with that request. Please try again.