fasterer 0.1.9 → 0.1.10

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: 9166a1cbd984ee3e8af00277252f430d7efcc817
4
- data.tar.gz: 35ec0f0a4953e38f0145106c3523622461e9467c
3
+ metadata.gz: 917099eee3733d73079d7cb3add928d81880351e
4
+ data.tar.gz: 8de26edcf41f8919a38dc34d16f16d796f57ca2c
5
5
  SHA512:
6
- metadata.gz: 8f9774ae496a60c30b619155a53e1cf306ee1beed19e63fb601e4de2a40e3c435c0352daafeeb6d3de19ee7b9fde694d3493089cf36901197be939d80e376ca5
7
- data.tar.gz: 0bac8bc68e9f4d5032d12d9dd29a8b4cc99efc59338aefe15a262590f955fb97f2af2ed4cb6b25b0502992f48cc1b4e983d54aee2879789c81b9a1c9442073e3
6
+ metadata.gz: 9db9bedccb3ffb027fdfce9dade3ca0ef33cd114e25c23f46491afb2bda5db1ef3af7b0e35655472a0219f4aef46acfd7545ff1270c22be23f189bc0d0662a34
7
+ data.tar.gz: a71ed2ece3272ec0c027b9fc2b1f625a7406073a99284b4ed2c940b96b7b9f7813b8157a65625657531bfc656f527453627c894040cb1d9c8bc0191e67b1e98f
@@ -58,7 +58,7 @@ module Fasterer
58
58
  end
59
59
 
60
60
  def set_block_presence
61
- if element.sexp_type == :iter
61
+ if element.sexp_type == :iter || (arguments.last && arguments.last.type == :block_pass)
62
62
  @block_present = true
63
63
  end
64
64
  end
@@ -71,9 +71,9 @@ module Fasterer
71
71
 
72
72
  # TODO: write specs for lambdas and procs
73
73
  def set_block_argument_names
74
- @block_argument_names = if has_block? and element[2].is_a?(Sexp) # hack for lambdas
75
- element[2].drop(1).map { |argument| argument }
76
- end || []
74
+ @block_argument_names = if has_block? && element[2].is_a?(Sexp) # hack for lambdas
75
+ element[2].drop(1).map { |argument| argument }
76
+ end || []
77
77
  end
78
78
  end
79
79
 
@@ -102,7 +102,6 @@ module Fasterer
102
102
  end
103
103
 
104
104
  class Argument
105
-
106
105
  attr_reader :element
107
106
 
108
107
  def initialize(element)
@@ -83,6 +83,8 @@ module Fasterer
83
83
  when :shuffle
84
84
  add_offense(:shuffle_first_vs_sample)
85
85
  when :select
86
+ return unless method_call.receiver.has_block?
87
+
86
88
  add_offense(:select_first_vs_detect)
87
89
  end
88
90
  end
@@ -1,3 +1,3 @@
1
1
  module Fasterer
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
@@ -7,6 +7,6 @@ describe Fasterer::Analyzer do
7
7
  it 'should detect sort once' do
8
8
  analyzer = Fasterer::Analyzer.new(test_file_path)
9
9
  analyzer.scan
10
- expect(analyzer.errors[:select_first_vs_detect].count).to eq(2)
10
+ expect(analyzer.errors[:select_first_vs_detect].count).to eq(3)
11
11
  end
12
12
  end
@@ -466,6 +466,19 @@ describe Fasterer::MethodCall do
466
466
 
467
467
  end
468
468
 
469
+ describe 'method call with symbol to proc argument' do
470
+ let(:code) { '[].select(&:zero?)' }
471
+
472
+ let(:call_element) { ripper }
473
+
474
+ it 'should detect block pass argument' do
475
+ expect(method_call.method_name).to eq(:select)
476
+ expect(method_call.arguments.count).to eq(1)
477
+ expect(method_call.arguments[0].type).to eq(:block_pass)
478
+ expect(method_call.has_block?).to be
479
+ end
480
+ end
481
+
469
482
  describe 'method call with equals operator' do
470
483
 
471
484
  let(:code) { 'method_call_with_equals.rb' }
@@ -5,3 +5,7 @@ ARRAY.select { |x| x.eql?(15) }.first
5
5
  ARRAY.select do |x|
6
6
  x.eql?(15)
7
7
  end.first
8
+
9
+ ARRAY.select(&:zero?).first
10
+
11
+ ActiveRecordRelation.new.select('name').first
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.9
4
+ version: 0.1.10
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-04-09 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -321,4 +321,3 @@ test_files:
321
321
  - spec/support/rescue_call/rescue_with_multiple_classes.rb
322
322
  - spec/support/rescue_call/rescue_with_multiple_classes_and_variable.rb
323
323
  - spec/support/rescue_call/rescue_with_variable.rb
324
- has_rdoc: