enlint 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/enlint +13 -59
  3. data/lib/enlint.rb +56 -32
  4. data/lib/version.rb +1 -1
  5. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 22767de80b9fa973581afb14aa5443c9f6ed5f5d
4
- data.tar.gz: 212a81cae4d05cebef59d4694aa99ccb37a30184
3
+ metadata.gz: e1f0469cab9473fbcdcc79df7e0517a04a8332e9
4
+ data.tar.gz: 271b8ed696b22de4b9d19d42b9170be43ee806c0
5
5
  SHA512:
6
- metadata.gz: 406b8284ab6084930461a7a07cb7196a16a5319ab0e9669853e54228235fa3ba224122ec9569ddda10b49fe8dd55a4261f6d084edb649d12fb8405dddddbb753
7
- data.tar.gz: 7bbd4dbd40d8a4aabd9126087e46d39ae20d278c8c21a026d748dd6809c0ad4b5a2eb1694697642ced91564cb991743184a42e9cf15709ecb149edd3b2996faf
6
+ metadata.gz: 02a97d6a57ac51cbfc9a254fe3925c377c6fc354aeedf7e29eedfe4d2be913045254891a57269ec55f7428d63a48fc3006ab9249a20199285ec90e2b364576b3
7
+ data.tar.gz: e6501d0a886ed76fd5839931475926dbf377cf5bc828ca3e67c6a861e9ea610502fac8c8de4a85e9235497a82b5d99a2f92dcb7d5509c89a0211355fe0b8bbb5
data/bin/enlint CHANGED
@@ -3,23 +3,18 @@
3
3
  require 'rubygems'
4
4
  require 'find'
5
5
  require 'optparse'
6
- require 'yaml'
6
+ require 'dotsmack'
7
7
  require 'enlint'
8
8
 
9
- IGNORE_FILENAME = '.enlintignore'
10
- CONFIGURATION_FILENAME = '.enlintrc.yml'
11
-
12
9
  def main
13
10
  ignores = DEFAULT_IGNORES
14
11
 
15
- filenames = ['.']
16
-
17
12
  configuration_flags = {}
18
13
 
19
14
  option = OptionParser.new do |option|
20
15
  option.banner = 'Usage: enlint [options] [<files>]'
21
16
 
22
- option.on('-i', '--ignore pattern', 'Ignore file names matching Ruby regex pattern') do |pattern|
17
+ option.on('-i', '--ignore pattern', 'Ignore file patterns (fnmatch)') do |pattern|
23
18
  ignores << pattern
24
19
  end
25
20
 
@@ -36,62 +31,21 @@ def main
36
31
 
37
32
  option.parse!
38
33
 
39
- filenames = ARGV unless ARGV.empty?
40
-
41
- recursive_filenames = []
42
-
43
- filenames.each do |f|
44
- if File.directory? f
45
- recursive_filenames = recursive_filenames.concat(recursive_list(f, ignores))
34
+ filenames =
35
+ if ARGV == []
36
+ ['.']
46
37
  else
47
- recursive_filenames << f
38
+ ARGV
48
39
  end
49
- end
50
40
 
51
- configuration_dotfile = DEFAULT_CONFIGURATION
41
+ dotsmack = Dotsmack::Smacker.new(
42
+ dotignore = '.enlintignore',
43
+ additional_ignores = ignores,
44
+ dotconfig = '.enlintrc.yml',
45
+ )
52
46
 
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
47
+ dotsmack.enumerate(filenames).each do |filename, config|
48
+ check(filename, config)
95
49
  end
96
50
  end
97
51
 
@@ -1,24 +1,51 @@
1
- require 'rubygems'
2
1
  require 'ptools'
2
+ require 'yaml'
3
3
 
4
- require 'version'
4
+ require_relative 'version'
5
5
 
6
6
  DEFAULT_IGNORES = %w(
7
- \.hg/
8
- \.svn/
9
- \.git/
10
- \.gitignore
11
- node_modules/
12
- \.vagrant/
13
- Gemfile\.lock
14
- \.exe
15
- \.bin
16
- \.pdf
17
- \.png
18
- \.jpg
19
- \.jpeg
20
- \.min.js
21
- -min\.js
7
+ tmp
8
+ .hg
9
+ .svn
10
+ .git
11
+ .gitignore
12
+ node_modules
13
+ bower_components
14
+ target
15
+ dist
16
+ .vagrant
17
+ Gemfile.lock
18
+ *.exe
19
+ *.bin
20
+ *.apk
21
+ *.ap_
22
+ res
23
+ *.dmg
24
+ *.pkg
25
+ *.app
26
+ *.xcodeproj
27
+ *.lproj
28
+ *.xcassets
29
+ *.pmdoc
30
+ *.dSYM
31
+ *.class
32
+ *.zip
33
+ *.jar
34
+ *.war
35
+ *.xpi
36
+ *.jad
37
+ *.cmo
38
+ *.cmi
39
+ *.pdf
40
+ *.dot
41
+ *.png
42
+ *.gif
43
+ *.jpg
44
+ *.jpeg
45
+ *.tiff
46
+ *.ico
47
+ *.wav
48
+ *.mp3
22
49
  )
23
50
 
24
51
  #
@@ -26,10 +53,8 @@ DEFAULT_IGNORES = %w(
26
53
  # Only the earliest file pattern match's rule applies.
27
54
  #
28
55
  DEFAULT_RULES = [
29
- [/\.reg$/, /(ascii|utf-16)/],
30
- [/\.bat$/, /(ascii|utf-16)/],
31
- [/\.ps1$/, /(ascii|utf-16)/],
32
- [/.*/, /(utf-8|ascii|binary|unknown)/]
56
+ ['*.{reg,bat,ps1}', /(ascii|utf-16)/],
57
+ ['*', /(utf-8|ascii|binary|unknown)/]
33
58
  ]
34
59
 
35
60
  DEFAULT_CONFIGURATION = {
@@ -93,7 +118,9 @@ class AnEncoding
93
118
  if @empty
94
119
  false
95
120
  else
96
- preferred = rules.select { |rule| filename =~ rule.first }.first[1]
121
+ preferred = rules.select do |rule|
122
+ Dotsmack::fnmatch?(rule.first, filename)
123
+ end.first[1]
97
124
 
98
125
  if ! (encoding =~ preferred)
99
126
  [encoding, preferred]
@@ -119,19 +146,16 @@ class AnEncoding
119
146
  end
120
147
  end
121
148
 
122
- def self.recursive_list(directory, ignores = DEFAULT_IGNORES)
123
- Find.find(directory).reject do |f|
124
- File.directory?(f) ||
125
- ignores.any? { |ignore| f =~ /#{ignore}/ } ||
126
- File.binary?(f)
127
- end
128
- end
149
+ def self.check(filename, configuration = nil)
150
+ configuration =
151
+ if configuration.nil?
152
+ DEFAULT_CONFIGURATION
153
+ else
154
+ DEFAULT_CONFIGURATION.merge(YAML.load(configuration))
155
+ end
129
156
 
130
- def self.check(filename, configuration = DEFAULT_CONFIGURATION)
131
157
  rules = configuration['rules']
132
158
 
133
- # puts "Rules: #{rules}"
134
-
135
159
  line = `file #{MIME_FLAG} "#{filename}" 2>&1`
136
160
 
137
161
  encoding = AnEncoding.parse(filename, line)
@@ -2,5 +2,5 @@
2
2
  # EnLint
3
3
  #
4
4
  module EnLint
5
- VERSION = '0.4'
5
+ VERSION = '0.5'
6
6
  end
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'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Pennebaker
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotsmack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.3'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -257,7 +271,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
271
  requirements:
258
272
  - - '>='
259
273
  - !ruby/object:Gem::Version
260
- version: '0'
274
+ version: '2.0'
261
275
  required_rubygems_version: !ruby/object:Gem::Requirement
262
276
  requirements:
263
277
  - - '>='
@@ -265,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
265
279
  version: '0'
266
280
  requirements: []
267
281
  rubyforge_project:
268
- rubygems_version: 2.2.2
282
+ rubygems_version: 2.4.6
269
283
  signing_key:
270
284
  specification_version: 4
271
285
  summary: encoding linter