fasterer 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 917099eee3733d73079d7cb3add928d81880351e
4
- data.tar.gz: 8de26edcf41f8919a38dc34d16f16d796f57ca2c
3
+ metadata.gz: 5fc06a003ad7ef35818e525f60ef7bc3bbc7b015
4
+ data.tar.gz: c33294e5d4ae9d8f731cf018ff4f6e834731e230
5
5
  SHA512:
6
- metadata.gz: 9db9bedccb3ffb027fdfce9dade3ca0ef33cd114e25c23f46491afb2bda5db1ef3af7b0e35655472a0219f4aef46acfd7545ff1270c22be23f189bc0d0662a34
7
- data.tar.gz: a71ed2ece3272ec0c027b9fc2b1f625a7406073a99284b4ed2c940b96b7b9f7813b8157a65625657531bfc656f527453627c894040cb1d9c8bc0191e67b1e98f
6
+ metadata.gz: 13e41010ea909bc9990f61ac6423b91855ce9ea8d17323ed10ed1ca8d44613e22e9929895dbc8e9cf213ebb1acc1613e24e89d2ffab2840f3d06c769ea52f278
7
+ data.tar.gz: 654bd69d4a16bffab862c955e50aba3e9364118a23436f6aaf10a912ac65376a6bb9e9db1e8cfabeeae3b850eb0f6c9c6dcfa0466e50da2370b1d6889bd593d5
@@ -88,6 +88,8 @@ module Fasterer
88
88
  return VariableReference.new(receiver_info)
89
89
  when :call, :iter
90
90
  return MethodCall.new(receiver_info)
91
+ when :array, :dot2, :dot3, :lit
92
+ return Primitive.new(receiver_info)
91
93
  end
92
94
  end
93
95
  end
@@ -116,4 +118,24 @@ module Fasterer
116
118
  @value ||= @element[1]
117
119
  end
118
120
  end
121
+
122
+ class Primitive
123
+ attr_reader :element
124
+
125
+ def initialize(element)
126
+ @element = element
127
+ end
128
+
129
+ def type
130
+ @type ||= @element[0]
131
+ end
132
+
133
+ def range?
134
+ [:dot2, :dot3, :lit].include?(type)
135
+ end
136
+
137
+ def array?
138
+ type == :array
139
+ end
140
+ end
119
141
  end
@@ -71,7 +71,10 @@ module Fasterer
71
71
  'Use attr_reader for reading ivars',
72
72
 
73
73
  setter_vs_attr_writer:
74
- 'Use attr_writer for writing to ivars'
74
+ 'Use attr_writer for writing to ivars',
75
+
76
+ include_vs_cover_on_range:
77
+ 'Use #cover? instead of #include? on ranges'
75
78
  }
76
79
 
77
80
  end
@@ -41,6 +41,8 @@ module Fasterer
41
41
  check_merge_bang_offense
42
42
  when :last
43
43
  check_last_offense
44
+ when :include?
45
+ check_range_include_offense
44
46
  end
45
47
  end
46
48
 
@@ -155,5 +157,10 @@ module Fasterer
155
157
  end
156
158
  end
157
159
 
160
+ def check_range_include_offense
161
+ if method_call.receiver.is_a?(Primitive) && method_call.receiver.range?
162
+ add_offense(:include_vs_cover_on_range)
163
+ end
164
+ end
158
165
  end
159
166
  end
@@ -1,3 +1,3 @@
1
1
  module Fasterer
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fasterer::Analyzer do
4
+
5
+ let(:test_file_path) do
6
+ RSpec.root.join('support', 'analyzer', '29_include_vs_cover_on_range.rb')
7
+ end
8
+
9
+ it 'should detect 3 include? method calls' do
10
+ analyzer = Fasterer::Analyzer.new(test_file_path)
11
+ analyzer.scan
12
+ expect(analyzer.errors[:include_vs_cover_on_range].count).to eq(3)
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ [1,2,3].include? 2
2
+
3
+ numbers = [1,2,3]
4
+
5
+ numbers.include? 2
6
+
7
+ def fast
8
+ (BEGIN_OF_JULY..END_OF_JULY).cover? DAY_IN_JULY
9
+ end
10
+
11
+ def slow
12
+ (BEGIN_OF_JULY..END_OF_JULY).include? DAY_IN_JULY
13
+ end
14
+
15
+ (10..1_000_000).include? 999
16
+
17
+ (BEGIN_OF_JULY...END_OF_JULY).include? DAY_IN_JULY
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.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damir Svrtan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-04 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -163,6 +163,7 @@ files:
163
163
  - spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb
164
164
  - spec/lib/fasterer/analyzer/26_getter_vs_attr_reader_spec.rb
165
165
  - spec/lib/fasterer/analyzer/27_setter_vs_attr_writer_spec.rb
166
+ - spec/lib/fasterer/analyzer/29_include_vs_cover_on_range_spec.rb
166
167
  - spec/lib/fasterer/analyzer/98_misc_spec.rb
167
168
  - spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb
168
169
  - spec/lib/fasterer/method_call_spec.rb
@@ -188,6 +189,7 @@ files:
188
189
  - spec/support/analyzer/25_select_last_vs_reverse_detect.rb
189
190
  - spec/support/analyzer/26_getter_vs_attr_reader.rb
190
191
  - spec/support/analyzer/27_setter_vs_attr_writer.rb
192
+ - spec/support/analyzer/29_include_vs_cover_on_range.rb
191
193
  - spec/support/analyzer/98_misc.rb
192
194
  - spec/support/analyzer/99_exceptional_files.rb
193
195
  - spec/support/binary_call/simple_comparison.rb
@@ -240,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
242
  version: '0'
241
243
  requirements: []
242
244
  rubyforge_project:
243
- rubygems_version: 2.2.2
245
+ rubygems_version: 2.4.5
244
246
  signing_key:
245
247
  specification_version: 4
246
248
  summary: Run Ruby more than fast. Fasterer
@@ -264,6 +266,7 @@ test_files:
264
266
  - spec/lib/fasterer/analyzer/25_select_last_vs_reverse_detect_spec.rb
265
267
  - spec/lib/fasterer/analyzer/26_getter_vs_attr_reader_spec.rb
266
268
  - spec/lib/fasterer/analyzer/27_setter_vs_attr_writer_spec.rb
269
+ - spec/lib/fasterer/analyzer/29_include_vs_cover_on_range_spec.rb
267
270
  - spec/lib/fasterer/analyzer/98_misc_spec.rb
268
271
  - spec/lib/fasterer/analyzer/99_exceptional_files_spec.rb
269
272
  - spec/lib/fasterer/method_call_spec.rb
@@ -289,6 +292,7 @@ test_files:
289
292
  - spec/support/analyzer/25_select_last_vs_reverse_detect.rb
290
293
  - spec/support/analyzer/26_getter_vs_attr_reader.rb
291
294
  - spec/support/analyzer/27_setter_vs_attr_writer.rb
295
+ - spec/support/analyzer/29_include_vs_cover_on_range.rb
292
296
  - spec/support/analyzer/98_misc.rb
293
297
  - spec/support/analyzer/99_exceptional_files.rb
294
298
  - spec/support/binary_call/simple_comparison.rb
@@ -321,3 +325,4 @@ test_files:
321
325
  - spec/support/rescue_call/rescue_with_multiple_classes.rb
322
326
  - spec/support/rescue_call/rescue_with_multiple_classes_and_variable.rb
323
327
  - spec/support/rescue_call/rescue_with_variable.rb
328
+ has_rdoc: