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 63 64 65 66 67 68 69 70 71 72 73 74 75
|
require "rake/clean"
begin
require "rubocop/rake_task"
module AstyleHelper
class << self
def run(files)
assert
command = ["astyle", args, files].flatten.shelljoin
system(command)
end
def assert
require "mkmf"
find_executable0("astyle") || raise("Could not find command 'astyle'")
end
def args
[
# indentation
"--indent=spaces=4",
"--indent-switches",
# brackets
"--style=1tbs",
"--keep-one-line-blocks",
# where do we want spaces
"--unpad-paren",
"--pad-header",
"--pad-oper",
"--pad-comma",
# "void *pointer" and not "void* pointer"
"--align-pointer=name",
# function definitions and declarations
"--break-return-type",
"--attach-return-type-decl",
# gotta set a limit somewhere
"--max-code-length=100",
# be quiet about files that haven't changed
"--formatted",
"--verbose"
]
end
def c_files
SQLITE3_SPEC.files.grep(%r{ext/sqlite3/.*\.[ch]\Z})
end
end
end
namespace "format" do
desc "Format C code"
task "c" do
puts "Running astyle on C files ..."
AstyleHelper.run(AstyleHelper.c_files)
end
CLEAN.add(AstyleHelper.c_files.map { |f| "#{f}.orig" })
desc "Format Ruby code"
task "ruby" => "rubocop:autocorrect"
end
RuboCop::RakeTask.new
task "format" => ["format:c", "format:ruby"]
rescue LoadError => e
puts "NOTE: Rubocop is not available in this environment: #{e.message}"
end
|