diff options
| author | Xu Cheng | 2015-06-08 18:57:17 +0800 |
|---|---|---|
| committer | Xu Cheng | 2015-06-09 16:03:53 +0800 |
| commit | 8604799f1a320850ac564935265f414f93598599 (patch) | |
| tree | 277d5064657fe681f641652c2a8b435bcb425b71 /Library | |
| parent | d3ab5e6034c62b9da5c4c5f5e07a86f277a760e7 (diff) | |
| download | brew-8604799f1a320850ac564935265f414f93598599.tar.bz2 | |
audit: add rules on field order
Closes Homebrew/homebrew#40472.
Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/cmd/audit.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb index 51388c905..369c50e99 100644 --- a/Library/Homebrew/cmd/audit.rb +++ b/Library/Homebrew/cmd/audit.rb @@ -56,6 +56,7 @@ end class FormulaText def initialize path @text = path.open("rb", &:read) + @lines = @text.lines end def without_patch @@ -77,6 +78,11 @@ class FormulaText def =~ regex regex =~ @text end + + def line_number regex + index = @lines.index { |line| line =~ regex } + index ? index + 1 : nil + end end class FormulaAuditor @@ -125,6 +131,37 @@ class FormulaAuditor unless text.has_trailing_newline? problem "File should end with a newline" end + + return unless @strict + + component_list = [ + [/^ desc ["'][\S\ ]+["']/, "desc" ], + [/^ homepage ["'][\S\ ]+["']/, "homepage" ], + [/^ url ["'][\S\ ]+["']/, "url" ], + [/^ mirror ["'][\S\ ]+["']/, "mirror" ], + [/^ version ["'][\S\ ]+["']/, "version" ], + [/^ (sha1|sha256) ["'][\S\ ]+["']/, "checksum" ], + [/^ head ["'][\S\ ]+["']/, "head" ], + [/^ stable do/, "stable block" ], + [/^ bottle do/, "bottle block" ], + [/^ devel do/, "devel block" ], + [/^ head do/, "head block" ], + [/^ option/, "option" ], + [/^ depends_on/, "depends_on" ], + [/^ def install/, "install method"], + [/^ def caveats/, "caveats method"], + [/^ test do/, "test block" ], + ] + + component_list.map do |regex, name| + lineno = text.line_number regex + next unless lineno + [lineno, name] + end.compact.each_cons(2) do |c1, c2| + unless c1[0] < c2[0] + problem "`#{c1[1]}`(line #{c1[0]}) should be put before `#{c2[1]}`(line #{c2[0]})" + end + end end def audit_class |
