-
-
Notifications
You must be signed in to change notification settings - Fork 897
/
format.rake
82 lines (66 loc) · 1.92 KB
/
format.rake
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
76
77
78
79
80
81
82
# coding: utf-8
# frozen_string_literal: true
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
# See http://astyle.sourceforge.net/astyle.html
# These choices are just what I happen to like,
# but I'm the one writing most of the code these days, so ¯\_(ツ)_/¯
[
# indentation
"--indent=spaces=2",
"--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=120",
# be quiet about files that haven't changed
"--formatted",
"--verbose",
]
end
def c_files
NOKOGIRI_SPEC.files.grep(%r{ext/nokogiri/.*\.[ch]\Z})
end
def java_files
NOKOGIRI_SPEC.files.grep(%r{ext/java/.*\.java\Z})
end
end
end
namespace "format" do
desc "Format Nokogiri's C code"
task "c" do
puts "Running astyle on C files ..."
AstyleHelper.run(AstyleHelper.c_files)
end
desc "Format Nokogiri's Java code"
task "java" do
puts "Running astyle on Java files ..."
AstyleHelper.run(AstyleHelper.java_files)
end
desc "Format Nokogiri's Ruby code"
task "ruby" => "rubocop:check:auto_correct"
CLEAN.add(AstyleHelper.c_files.map { |f| "#{f}.orig" })
CLEAN.add(AstyleHelper.java_files.map { |f| "#{f}.orig" })
end
task "format" => ["format:c", "format:java", "format:ruby"]