enlint 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/enlint +52 -3
- data/lib/enlint.rb +34 -27
- data/lib/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22767de80b9fa973581afb14aa5443c9f6ed5f5d
|
4
|
+
data.tar.gz: 212a81cae4d05cebef59d4694aa99ccb37a30184
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 406b8284ab6084930461a7a07cb7196a16a5319ab0e9669853e54228235fa3ba224122ec9569ddda10b49fe8dd55a4261f6d084edb649d12fb8405dddddbb753
|
7
|
+
data.tar.gz: 7bbd4dbd40d8a4aabd9126087e46d39ae20d278c8c21a026d748dd6809c0ad4b5a2eb1694697642ced91564cb991743184a42e9cf15709ecb149edd3b2996faf
|
data/bin/enlint
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
require 'rubygems'
|
3
4
|
require 'find'
|
4
5
|
require 'optparse'
|
5
|
-
|
6
|
-
require 'rubygems'
|
6
|
+
require 'yaml'
|
7
7
|
require 'enlint'
|
8
8
|
|
9
|
+
IGNORE_FILENAME = '.enlintignore'
|
10
|
+
CONFIGURATION_FILENAME = '.enlintrc.yml'
|
11
|
+
|
9
12
|
def main
|
10
13
|
ignores = DEFAULT_IGNORES
|
11
14
|
|
12
15
|
filenames = ['.']
|
13
16
|
|
17
|
+
configuration_flags = {}
|
18
|
+
|
14
19
|
option = OptionParser.new do |option|
|
15
20
|
option.banner = 'Usage: enlint [options] [<files>]'
|
16
21
|
|
@@ -43,7 +48,51 @@ def main
|
|
43
48
|
end
|
44
49
|
end
|
45
50
|
|
46
|
-
|
51
|
+
configuration_dotfile = DEFAULT_CONFIGURATION
|
52
|
+
|
53
|
+
recursive_filenames.each do |f|
|
54
|
+
dir = File.expand_path("..", f)
|
55
|
+
|
56
|
+
parent_of_home = File.expand_path("..", ENV["HOME"])
|
57
|
+
|
58
|
+
while dir != parent_of_home
|
59
|
+
ignore_file = dir + File::SEPARATOR + IGNORE_FILENAME
|
60
|
+
|
61
|
+
if File.exist?(ignore_file) then
|
62
|
+
ignores.concat(open(ignore_file).read.split("\n"))
|
63
|
+
end
|
64
|
+
|
65
|
+
dir = File.expand_path("..", dir)
|
66
|
+
end
|
67
|
+
|
68
|
+
if ignores.none? { |ignore| f =~ %r(#{ignore}) } then
|
69
|
+
dir = File.expand_path("..", f)
|
70
|
+
|
71
|
+
parent_of_home = File.expand_path("..", ENV["HOME"])
|
72
|
+
|
73
|
+
while dir != parent_of_home
|
74
|
+
config_file = dir + File::SEPARATOR + CONFIGURATION_FILENAME
|
75
|
+
|
76
|
+
if File.exist?(config_file) then
|
77
|
+
configuration_dotfile = DEFAULT_CONFIGURATION.merge(YAML.load_file(config_file))
|
78
|
+
break
|
79
|
+
else
|
80
|
+
dir = File.expand_path("..", dir)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# Hack to Reset configuration when changing directories
|
85
|
+
configuration_dotfile = DEFAULT_CONFIGURATION unless File.exist?(dir + File::SEPARATOR + CONFIGURATION_FILENAME)
|
86
|
+
|
87
|
+
# Command line flags override dotfile settings
|
88
|
+
configuration = configuration_dotfile.merge(configuration_flags)
|
89
|
+
|
90
|
+
# puts "F: #{f}"
|
91
|
+
# puts "Configuration: #{configuration}"
|
92
|
+
|
93
|
+
check(f, configuration)
|
94
|
+
end
|
95
|
+
end
|
47
96
|
end
|
48
97
|
|
49
98
|
begin
|
data/lib/enlint.rb
CHANGED
@@ -4,22 +4,21 @@ require 'ptools'
|
|
4
4
|
require 'version'
|
5
5
|
|
6
6
|
DEFAULT_IGNORES = %w(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
.gitignore
|
7
|
+
\.hg/
|
8
|
+
\.svn/
|
9
|
+
\.git/
|
10
|
+
\.gitignore
|
12
11
|
node_modules/
|
13
|
-
|
14
|
-
Gemfile
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
-min
|
12
|
+
\.vagrant/
|
13
|
+
Gemfile\.lock
|
14
|
+
\.exe
|
15
|
+
\.bin
|
16
|
+
\.pdf
|
17
|
+
\.png
|
18
|
+
\.jpg
|
19
|
+
\.jpeg
|
20
|
+
\.min.js
|
21
|
+
-min\.js
|
23
22
|
)
|
24
23
|
|
25
24
|
#
|
@@ -28,30 +27,36 @@ DEFAULT_IGNORES = %w(
|
|
28
27
|
#
|
29
28
|
DEFAULT_RULES = [
|
30
29
|
[/\.reg$/, /(ascii|utf-16)/],
|
30
|
+
[/\.bat$/, /(ascii|utf-16)/],
|
31
|
+
[/\.ps1$/, /(ascii|utf-16)/],
|
31
32
|
[/.*/, /(utf-8|ascii|binary|unknown)/]
|
32
33
|
]
|
33
34
|
|
35
|
+
DEFAULT_CONFIGURATION = {
|
36
|
+
'rules' => DEFAULT_RULES
|
37
|
+
}
|
38
|
+
|
34
39
|
# Warning for files that do not exist
|
35
40
|
NO_SUCH_FILE = 'no such file'
|
36
41
|
|
37
42
|
MAC_OS_X = RUBY_PLATFORM =~ /darwin/
|
38
43
|
|
39
44
|
MIME_FLAG =
|
40
|
-
if MAC_OS_X
|
45
|
+
if MAC_OS_X
|
41
46
|
'--mime-encoding'
|
42
47
|
else
|
43
48
|
'-i'
|
44
49
|
end
|
45
50
|
|
46
51
|
PARSER =
|
47
|
-
if MAC_OS_X
|
52
|
+
if MAC_OS_X
|
48
53
|
/^(.+)\:\s+(.+)$/
|
49
54
|
else
|
50
55
|
/^.+\:\s+(.+);\s+charset=(.+)$/
|
51
56
|
end
|
52
57
|
|
53
58
|
DNE =
|
54
|
-
if MAC_OS_X
|
59
|
+
if MAC_OS_X
|
55
60
|
/^.+: cannot open `.+' (No such file or directory)$/
|
56
61
|
else
|
57
62
|
/ERROR\:/
|
@@ -65,7 +70,7 @@ class AnEncoding
|
|
65
70
|
attr_accessor :filename, :empty, :encoding
|
66
71
|
|
67
72
|
def self.parse(filename, file_line)
|
68
|
-
if file_line =~ DNE
|
73
|
+
if file_line =~ DNE
|
69
74
|
AnEncoding.new(filename, false, NO_SUCH_FILE)
|
70
75
|
else
|
71
76
|
match = file_line.match(PARSER)
|
@@ -85,12 +90,12 @@ class AnEncoding
|
|
85
90
|
|
86
91
|
def violate?(rules)
|
87
92
|
# Ignore empty files, which are considered binary.
|
88
|
-
if @empty
|
93
|
+
if @empty
|
89
94
|
false
|
90
95
|
else
|
91
96
|
preferred = rules.select { |rule| filename =~ rule.first }.first[1]
|
92
97
|
|
93
|
-
if ! (encoding =~ preferred)
|
98
|
+
if ! (encoding =~ preferred)
|
94
99
|
[encoding, preferred]
|
95
100
|
else
|
96
101
|
false
|
@@ -99,11 +104,11 @@ class AnEncoding
|
|
99
104
|
end
|
100
105
|
|
101
106
|
def to_s(encoding_difference = false)
|
102
|
-
if encoding_difference
|
107
|
+
if encoding_difference
|
103
108
|
observed = encoding_difference[0]
|
104
109
|
preferred = encoding_difference[1].inspect
|
105
110
|
|
106
|
-
if observed == NO_SUCH_FILE
|
111
|
+
if observed == NO_SUCH_FILE
|
107
112
|
"#{@filename}: #{NO_SUCH_FILE}"
|
108
113
|
else
|
109
114
|
"#{@filename}: observed #{observed} preferred: #{preferred}"
|
@@ -122,14 +127,16 @@ def self.recursive_list(directory, ignores = DEFAULT_IGNORES)
|
|
122
127
|
end
|
123
128
|
end
|
124
129
|
|
125
|
-
def self.check(filename,
|
130
|
+
def self.check(filename, configuration = DEFAULT_CONFIGURATION)
|
131
|
+
rules = configuration['rules']
|
132
|
+
|
133
|
+
# puts "Rules: #{rules}"
|
134
|
+
|
126
135
|
line = `file #{MIME_FLAG} "#{filename}" 2>&1`
|
127
136
|
|
128
137
|
encoding = AnEncoding.parse(filename, line)
|
129
138
|
|
130
139
|
encoding_difference = encoding.violate?(rules)
|
131
140
|
|
132
|
-
if encoding_difference
|
133
|
-
puts encoding.to_s(encoding_difference)
|
134
|
-
end
|
141
|
+
puts encoding.to_s(encoding_difference) if encoding_difference
|
135
142
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Pennebaker
|
@@ -241,10 +241,10 @@ executables:
|
|
241
241
|
extensions: []
|
242
242
|
extra_rdoc_files: []
|
243
243
|
files:
|
244
|
-
- lib/enlint.rb
|
245
|
-
- lib/version.rb
|
246
244
|
- LICENSE.md
|
247
245
|
- bin/enlint
|
246
|
+
- lib/enlint.rb
|
247
|
+
- lib/version.rb
|
248
248
|
homepage: https://github.com/mcandre/enlint
|
249
249
|
licenses:
|
250
250
|
- FreeBSD
|
@@ -265,9 +265,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
265
265
|
version: '0'
|
266
266
|
requirements: []
|
267
267
|
rubyforge_project:
|
268
|
-
rubygems_version: 2.
|
268
|
+
rubygems_version: 2.2.2
|
269
269
|
signing_key:
|
270
270
|
specification_version: 4
|
271
271
|
summary: encoding linter
|
272
272
|
test_files: []
|
273
|
-
has_rdoc:
|