fasterer 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fasterer/cli.rb +1 -1
- data/lib/fasterer/file_traverser.rb +28 -9
- data/lib/fasterer/version.rb +1 -1
- data/spec/lib/fasterer/file_traverser_spec.rb +149 -100
- data/spec/spec_helper.rb +3 -78
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bd16fef20d165a6c0bd45c9c360234396612eb2
|
4
|
+
data.tar.gz: 2c4befcae361090c9bceed13cbc2e293bd2c311f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70a2638a04aebaab8dcecc7d27e28767a5c03b1193edd06acad819f89a83e12d7c1a367902e4c75eda2965be640755a7544fc9932144a569da3b18fcad822304
|
7
|
+
data.tar.gz: 8f502d31f594eeff788d51c56008fae99bbe951489682428720a87328beac04cf2ea42b5c94e5644042451b4cbe29608f88ff2cada39aae3f5afff808a8ed321
|
data/lib/fasterer/cli.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
require 'colorize'
|
3
3
|
require 'English'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
require_relative 'analyzer'
|
6
7
|
require_relative 'config'
|
@@ -16,19 +17,15 @@ module Fasterer
|
|
16
17
|
attr_accessor :offenses_total_count
|
17
18
|
|
18
19
|
def initialize(path)
|
19
|
-
@path = Pathname(path)
|
20
|
+
@path = Pathname(path || '.')
|
20
21
|
@parse_error_paths = []
|
21
22
|
@config = Config.new
|
22
23
|
@offenses_total_count = 0
|
23
24
|
end
|
24
25
|
|
25
26
|
def traverse
|
26
|
-
|
27
|
-
|
28
|
-
else
|
29
|
-
scan_file(@path)
|
30
|
-
end
|
31
|
-
output_parse_errors if parse_error_paths.any?
|
27
|
+
traverse_files
|
28
|
+
output_parse_errors
|
32
29
|
output_statistics
|
33
30
|
end
|
34
31
|
|
@@ -48,6 +45,14 @@ module Fasterer
|
|
48
45
|
|
49
46
|
attr_accessor :offenses_found
|
50
47
|
|
48
|
+
def traverse_files
|
49
|
+
if @path.exist?
|
50
|
+
scannable_files.each { |ruby_file| scan_file(ruby_file) }
|
51
|
+
else
|
52
|
+
output_unable_to_find_file(@path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
51
56
|
def scan_file(path)
|
52
57
|
analyzer = Analyzer.new(path)
|
53
58
|
analyzer.scan
|
@@ -62,11 +67,19 @@ module Fasterer
|
|
62
67
|
end
|
63
68
|
|
64
69
|
def all_files
|
65
|
-
|
66
|
-
|
70
|
+
if @path.directory?
|
71
|
+
Dir[File.join(@path, '**', '*.rb')].map do |ruby_file_path|
|
72
|
+
Pathname(ruby_file_path).relative_path_from(root_dir).to_s
|
73
|
+
end
|
74
|
+
else
|
75
|
+
[@path.to_s]
|
67
76
|
end
|
68
77
|
end
|
69
78
|
|
79
|
+
def root_dir
|
80
|
+
@root_dir ||= Pathname('.')
|
81
|
+
end
|
82
|
+
|
70
83
|
def output(analyzer)
|
71
84
|
puts analyzer.file_path.colorize(:red)
|
72
85
|
|
@@ -85,6 +98,8 @@ module Fasterer
|
|
85
98
|
end
|
86
99
|
|
87
100
|
def output_parse_errors
|
101
|
+
return if parse_error_paths.none?
|
102
|
+
|
88
103
|
puts 'Fasterer was unable to process some files because the'
|
89
104
|
puts 'internal parser is not able to read some characters or'
|
90
105
|
puts 'has timed out. Unprocessable files were:'
|
@@ -97,6 +112,10 @@ module Fasterer
|
|
97
112
|
puts Statistics.new(self)
|
98
113
|
end
|
99
114
|
|
115
|
+
def output_unable_to_find_file(path)
|
116
|
+
puts "No such file or directory - #{path}".colorize(:red)
|
117
|
+
end
|
118
|
+
|
100
119
|
def ignored_speedups
|
101
120
|
config.ignored_speedups
|
102
121
|
end
|
data/lib/fasterer/version.rb
CHANGED
@@ -121,153 +121,202 @@ describe Fasterer::FileTraverser do
|
|
121
121
|
end
|
122
122
|
|
123
123
|
describe 'scannable files' do
|
124
|
-
|
125
|
-
let(:file_traverser) { Fasterer::FileTraverser.new('.') }
|
124
|
+
let(:file_traverser) { Fasterer::FileTraverser.new(argument) }
|
126
125
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
end
|
126
|
+
describe 'with no ARGV' do
|
127
|
+
let(:argument) { '.' }
|
131
128
|
|
132
|
-
|
133
|
-
|
134
|
-
|
129
|
+
context 'when no files in folder' do
|
130
|
+
it 'returns empty array' do
|
131
|
+
expect(file_traverser.scannable_files).to eq([])
|
132
|
+
end
|
135
133
|
end
|
136
134
|
|
137
|
-
|
135
|
+
context 'only a non-ruby file inside' do
|
136
|
+
before do
|
137
|
+
create_file('something.yml')
|
138
|
+
end
|
138
139
|
|
139
|
-
|
140
|
-
|
140
|
+
it 'returns empty array' do
|
141
|
+
expect(file_traverser.scannable_files).to eq([])
|
142
|
+
end
|
141
143
|
end
|
142
|
-
end
|
143
144
|
|
144
|
-
|
145
|
-
|
145
|
+
context 'a ruby file inside' do
|
146
|
+
let(:file_name) { 'something.rb' }
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
before do
|
149
|
+
create_file(file_name)
|
150
|
+
end
|
150
151
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
expect(file_traverser.send(:scannable_files)).to eq([file_name])
|
152
|
+
it 'returns array with that file inside' do
|
153
|
+
expect(file_traverser.scannable_files).to eq([file_name])
|
154
|
+
end
|
155
155
|
end
|
156
|
-
end
|
157
156
|
|
158
|
-
|
159
|
-
|
157
|
+
context 'a ruby file inside that is ignored' do
|
158
|
+
let(:file_name) { 'something.rb' }
|
160
159
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
160
|
+
let(:config_file_content) do
|
161
|
+
"exclude_paths:\n"\
|
162
|
+
" - '#{file_name}'"
|
163
|
+
end
|
165
164
|
|
166
|
-
|
167
|
-
|
168
|
-
|
165
|
+
before(:each) do
|
166
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME,
|
167
|
+
config_file_content)
|
168
|
+
|
169
|
+
create_file(file_name)
|
170
|
+
end
|
169
171
|
|
170
|
-
|
172
|
+
it 'returns empty array' do
|
173
|
+
expect(file_traverser.scannable_files).to eq([])
|
174
|
+
end
|
171
175
|
end
|
172
176
|
|
173
|
-
|
177
|
+
context 'a ruby file inside that is not ignored' do
|
178
|
+
let(:file_name) { 'something.rb' }
|
174
179
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
180
|
+
let(:config_file_content) do
|
181
|
+
"exclude_paths:\n"\
|
182
|
+
" - 'sumthing.rb'"
|
183
|
+
end
|
179
184
|
|
180
|
-
|
181
|
-
|
185
|
+
before(:each) do
|
186
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME, config_file_content)
|
187
|
+
create_file(file_name)
|
188
|
+
end
|
182
189
|
|
183
|
-
|
184
|
-
|
185
|
-
|
190
|
+
it 'returns empty array' do
|
191
|
+
expect(file_traverser.scannable_files).to eq([file_name])
|
192
|
+
end
|
186
193
|
end
|
187
194
|
|
188
|
-
|
189
|
-
|
190
|
-
|
195
|
+
context 'nested ruby files' do
|
196
|
+
before(:each) do
|
197
|
+
create_file('something.rb')
|
198
|
+
create_file('nested/something.rb')
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'returns files properly' do
|
202
|
+
expect(file_traverser.scannable_files)
|
203
|
+
.to match_array(['something.rb', 'nested/something.rb'])
|
204
|
+
end
|
191
205
|
end
|
192
206
|
|
193
|
-
|
207
|
+
context 'ruby files but nested ignored explicitly' do
|
208
|
+
let(:config_file_content) do
|
209
|
+
"exclude_paths:\n"\
|
210
|
+
" - 'nested/something.rb'"
|
211
|
+
end
|
194
212
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
213
|
+
before(:each) do
|
214
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME, config_file_content)
|
215
|
+
create_file('something.rb')
|
216
|
+
create_file('nested/something.rb')
|
217
|
+
end
|
199
218
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
219
|
+
it 'returns unignored files' do
|
220
|
+
expect(file_traverser.scannable_files)
|
221
|
+
.to match_array(['something.rb'])
|
222
|
+
end
|
204
223
|
end
|
205
224
|
|
206
|
-
|
225
|
+
context 'ruby files but nested ignored with *' do
|
226
|
+
let(:config_file_content) do
|
227
|
+
"exclude_paths:\n"\
|
228
|
+
" - 'nested/*'"
|
229
|
+
end
|
207
230
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
231
|
+
before(:each) do
|
232
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME, config_file_content)
|
233
|
+
create_file('something.rb')
|
234
|
+
create_file('nested/something.rb')
|
235
|
+
end
|
213
236
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
237
|
+
it 'returns unignored files' do
|
238
|
+
expect(file_traverser.scannable_files)
|
239
|
+
.to match_array(['something.rb'])
|
240
|
+
end
|
218
241
|
end
|
219
242
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
243
|
+
context 'ruby files but unnested ignored' do
|
244
|
+
let(:config_file_content) do
|
245
|
+
"exclude_paths:\n"\
|
246
|
+
" - 'something.rb'"
|
247
|
+
end
|
225
248
|
|
226
|
-
|
249
|
+
before(:each) do
|
250
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME, config_file_content)
|
251
|
+
create_file('something.rb')
|
252
|
+
create_file('nested/something.rb')
|
253
|
+
end
|
227
254
|
|
228
|
-
|
229
|
-
|
230
|
-
|
255
|
+
it 'returns unignored files' do
|
256
|
+
expect(file_traverser.scannable_files).to match_array(['nested/something.rb'])
|
257
|
+
end
|
231
258
|
end
|
232
259
|
end
|
233
260
|
|
234
|
-
|
235
|
-
let(:
|
236
|
-
"exclude_paths:\n"\
|
237
|
-
" - 'nested/*'"
|
238
|
-
end
|
261
|
+
describe 'with one file argument' do
|
262
|
+
let(:argument) { 'something.rb' }
|
239
263
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
264
|
+
context 'and no config file' do
|
265
|
+
before do
|
266
|
+
create_file('something.rb')
|
267
|
+
end
|
268
|
+
|
269
|
+
it 'returns that file' do
|
270
|
+
expect(file_traverser.scannable_files).to match_array([argument])
|
271
|
+
end
|
244
272
|
end
|
245
273
|
|
246
|
-
|
274
|
+
context 'and config file ignoring it' do
|
275
|
+
let(:config_file_content) do
|
276
|
+
"exclude_paths:\n"\
|
277
|
+
" - 'something.rb'"
|
278
|
+
end
|
247
279
|
|
248
|
-
|
249
|
-
|
250
|
-
|
280
|
+
before do
|
281
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME, config_file_content)
|
282
|
+
create_file('something.rb')
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'returns empty array' do
|
286
|
+
expect(file_traverser.scannable_files).to match_array([])
|
287
|
+
end
|
251
288
|
end
|
252
289
|
end
|
253
290
|
|
254
|
-
|
255
|
-
let(:
|
256
|
-
"exclude_paths:\n"\
|
257
|
-
" - 'something.rb'"
|
258
|
-
end
|
291
|
+
describe 'with one folder argument' do
|
292
|
+
let(:argument) { 'nested/' }
|
259
293
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
294
|
+
let(:file_names) { ['nested/something.rb', 'nested/something_else.rb'] }
|
295
|
+
|
296
|
+
context 'and no config file' do
|
297
|
+
before do
|
298
|
+
file_names.each { |file_name| create_file(file_name) }
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'returns those files' do
|
302
|
+
expect(file_traverser.scannable_files).to match_array(file_names)
|
303
|
+
end
|
264
304
|
end
|
265
305
|
|
266
|
-
|
306
|
+
context 'and config file ignoring it' do
|
307
|
+
let(:config_file_content) do
|
308
|
+
"exclude_paths:\n"\
|
309
|
+
" - 'nested/*'"
|
310
|
+
end
|
311
|
+
|
312
|
+
before do
|
313
|
+
create_file(Fasterer::FileTraverser::CONFIG_FILE_NAME, config_file_content)
|
314
|
+
file_names.each { |file_name| create_file(file_name) }
|
315
|
+
end
|
267
316
|
|
268
|
-
|
269
|
-
|
270
|
-
|
317
|
+
it 'returns empty array' do
|
318
|
+
expect(file_traverser.scannable_files).to match_array([])
|
319
|
+
end
|
271
320
|
end
|
272
321
|
end
|
273
322
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,6 +8,7 @@ end
|
|
8
8
|
require 'fasterer'
|
9
9
|
require 'fasterer/cli'
|
10
10
|
require 'pry'
|
11
|
+
|
11
12
|
Dir["#{File.dirname(__FILE__)}/support/*.rb"].each { |f| require f }
|
12
13
|
|
13
14
|
if ENV['TRAVIS']
|
@@ -19,92 +20,16 @@ def RSpec.root
|
|
19
20
|
@root_path = Pathname.new(File.dirname(__FILE__))
|
20
21
|
end
|
21
22
|
|
22
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
23
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
24
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
25
|
-
# file to always be loaded, without a need to explicitly require it in any files.
|
26
|
-
#
|
27
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
28
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
29
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
30
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
31
|
-
# a separate helper file that requires the additional dependencies and performs
|
32
|
-
# the additional setup, and require it from the spec files that actually need it.
|
33
|
-
#
|
34
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
35
|
-
# users commonly want.
|
36
|
-
#
|
37
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
38
23
|
RSpec.configure do |config|
|
39
|
-
# rspec-expectations config goes here. You can use an alternate
|
40
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
41
|
-
# assertions if you prefer.
|
42
24
|
config.expect_with :rspec do |expectations|
|
43
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
44
|
-
# and `failure_message` of custom matchers include text for helper methods
|
45
|
-
# defined using `chain`, e.g.:
|
46
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
47
|
-
# # => "be bigger than 2 and smaller than 4"
|
48
|
-
# ...rather than:
|
49
|
-
# # => "be bigger than 2"
|
50
25
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
51
26
|
end
|
52
27
|
|
53
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
54
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
55
28
|
config.mock_with :rspec do |mocks|
|
56
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
57
|
-
# a real object. This is generally recommended, and will default to
|
58
|
-
# `true` in RSpec 4.
|
59
29
|
mocks.verify_partial_doubles = true
|
60
30
|
end
|
61
31
|
|
62
|
-
|
63
|
-
|
64
|
-
=begin
|
65
|
-
# These two settings work together to allow you to limit a spec run
|
66
|
-
# to individual examples or groups you care about by tagging them with
|
67
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
68
|
-
# get run.
|
69
|
-
config.filter_run :focus
|
70
|
-
config.run_all_when_everything_filtered = true
|
71
|
-
|
72
|
-
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
73
|
-
# For more details, see:
|
74
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
75
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
76
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
77
|
-
config.disable_monkey_patching!
|
78
|
-
|
79
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
80
|
-
# be too noisy due to issues in dependencies.
|
81
|
-
config.warnings = true
|
82
|
-
|
83
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
84
|
-
# file, and it's useful to allow more verbose output when running an
|
85
|
-
# individual spec file.
|
86
|
-
if config.files_to_run.one?
|
87
|
-
# Use the documentation formatter for detailed output,
|
88
|
-
# unless a formatter has already been configured
|
89
|
-
# (e.g. via a command-line flag).
|
90
|
-
config.default_formatter = 'doc'
|
32
|
+
config.before(:each) do
|
33
|
+
allow_any_instance_of(Fasterer::FileTraverser).to receive(:puts).and_return(nil)
|
91
34
|
end
|
92
|
-
|
93
|
-
# Print the 10 slowest examples and example groups at the
|
94
|
-
# end of the spec run, to help surface which specs are running
|
95
|
-
# particularly slow.
|
96
|
-
config.profile_examples = 10
|
97
|
-
|
98
|
-
# Run specs in random order to surface order dependencies. If you find an
|
99
|
-
# order dependency and want to debug it, you can fix the order by providing
|
100
|
-
# the seed, which is printed after each run.
|
101
|
-
# --seed 1234
|
102
|
-
config.order = :random
|
103
|
-
|
104
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
105
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
106
|
-
# test failures related to randomization by passing the same `--seed` value
|
107
|
-
# as the one that triggered the failure.
|
108
|
-
Kernel.srand config.seed
|
109
|
-
=end
|
110
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fasterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damir Svrtan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|