Top Level Namespace
Defined Under Namespace
Modules: EnLint Classes: AnEncoding
Constant Summary collapse
- DEFAULT_IGNORES =
%w( tmp .hg .svn .git .gitignore node_modules bower_components target dist .vagrant Gemfile.lock *.exe *.bin *.apk *.ap_ res *.dmg *.pkg *.app *.xcodeproj *.lproj *.xcassets *.pmdoc *.dSYM *.class *.zip *.jar *.war *.xpi *.jad *.cmo *.cmi *.pdf *.dot *.png *.gif *.jpg *.jpeg *.tiff *.ico *.wav *.mp3 )
- DEFAULT_RULES =
Note that order is significant; Only the earliest file pattern match’s rule applies.
[ ['*.{reg,bat,ps1}', /(ascii|utf-16)/], ['*', /(utf-8|ascii|binary|unknown)/] ]
- DEFAULT_CONFIGURATION =
{ 'rules' => DEFAULT_RULES }
- NO_SUCH_FILE =
Warning for files that do not exist
'no such file'
- MAC_OS_X =
RUBY_PLATFORM =~ /darwin/
- MIME_FLAG =
if MAC_OS_X '--mime-encoding' else '-i' end
- PARSER =
if MAC_OS_X /^(.+)\:\s+(.+)$/ else /^.+\:\s+(.+);\s+charset=(.+)$/ end
- DNE =
if MAC_OS_X /^.+: cannot open `.+' (No such file or directory)$/ else /ERROR\:/ end
Class Method Summary collapse
Class Method Details
.check(filename, configuration = nil) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/enlint.rb', line 149 def self.check(filename, configuration = nil) configuration = if configuration.nil? DEFAULT_CONFIGURATION else DEFAULT_CONFIGURATION.merge(YAML.load(configuration)) end rules = configuration['rules'] line = `file #{MIME_FLAG} "#{filename}" 2>&1` encoding = AnEncoding.parse(filename, line) encoding_difference = encoding.violate?(rules) puts encoding.to_s(encoding_difference) if encoding_difference end |