pippi 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 896e82f6e2cf4dab869124c38159fada16b72b97
4
- data.tar.gz: ed2e62b742ffdc6a750c80d52a1e83ee00347ae1
3
+ metadata.gz: bd4bb5e3d9e8a7c1b97def8b8c81a3ebc1bcf6b1
4
+ data.tar.gz: ba99f8da56b5dcdb9a73989b377e76e9b1f006c0
5
5
  SHA512:
6
- metadata.gz: b97e79a1af7f290e69acb952ebf5fe1a35155b42ceda4b946c8a0bb44ae26c6da7459d4e86b57a315176fafb051b9ca3dbdd55d9aac0e0d538dc188a84e95f57
7
- data.tar.gz: 423bcbabce73b144fd9ecab55847cf0cf80380d9f02ecc4969af16389bb60a74f5bc3fe13e2db3e2a82fc2b03ae427f7ec3eaebd0b08196e06b4153f82a44500
6
+ metadata.gz: 5f59f05b8883eae2a0781097494d5a73cb25a25c673d593de4d011605012642763473c7ea7b6b95c592bcfde0d889bd171b7e2da3a78d4de120a82a685bb772e
7
+ data.tar.gz: e85313fc90ffaddc56a566e6a2016cd85e22ce5f8c506474c3e22cde50b8f0fc2a254b139e9df66a93b9285599a005a1f04107fdae418fd10dedc9a65aff4d30
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.0.8 (2014-12-04)
2
+
3
+ * [NEW] Added SelectFollowedByAny
4
+ * [FIXED] False positives reduced
5
+
1
6
  ## 0.0.7 (2014-12-01)
2
7
 
3
8
  * [FIXED] Support for Ruby 2.0
data/README.md CHANGED
@@ -141,6 +141,22 @@ Instead, consider doing this:
141
141
  [1,2,3].reverse_each {|x| x+1 }
142
142
  ```
143
143
 
144
+ #### SelectFollowedByAny
145
+
146
+ Don't use select followed by any?; use any? with a block instead
147
+
148
+ For example, rather than doing this:
149
+
150
+ ```ruby
151
+ [1,2,3].select {|x| x > 1 }.any?
152
+ ```
153
+
154
+ Instead, consider doing this:
155
+
156
+ ```ruby
157
+ [1,2,3].any? {|x| x > 1 }
158
+ ```
159
+
144
160
  #### SelectFollowedByEmpty
145
161
 
146
162
  Don't use select followed by empty?; use none? instead
@@ -330,6 +346,7 @@ rm -rf pippi_debug.log pippi.log .bundle/gems/pippi-0.0.1/ .bundle/cache/pippi-0
330
346
  * Tie off Changelog notes
331
347
  * Regenerate docs with `pippi:generate_docs`, copy and paste that into README
332
348
  * Commit, push
349
+ * Tag the release
333
350
  * `bundle exec gem build pippi.gemspec`
334
351
  * `gem push pippi-x.gem`
335
352
  * Update pippi_demo
data/doc/docs.md CHANGED
@@ -16,6 +16,22 @@ Instead, consider doing this:
16
16
  [1,2,3].reverse_each {|x| x+1 }
17
17
  ```
18
18
 
19
+ #### SelectFollowedByAny
20
+
21
+ Don't use select followed by any?; use any? with a block instead
22
+
23
+ For example, rather than doing this:
24
+
25
+ ```ruby
26
+ [1,2,3].select {|x| x > 1 }.any?
27
+ ```
28
+
29
+ Instead, consider doing this:
30
+
31
+ ```ruby
32
+ [1,2,3].any? {|x| x > 1 }
33
+ ```
34
+
19
35
  #### SelectFollowedByEmpty
20
36
 
21
37
  Don't use select followed by empty?; use none? instead
@@ -50,7 +66,7 @@ Instead, consider doing this:
50
66
 
51
67
  #### SelectFollowedBySelect
52
68
 
53
- Don't use select followed by select; use a single select instead
69
+ Don't use consecutive select blocks; use a single select instead
54
70
 
55
71
  For example, rather than doing this:
56
72
 
@@ -22,6 +22,7 @@ module Pippi
22
22
  "basic" => [
23
23
  "SelectFollowedByFirst",
24
24
  "SelectFollowedBySize",
25
+ "SelectFollowedByAny",
25
26
  "SelectFollowedByEmpty",
26
27
  "ReverseFollowedByEach",
27
28
  "SelectFollowedBySelect"
@@ -11,7 +11,7 @@ module Pippi::Checks
11
11
  end
12
12
 
13
13
  def method_names_that_indicate_this_is_being_used_as_a_collection
14
- [:collect!, :compact!, :flatten!, :map!, :reject!, :reverse!, :rotate!, :select!, :shuffle!, :slice!, :sort!, :sort_by!, :uniq!, :collect, :compact, :flatten, :map, :reject, :reverse, :rotate, :select, :shuffle, :slice, :sort, :sort_by, :uniq]
14
+ [:collect!, :compact!, :flatten!, :map!, :reject!, :reverse!, :rotate!, :select!, :shuffle!, :slice!, :sort!, :sort_by!, :uniq!, :collect, :compact, :first, :flatten, :join, :last, :map, :reject, :reverse, :rotate, :select, :shuffle, :slice, :sort, :sort_by, :uniq]
15
15
  end
16
16
 
17
17
  def add_problem
@@ -19,9 +19,8 @@ module Pippi::Checks
19
19
  ctx.report.add(Pippi::Problem.new(line_number: problem_location.lineno, file_path: problem_location.path, check_class: self.class))
20
20
  end
21
21
 
22
- def clear_fault_proc(clz)
22
+ def clear_fault_proc(clz, problem_location)
23
23
  proc do |*args, &blk|
24
- problem_location = caller_locations.find { |c| c.to_s !~ /byebug|lib\/pippi\/checks/ }
25
24
  clz.clear_fault(problem_location.lineno, problem_location.path)
26
25
  super(*args, &blk)
27
26
  end
@@ -0,0 +1,56 @@
1
+ module Pippi::Checks
2
+
3
+ class SelectFollowedByAny < Check
4
+
5
+ module MyAny
6
+ def any?(&blk)
7
+ self.class._pippi_check_select_followed_by_any.add_problem
8
+ problem_location = caller_locations.find { |c| c.to_s !~ /byebug|lib\/pippi\/checks/ }
9
+ self.class._pippi_check_select_followed_by_any.method_names_that_indicate_this_is_being_used_as_a_collection.each do |this_means_its_ok_sym|
10
+ define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_select_followed_by_any.clear_fault_proc(self.class._pippi_check_select_followed_by_any, problem_location))
11
+ end
12
+ super
13
+ end
14
+ end
15
+
16
+ module MySelect
17
+ def select(&blk)
18
+ result = super
19
+ if self.class._pippi_check_select_followed_by_any.nil?
20
+ # Ignore Array subclasses since select or any may have difference meanings
21
+ # elsif defined?(ActiveRecord::Relation) && self.class.kind_of?(ActiveRecord::Relation) # maybe also this
22
+ else
23
+ result.extend MyAny
24
+ self.class._pippi_check_select_followed_by_any.array_mutator_methods.each do |this_means_its_ok_sym|
25
+ result.define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_select_followed_by_any.its_ok_watcher_proc(MyAny, :any?))
26
+ end
27
+ end
28
+ result
29
+ end
30
+ end
31
+
32
+ def decorate
33
+ Array.class_exec(self) do |my_check|
34
+ @_pippi_check_select_followed_by_any = my_check
35
+ def self._pippi_check_select_followed_by_any
36
+ @_pippi_check_select_followed_by_any
37
+ end
38
+ prepend MySelect
39
+ end
40
+ end
41
+
42
+ class Documentation
43
+ def description
44
+ "Don't use select followed by any?; use any? with a block instead"
45
+ end
46
+ def sample
47
+ "[1,2,3].select {|x| x > 1 }.any?"
48
+ end
49
+ def instead_use
50
+ "[1,2,3].any? {|x| x > 1 }"
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -5,8 +5,9 @@ module Pippi::Checks
5
5
  module MyEmpty
6
6
  def empty?(&blk)
7
7
  self.class._pippi_check_select_followed_by_empty.add_problem
8
+ problem_location = caller_locations.find { |c| c.to_s !~ /byebug|lib\/pippi\/checks/ }
8
9
  self.class._pippi_check_select_followed_by_empty.method_names_that_indicate_this_is_being_used_as_a_collection.each do |this_means_its_ok_sym|
9
- define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_select_followed_by_empty.clear_fault_proc(self.class._pippi_check_select_followed_by_empty))
10
+ define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_select_followed_by_empty.clear_fault_proc(self.class._pippi_check_select_followed_by_empty, problem_location))
10
11
  end
11
12
  super
12
13
  end
@@ -3,8 +3,9 @@ module Pippi::Checks
3
3
  module MySize
4
4
  def size
5
5
  self.class._pippi_check_select_followed_by_size.add_problem
6
+ problem_location = caller_locations.find { |c| c.to_s !~ /byebug|lib\/pippi\/checks/ }
6
7
  self.class._pippi_check_select_followed_by_size.method_names_that_indicate_this_is_being_used_as_a_collection.each do |this_means_its_ok_sym|
7
- define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_select_followed_by_size.clear_fault_proc(self.class._pippi_check_select_followed_by_size))
8
+ define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_select_followed_by_size.clear_fault_proc(self.class._pippi_check_select_followed_by_size, problem_location))
8
9
  end
9
10
  super()
10
11
  end
data/lib/pippi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pippi
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
data/lib/pippi.rb CHANGED
@@ -13,6 +13,7 @@ require 'pippi/checks/reverse_followed_by_each'
13
13
  require 'pippi/checks/select_followed_by_first'
14
14
  require 'pippi/checks/select_followed_by_size'
15
15
  require 'pippi/checks/select_followed_by_empty'
16
+ require 'pippi/checks/select_followed_by_any'
16
17
  require 'pippi/checks/select_followed_by_select'
17
18
  require 'pippi/checks/assert_with_nil'
18
19
  require 'pippi/checks/debug_check'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pippi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Copeland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -74,6 +74,7 @@ files:
74
74
  - lib/pippi/checks/debug_check.rb
75
75
  - lib/pippi/checks/map_followed_by_flatten.rb
76
76
  - lib/pippi/checks/reverse_followed_by_each.rb
77
+ - lib/pippi/checks/select_followed_by_any.rb
77
78
  - lib/pippi/checks/select_followed_by_empty.rb
78
79
  - lib/pippi/checks/select_followed_by_first.rb
79
80
  - lib/pippi/checks/select_followed_by_select.rb