aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-05-24 15:59:00 +0800
committerXu Cheng2015-05-24 20:07:33 +0800
commit78ccd4125124024e4e73734a54059a8af994791d (patch)
tree1b109b188f4d64acd2864132bf937f252d89e07b /Library
parente4ff0a2f2edce6166bf6fad018e6f8154b2ee218 (diff)
downloadbrew-78ccd4125124024e4e73734a54059a8af994791d.tar.bz2
audit: add rules for non-ascii character and encoding comment
Closes Homebrew/homebrew#40042. Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/audit.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/Library/Homebrew/cmd/audit.rb b/Library/Homebrew/cmd/audit.rb
index 4290bec4c..be6be5c39 100644
--- a/Library/Homebrew/cmd/audit.rb
+++ b/Library/Homebrew/cmd/audit.rb
@@ -70,6 +70,14 @@ class FormulaText
/\Z\n/ =~ @text
end
+ def has_non_ascii_character?
+ /[^\x00-\x7F]/ =~ @text
+ end
+
+ def has_encoding_comment?
+ /^# (en)?coding: utf-8$/i =~ @text
+ end
+
def =~ regex
regex =~ @text
end
@@ -118,6 +126,14 @@ class FormulaAuditor
problem "'__END__' was found, but 'DATA' is not used"
end
+ if text.has_non_ascii_character? and not text.has_encoding_comment?
+ problem "Found non-ASCII character: add `# encoding: UTF-8` in the first line"
+ end
+
+ if text.has_encoding_comment? and not text.has_non_ascii_character?
+ problem "Remove the redundant `# encoding: UTF-8`"
+ end
+
unless text.has_trailing_newline?
problem "File should end with a newline"
end