pippi 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -2
- data/README.md +41 -20
- data/doc/docs.md +18 -1
- data/lib/pippi.rb +1 -0
- data/lib/pippi/check_set_mapper.rb +3 -0
- data/lib/pippi/checks/check.rb +6 -2
- data/lib/pippi/checks/map_followed_by_flatten.rb +1 -1
- data/lib/pippi/checks/method_sequence_checker.rb +3 -3
- data/lib/pippi/checks/reverse_followed_by_each.rb +2 -2
- data/lib/pippi/checks/strip_followed_by_empty.rb +30 -0
- data/lib/pippi/report.rb +2 -0
- data/lib/pippi/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 948ecbfacbd679fa33cc861541088156d6928069
|
4
|
+
data.tar.gz: 7037d5aa7e33ac744b041d4f15e266e433b138f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3889d565b2472028144711ea64975e6e70ea6153b52a86d69eeb31767be7a8893ea939437319da2fae390f6ac78f81bc699c98673e451c11c679de74235d1b7f
|
7
|
+
data.tar.gz: 6578976bea375f870a594525cee6fdf6b20f07f0158deb9a1947178083ec84cd32686d028f16340973055252eb8296303a42c2062dddfc220ce062697abf6fd1
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
+
## 0.0.14 (2015-04-23)
|
2
|
+
|
3
|
+
* [NEW] Added Rails checkset with first rule StripFollowedByEmpty
|
4
|
+
* [FIXED] Docs fixes
|
5
|
+
* [FIXED] Missing require when using pippi outside Rails
|
6
|
+
|
1
7
|
## 0.0.13 (2015-02-17)
|
2
8
|
|
3
|
-
*
|
9
|
+
* [FIXED] :io option was still opening default file
|
4
10
|
|
5
11
|
## 0.0.12 (2015-02-16)
|
6
12
|
|
7
|
-
*
|
13
|
+
* [NEW] Changed output format to work better with IDEs
|
8
14
|
|
9
15
|
## 0.0.11 (2014-12-19)
|
10
16
|
|
data/README.md
CHANGED
@@ -74,7 +74,13 @@ USE_PIPPI=true bundle exec rake test:units && cat log/pippi.log
|
|
74
74
|
* You can also select a different checkset:
|
75
75
|
|
76
76
|
```text
|
77
|
-
USE_PIPPI=true PIPPI_CHECKSET=
|
77
|
+
USE_PIPPI=true PIPPI_CHECKSET=rails bundle exec rake test:units && cat log/pippi.log
|
78
|
+
```
|
79
|
+
|
80
|
+
* And you can run multiple checksets:
|
81
|
+
|
82
|
+
```text
|
83
|
+
USE_PIPPI=true PIPPI_CHECKSET=basic,rails bundle exec rake test:units && cat log/pippi.log
|
78
84
|
```
|
79
85
|
|
80
86
|
|
@@ -129,18 +135,18 @@ Pippi has the concept of "checksets" which are, well, sets of checks. The curre
|
|
129
135
|
|
130
136
|
#### ReverseFollowedByEach
|
131
137
|
|
132
|
-
Don't use
|
138
|
+
Don't use reverse followed by each; use reverse_each instead
|
133
139
|
|
134
140
|
For example, rather than doing this:
|
135
141
|
|
136
142
|
```ruby
|
137
|
-
[1,
|
143
|
+
[1,2,3].reverse.each {|x| x+1 }
|
138
144
|
```
|
139
145
|
|
140
146
|
Instead, consider doing this:
|
141
147
|
|
142
148
|
```ruby
|
143
|
-
[1,
|
149
|
+
[1,2,3].reverse_each {|x| x+1 }
|
144
150
|
```
|
145
151
|
|
146
152
|
#### SelectFollowedByAny
|
@@ -150,13 +156,13 @@ Don't use select followed by any?; use any? with a block instead
|
|
150
156
|
For example, rather than doing this:
|
151
157
|
|
152
158
|
```ruby
|
153
|
-
[1,
|
159
|
+
[1,2,3].select {|x| x > 1 }.any?
|
154
160
|
```
|
155
161
|
|
156
162
|
Instead, consider doing this:
|
157
163
|
|
158
164
|
```ruby
|
159
|
-
[1,
|
165
|
+
[1,2,3].any? {|x| x > 1 }
|
160
166
|
```
|
161
167
|
|
162
168
|
#### SelectFollowedByEmpty
|
@@ -166,13 +172,13 @@ Don't use select followed by empty?; use none? instead
|
|
166
172
|
For example, rather than doing this:
|
167
173
|
|
168
174
|
```ruby
|
169
|
-
[1,
|
175
|
+
[1,2,3].select {|x| x > 1 }.empty?
|
170
176
|
```
|
171
177
|
|
172
178
|
Instead, consider doing this:
|
173
179
|
|
174
180
|
```ruby
|
175
|
-
[1,
|
181
|
+
[1,2,3].none? {|x| x > 1 }
|
176
182
|
```
|
177
183
|
|
178
184
|
#### SelectFollowedByFirst
|
@@ -182,13 +188,13 @@ Don't use select followed by first; use detect instead
|
|
182
188
|
For example, rather than doing this:
|
183
189
|
|
184
190
|
```ruby
|
185
|
-
[1,
|
191
|
+
[1,2,3].select {|x| x > 1 }.first
|
186
192
|
```
|
187
193
|
|
188
194
|
Instead, consider doing this:
|
189
195
|
|
190
196
|
```ruby
|
191
|
-
[1,
|
197
|
+
[1,2,3].detect {|x| x > 1 }
|
192
198
|
```
|
193
199
|
|
194
200
|
#### SelectFollowedByNone
|
@@ -198,13 +204,13 @@ Don't use select followed by none?; use none? with a block instead
|
|
198
204
|
For example, rather than doing this:
|
199
205
|
|
200
206
|
```ruby
|
201
|
-
[1,
|
207
|
+
[1,2,3].select {|x| x > 1 }.none?
|
202
208
|
```
|
203
209
|
|
204
210
|
Instead, consider doing this:
|
205
211
|
|
206
212
|
```ruby
|
207
|
-
[1,
|
213
|
+
[1,2,3].none? {|x| x > 1 }
|
208
214
|
```
|
209
215
|
|
210
216
|
#### SelectFollowedBySelect
|
@@ -214,13 +220,13 @@ Don't use consecutive select blocks; use a single select instead
|
|
214
220
|
For example, rather than doing this:
|
215
221
|
|
216
222
|
```ruby
|
217
|
-
[1,
|
223
|
+
[1,2,3].select {|x| x > 1 }.select {|x| x > 2 }
|
218
224
|
```
|
219
225
|
|
220
226
|
Instead, consider doing this:
|
221
227
|
|
222
228
|
```ruby
|
223
|
-
[1,
|
229
|
+
[1,2,3].select {|x| x > 2 }
|
224
230
|
```
|
225
231
|
|
226
232
|
#### SelectFollowedBySize
|
@@ -230,13 +236,13 @@ Don't use select followed by size; use count instead
|
|
230
236
|
For example, rather than doing this:
|
231
237
|
|
232
238
|
```ruby
|
233
|
-
[1
|
239
|
+
[1,2,3].select {|x| x > 1 }.size
|
234
240
|
```
|
235
241
|
|
236
242
|
Instead, consider doing this:
|
237
243
|
|
238
244
|
```ruby
|
239
|
-
[1,
|
245
|
+
[1,2,3].count {|x| x > 1 }
|
240
246
|
```
|
241
247
|
### buggy
|
242
248
|
|
@@ -263,13 +269,30 @@ Don't use map followed by flatten(1); use flat_map instead
|
|
263
269
|
For example, rather than doing this:
|
264
270
|
|
265
271
|
```ruby
|
266
|
-
[1,
|
272
|
+
[1,2,3].map {|x| [x,x+1] }.flatten(1)
|
273
|
+
```
|
274
|
+
|
275
|
+
Instead, consider doing this:
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
[1,2,3].flat_map {|x| [x, x+1]}
|
279
|
+
```
|
280
|
+
### rails
|
281
|
+
|
282
|
+
#### StripFollowedByEmpty
|
283
|
+
|
284
|
+
Don't use String#strip followed by empty?; use String#blank? instead
|
285
|
+
|
286
|
+
For example, rather than doing this:
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
' '.strip.empty?
|
267
290
|
```
|
268
291
|
|
269
292
|
Instead, consider doing this:
|
270
293
|
|
271
294
|
```ruby
|
272
|
-
|
295
|
+
' '.blank?
|
273
296
|
```
|
274
297
|
|
275
298
|
## Ideas for other problems to detect:
|
@@ -335,9 +358,7 @@ end
|
|
335
358
|
## TODO
|
336
359
|
|
337
360
|
* Clean up this initial hacked out metaprogramming
|
338
|
-
* Do more checks
|
339
361
|
* Finish refactoring duplicated code into MethodSequenceChecker
|
340
|
-
* Use MethodSequenceFinder to do something with String
|
341
362
|
|
342
363
|
## Developing
|
343
364
|
|
data/doc/docs.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#### ReverseFollowedByEach
|
4
4
|
|
5
|
-
Don't use
|
5
|
+
Don't use reverse followed by each; use reverse_each instead
|
6
6
|
|
7
7
|
For example, rather than doing this:
|
8
8
|
|
@@ -144,3 +144,20 @@ Instead, consider doing this:
|
|
144
144
|
```ruby
|
145
145
|
[1,2,3].flat_map {|x| [x, x+1]}
|
146
146
|
```
|
147
|
+
### rails
|
148
|
+
|
149
|
+
#### StripFollowedByEmpty
|
150
|
+
|
151
|
+
Don't use String#strip followed by empty?; use String#blank? instead
|
152
|
+
|
153
|
+
For example, rather than doing this:
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
' '.strip.empty?
|
157
|
+
```
|
158
|
+
|
159
|
+
Instead, consider doing this:
|
160
|
+
|
161
|
+
```ruby
|
162
|
+
' '.blank?
|
163
|
+
```
|
data/lib/pippi.rb
CHANGED
@@ -16,6 +16,7 @@ require 'pippi/checks/select_followed_by_empty'
|
|
16
16
|
require 'pippi/checks/select_followed_by_any'
|
17
17
|
require 'pippi/checks/select_followed_by_none'
|
18
18
|
require 'pippi/checks/select_followed_by_select'
|
19
|
+
require 'pippi/checks/strip_followed_by_empty'
|
19
20
|
require 'pippi/checks/method_sequence_finder'
|
20
21
|
require 'pippi/checks/method_sequence_checker'
|
21
22
|
require 'pippi/checks/assert_with_nil'
|
data/lib/pippi/checks/check.rb
CHANGED
@@ -6,8 +6,12 @@ module Pippi::Checks
|
|
6
6
|
@ctx = ctx
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
9
|
+
def mutator_methods(the_type=Array)
|
10
|
+
if the_type == String
|
11
|
+
[:insert, :<<]
|
12
|
+
else
|
13
|
+
[:collect!, :compact!, :flatten!, :map!, :reject!, :reverse!, :rotate!, :select!, :shuffle!, :slice!, :sort!, :sort_by!, :uniq!]
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
17
|
def method_names_that_indicate_this_is_being_used_as_a_collection
|
@@ -22,7 +22,7 @@ module Pippi::Checks
|
|
22
22
|
# Ignore Array subclasses since map or flatten may have difference meanings
|
23
23
|
else
|
24
24
|
result.extend MyFlatten
|
25
|
-
self.class._pippi_check_map_followed_by_flatten.
|
25
|
+
self.class._pippi_check_map_followed_by_flatten.mutator_methods.each do |this_means_its_ok_sym|
|
26
26
|
result.define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_map_followed_by_flatten.its_ok_watcher_proc(MyFlatten, :flatten))
|
27
27
|
end
|
28
28
|
end
|
@@ -3,7 +3,7 @@ class MethodSequenceChecker
|
|
3
3
|
ARITY_TYPE_BLOCK_ARG = 1
|
4
4
|
ARITY_TYPE_NONE = 2
|
5
5
|
|
6
|
-
attr_reader :check, :clazz_to_decorate, :method1, :method2, :first_method_arity_type, :second_method_arity_type, :should_check_subsequent_calls
|
6
|
+
attr_reader :check, :clazz_to_decorate, :method1, :method2, :first_method_arity_type, :second_method_arity_type, :should_check_subsequent_calls, :return_type
|
7
7
|
|
8
8
|
def initialize(check, clazz_to_decorate, method1, method2, first_method_arity_type, second_method_arity_type, should_check_subsequent_calls)
|
9
9
|
@check = check
|
@@ -33,7 +33,7 @@ class MethodSequenceChecker
|
|
33
33
|
# e.g., Array#select returns an Array. Would need to further parameterize this to get
|
34
34
|
# different behavior.
|
35
35
|
self.class.instance_variable_get(name).add_problem
|
36
|
-
if method_sequence_check_instance.should_check_subsequent_calls && method_sequence_check_instance.clazz_to_decorate ==
|
36
|
+
if method_sequence_check_instance.should_check_subsequent_calls && method_sequence_check_instance.clazz_to_decorate == self.class
|
37
37
|
problem_location = caller_locations.find { |c| c.to_s !~ /byebug|lib\/pippi\/checks/ }
|
38
38
|
self.class.instance_variable_get(name).method_names_that_indicate_this_is_being_used_as_a_collection.each do |this_means_its_ok_sym|
|
39
39
|
define_singleton_method(this_means_its_ok_sym, self.class.instance_variable_get(name).clear_fault_proc(self.class.instance_variable_get(name), problem_location))
|
@@ -58,7 +58,7 @@ class MethodSequenceChecker
|
|
58
58
|
end
|
59
59
|
if self.class.instance_variable_get(name)
|
60
60
|
result.extend second_method_decorator
|
61
|
-
self.class.instance_variable_get(name).
|
61
|
+
self.class.instance_variable_get(name).mutator_methods(result.class).each do |this_means_its_ok_sym|
|
62
62
|
result.define_singleton_method(this_means_its_ok_sym, self.class.instance_variable_get(name).its_ok_watcher_proc(second_method_decorator, method_sequence_check_instance.method2))
|
63
63
|
end
|
64
64
|
end
|
@@ -16,7 +16,7 @@ module Pippi::Checks
|
|
16
16
|
# Ignore Array subclasses since reverse or each may have difference meanings
|
17
17
|
else
|
18
18
|
result.singleton_class.class_eval { prepend MyEach }
|
19
|
-
self.class._pippi_check_reverse_followed_by_each.
|
19
|
+
self.class._pippi_check_reverse_followed_by_each.mutator_methods.each do |this_means_its_ok_sym|
|
20
20
|
result.define_singleton_method(this_means_its_ok_sym, self.class._pippi_check_reverse_followed_by_each.its_ok_watcher_proc(MyEach, :each))
|
21
21
|
end
|
22
22
|
end
|
@@ -37,7 +37,7 @@ module Pippi::Checks
|
|
37
37
|
|
38
38
|
class Documentation
|
39
39
|
def description
|
40
|
-
"Don't use
|
40
|
+
"Don't use reverse followed by each; use reverse_each instead"
|
41
41
|
end
|
42
42
|
|
43
43
|
def sample
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Pippi::Checks
|
2
|
+
|
3
|
+
# This is a Rails-only check; how to call it out as such?
|
4
|
+
# Putting it in a "rails" checkset for now
|
5
|
+
class StripFollowedByEmpty < Check
|
6
|
+
|
7
|
+
def decorate
|
8
|
+
@mycheck.decorate
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(ctx)
|
12
|
+
super
|
13
|
+
@mycheck = MethodSequenceChecker.new(self, String, "strip", "empty?", MethodSequenceChecker::ARITY_TYPE_NONE, MethodSequenceChecker::ARITY_TYPE_NONE, true)
|
14
|
+
end
|
15
|
+
|
16
|
+
class Documentation
|
17
|
+
def description
|
18
|
+
"Don't use String#strip followed by empty?; use String#blank? instead"
|
19
|
+
end
|
20
|
+
def sample
|
21
|
+
"' '.strip.empty?"
|
22
|
+
end
|
23
|
+
def instead_use
|
24
|
+
"' '.blank?"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
data/lib/pippi/report.rb
CHANGED
data/lib/pippi/version.rb
CHANGED
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.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Copeland
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/pippi/checks/select_followed_by_none.rb
|
83
83
|
- lib/pippi/checks/select_followed_by_select.rb
|
84
84
|
- lib/pippi/checks/select_followed_by_size.rb
|
85
|
+
- lib/pippi/checks/strip_followed_by_empty.rb
|
85
86
|
- lib/pippi/context.rb
|
86
87
|
- lib/pippi/exec_runner.rb
|
87
88
|
- lib/pippi/problem.rb
|