fasterer 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.fasterer.yml +1 -0
- data/fasterer.gemspec +1 -1
- data/lib/fasterer/offense.rb +4 -1
- data/lib/fasterer/scanners/method_call_scanner.rb +11 -0
- data/lib/fasterer/version.rb +1 -1
- data/spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb +12 -0
- data/spec/support/analyzer/25_select_last_vs_reverse_detect.rb +7 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48ef235d9ddbd7e96e9e40c0543f593488f614f9
|
4
|
+
data.tar.gz: 43e7c00823bf1d792adef3bcf62e17b2c9a7f30b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdf479d3be8d49e4a9fcc9a287c96673d0e17590cf3b4e64602178a7dd04197ecee65e604eace3d1bdf453cfdfeedd38a08872dac646111a90fe69dd5e778b0b
|
7
|
+
data.tar.gz: 9ba93e58e71713d66aa2d0ef2465e13eabf9f1e91335c862add5bd6ddbdb779969b002f3cb968d454ec81ebff1eb254f8ecb5a69834714ddfb430991068e01a3
|
data/.fasterer.yml
CHANGED
data/fasterer.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
25
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
27
27
|
spec.add_development_dependency 'pry', '~> 0.10'
|
28
28
|
end
|
data/lib/fasterer/offense.rb
CHANGED
@@ -62,7 +62,10 @@ module Fasterer
|
|
62
62
|
'Calling blocks with call is slower than yielding',
|
63
63
|
|
64
64
|
gsub_vs_tr:
|
65
|
-
'Using tr is faster than gsub when replacing a single character in a string with another single character'
|
65
|
+
'Using tr is faster than gsub when replacing a single character in a string with another single character',
|
66
|
+
|
67
|
+
select_last_vs_reverse_detect:
|
68
|
+
'Array#select.last is slower than Array#reverse.detect'
|
66
69
|
}
|
67
70
|
|
68
71
|
end
|
@@ -39,6 +39,8 @@ module Fasterer
|
|
39
39
|
check_fetch_offense
|
40
40
|
when :merge!
|
41
41
|
check_merge_bang_offense
|
42
|
+
when :last
|
43
|
+
check_last_offense
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -142,5 +144,14 @@ module Fasterer
|
|
142
144
|
end
|
143
145
|
end
|
144
146
|
|
147
|
+
def check_last_offense
|
148
|
+
return method_call unless method_call.receiver.is_a?(MethodCall)
|
149
|
+
|
150
|
+
case method_call.receiver.name
|
151
|
+
when :select
|
152
|
+
add_offense(:select_last_vs_reverse_detect)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
145
156
|
end
|
146
157
|
end
|
data/lib/fasterer/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fasterer::Analyzer do
|
4
|
+
|
5
|
+
let(:test_file_path) { RSpec.root.join('support', 'analyzer', '25_select_last_vs_reverse_detect.rb') }
|
6
|
+
|
7
|
+
it 'should detect select last once' do
|
8
|
+
analyzer = Fasterer::Analyzer.new(test_file_path)
|
9
|
+
analyzer.scan
|
10
|
+
expect(analyzer.errors[:select_last_vs_reverse_detect].count).to eq(1)
|
11
|
+
end
|
12
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fasterer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damir Svrtan
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
75
|
+
version: '3.2'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
82
|
+
version: '3.2'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- spec/lib/fasterer/analyzer/18_block_vs_symbol_to_proc_spec.rb
|
148
148
|
- spec/lib/fasterer/analyzer/19_proc_call_vs_yield_spec.rb
|
149
149
|
- spec/lib/fasterer/analyzer/24_gsub_vs_tr_spec.rb
|
150
|
+
- spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb
|
150
151
|
- spec/lib/fasterer/analyzer/98_misc_spec.rb
|
151
152
|
- spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb
|
152
153
|
- spec/lib/fasterer/method_call_spec.rb
|
@@ -170,6 +171,7 @@ files:
|
|
170
171
|
- spec/support/analyzer/18_block_vs_symbol_to_proc.rb
|
171
172
|
- spec/support/analyzer/19_proc_call_vs_yield.rb
|
172
173
|
- spec/support/analyzer/24_gsub_vs_tr.rb
|
174
|
+
- spec/support/analyzer/25_select_last_vs_reverse_detect.rb
|
173
175
|
- spec/support/analyzer/98_misc.rb
|
174
176
|
- spec/support/analyzer/99_exceptional_files.rb
|
175
177
|
- spec/support/binary_call/simple_comparison.rb
|
@@ -244,6 +246,7 @@ test_files:
|
|
244
246
|
- spec/lib/fasterer/analyzer/18_block_vs_symbol_to_proc_spec.rb
|
245
247
|
- spec/lib/fasterer/analyzer/19_proc_call_vs_yield_spec.rb
|
246
248
|
- spec/lib/fasterer/analyzer/24_gsub_vs_tr_spec.rb
|
249
|
+
- spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb
|
247
250
|
- spec/lib/fasterer/analyzer/98_misc_spec.rb
|
248
251
|
- spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb
|
249
252
|
- spec/lib/fasterer/method_call_spec.rb
|
@@ -267,6 +270,7 @@ test_files:
|
|
267
270
|
- spec/support/analyzer/18_block_vs_symbol_to_proc.rb
|
268
271
|
- spec/support/analyzer/19_proc_call_vs_yield.rb
|
269
272
|
- spec/support/analyzer/24_gsub_vs_tr.rb
|
273
|
+
- spec/support/analyzer/25_select_last_vs_reverse_detect.rb
|
270
274
|
- spec/support/analyzer/98_misc.rb
|
271
275
|
- spec/support/analyzer/99_exceptional_files.rb
|
272
276
|
- spec/support/binary_call/simple_comparison.rb
|