enlint 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.md +23 -0
- data/bin/enlint +58 -0
- data/lib/enlint.rb +113 -0
- data/lib/version.rb +6 -0
- metadata +258 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07b94cdaaa325460bc0f1d2914aefc6062ec0abe
|
4
|
+
data.tar.gz: 4fdcb7ddf3cc9b5b64ca05357322df1cad0a595c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd3f7dd9531c43fd0c3bdd3fb9e64a386e5a63028eba051ac47e33890c2ff45cf690d6eaa160a39f251384a5716b2943579d071bc669aa52fa2a0a8eb99e4d4a
|
7
|
+
data.tar.gz: 09491a8f512067b8e4b2a49f850af707bf1ab3ab569686ca68a6ebae81c1d63ccf9c86531b9edfcf18daf1b870a7382fbf7f6ca90355b9f1a7c181052d4a10da
|
data/LICENSE.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# FreeBSD License
|
2
|
+
|
3
|
+
# Copyright 2014 Andrew Pennebaker. All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification,
|
6
|
+
are permitted provided that the following conditions are met:
|
7
|
+
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
9
|
+
list of conditions and the following disclaimer.
|
10
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
12
|
+
other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
15
|
+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
16
|
+
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
17
|
+
SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
18
|
+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
19
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
20
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
21
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
22
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
23
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/bin/enlint
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'enlint'
|
8
|
+
|
9
|
+
def main
|
10
|
+
ignores = DEFAULT_IGNORES
|
11
|
+
|
12
|
+
filenames = ['.']
|
13
|
+
|
14
|
+
option = OptionParser.new do |option|
|
15
|
+
option.banner = 'Usage: enlint [options] [<files>]'
|
16
|
+
|
17
|
+
option.on('-i', '--ignore pattern', 'Ignore file names matching Ruby regex pattern') do |pattern|
|
18
|
+
ignores << pattern
|
19
|
+
end
|
20
|
+
|
21
|
+
option.on('-h', '--help', 'Print usage info') do
|
22
|
+
puts option
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
|
26
|
+
option.on('-v', '--version', 'Print version info') do
|
27
|
+
puts "enlint #{EnLint::VERSION}"
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
option.parse!
|
33
|
+
|
34
|
+
filenames = ARGV unless ARGV.empty?
|
35
|
+
|
36
|
+
recursive_filenames = []
|
37
|
+
|
38
|
+
filenames.each do |f|
|
39
|
+
if File.directory? f
|
40
|
+
recursive_filenames = recursive_filenames.concat(recursive_list(f, ignores))
|
41
|
+
else
|
42
|
+
recursive_filenames << f
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
recursive_filenames.each { |f| check f }
|
47
|
+
end
|
48
|
+
|
49
|
+
begin
|
50
|
+
main
|
51
|
+
# User may quit enlint before completion.
|
52
|
+
rescue Interrupt
|
53
|
+
nil
|
54
|
+
# enlint may be piped to another program (e.g. `less`),
|
55
|
+
# which is quit before enlint completes.
|
56
|
+
rescue Errno::EPIPE, Errno::EMFILE
|
57
|
+
nil
|
58
|
+
end
|
data/lib/enlint.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'ptools'
|
3
|
+
|
4
|
+
require 'version'
|
5
|
+
|
6
|
+
DEFAULT_IGNORES = %w(
|
7
|
+
.hg/
|
8
|
+
.svn/
|
9
|
+
.git/
|
10
|
+
.git
|
11
|
+
.gitignore
|
12
|
+
node_modules/
|
13
|
+
.vagrant/
|
14
|
+
Gemfile.lock
|
15
|
+
.exe
|
16
|
+
.bin
|
17
|
+
.pdf
|
18
|
+
.png
|
19
|
+
.jpg
|
20
|
+
.jpeg
|
21
|
+
.svg
|
22
|
+
.min.js
|
23
|
+
-min.js
|
24
|
+
)
|
25
|
+
|
26
|
+
#
|
27
|
+
# Note that order is significant;
|
28
|
+
# Only the earliest file pattern match's rule applies.
|
29
|
+
#
|
30
|
+
DEFAULT_RULES = [
|
31
|
+
[/\.reg$/, /utf-16/],
|
32
|
+
[/.*/, /(utf-8|ascii|binary|unknown)/]
|
33
|
+
]
|
34
|
+
|
35
|
+
# Warning for files that do not exist
|
36
|
+
NO_SUCH_FILE = 'no such file'
|
37
|
+
|
38
|
+
#
|
39
|
+
# Parse, model, and print an encoding.
|
40
|
+
# Distinct from Ruby's built-in Encoding class.
|
41
|
+
#
|
42
|
+
class AnEncoding
|
43
|
+
attr_accessor :filename, :empty, :encoding
|
44
|
+
|
45
|
+
def self.parse(filename, file_line)
|
46
|
+
if file_line =~ /ERROR\:/ then
|
47
|
+
AnEncoding.new(filename, false, NO_SUCH_FILE)
|
48
|
+
else
|
49
|
+
match = file_line.match(/^.+\:\s+(.+);\s+charset=(.+)$/)
|
50
|
+
|
51
|
+
empty = match[1] == 'inode/x-empty'
|
52
|
+
encoding = match[2]
|
53
|
+
|
54
|
+
AnEncoding.new(filename, empty, encoding)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize(filename, empty, encoding)
|
59
|
+
@filename = filename
|
60
|
+
@empty = empty
|
61
|
+
@encoding = encoding
|
62
|
+
end
|
63
|
+
|
64
|
+
def violate?(rules)
|
65
|
+
# Ignore empty files, which are considered binary.
|
66
|
+
if @empty then
|
67
|
+
false
|
68
|
+
else
|
69
|
+
preferred = rules.select { |rule| filename =~ rule.first }.first[1]
|
70
|
+
|
71
|
+
if ! (encoding =~ preferred) then
|
72
|
+
[encoding, preferred]
|
73
|
+
else
|
74
|
+
false
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_s(encoding_difference = false)
|
80
|
+
if encoding_difference then
|
81
|
+
observed = encoding_difference[0]
|
82
|
+
preferred = encoding_difference[1].inspect
|
83
|
+
|
84
|
+
if observed == NO_SUCH_FILE then
|
85
|
+
"#{@filename}: #{NO_SUCH_FILE}"
|
86
|
+
else
|
87
|
+
"#{@filename}: observed #{observed} preferred: #{preferred}"
|
88
|
+
end
|
89
|
+
else
|
90
|
+
"#{@filename}: #{@encoding}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.recursive_list(directory, ignores = DEFAULT_IGNORES)
|
96
|
+
Find.find(directory).reject do |f|
|
97
|
+
File.directory?(f) ||
|
98
|
+
ignores.any? { |ignore| f =~ /#{ignore}/ } ||
|
99
|
+
File.binary?(f)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.check(filename, rules = DEFAULT_RULES)
|
104
|
+
line = `file -i "#{filename}" 2>&1`
|
105
|
+
|
106
|
+
encoding = AnEncoding.parse(filename, line)
|
107
|
+
|
108
|
+
encoding_difference = encoding.violate?(rules)
|
109
|
+
|
110
|
+
if encoding_difference then
|
111
|
+
puts encoding.to_s(encoding_difference)
|
112
|
+
end
|
113
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,258 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enlint
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Pennebaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ptools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: reek
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: flay
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: flog
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: roodi
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: churn
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: cane
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: excellent
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: tailor
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: guard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: guard-shell
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - '>='
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0.6'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - '>='
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0.6'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rspec
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - '>='
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: cucumber
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - '>='
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '>='
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
223
|
+
description: See README.md for example usage
|
224
|
+
email: andrew.pennebaker@gmail.com
|
225
|
+
executables:
|
226
|
+
- enlint
|
227
|
+
extensions: []
|
228
|
+
extra_rdoc_files: []
|
229
|
+
files:
|
230
|
+
- LICENSE.md
|
231
|
+
- bin/enlint
|
232
|
+
- lib/enlint.rb
|
233
|
+
- lib/version.rb
|
234
|
+
homepage: https://github.com/mcandre/enlint
|
235
|
+
licenses:
|
236
|
+
- FreeBSD
|
237
|
+
metadata: {}
|
238
|
+
post_install_message:
|
239
|
+
rdoc_options: []
|
240
|
+
require_paths:
|
241
|
+
- lib
|
242
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
243
|
+
requirements:
|
244
|
+
- - '>='
|
245
|
+
- !ruby/object:Gem::Version
|
246
|
+
version: '0'
|
247
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
248
|
+
requirements:
|
249
|
+
- - '>='
|
250
|
+
- !ruby/object:Gem::Version
|
251
|
+
version: '0'
|
252
|
+
requirements: []
|
253
|
+
rubyforge_project:
|
254
|
+
rubygems_version: 2.2.2
|
255
|
+
signing_key:
|
256
|
+
specification_version: 4
|
257
|
+
summary: encoding linter
|
258
|
+
test_files: []
|