pippi 0.0.1 → 0.0.2

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: 6b2991c3de0e47fb2502ca50193e9c6d1d1afef7
4
- data.tar.gz: 16af3bb256083ed6f0b0f9faa2410e20110590a7
3
+ metadata.gz: c5a74d95bf3f5630ef99c31014f3bfcc83043cab
4
+ data.tar.gz: d3225b55129c7c327fa963cec71a281c17f275c3
5
5
  SHA512:
6
- metadata.gz: 320cd3c32751f7835f3b8213b5d51841f27400f564161b7a4e55d38db747cec4984f8d31c81c9ff63a5186f509d868407e87146210d37d620c2397db3f36b1c0
7
- data.tar.gz: 44110d0bca80145d567821a6202562dac0f0757911feb983ff404932c87ad6843077ada711b37754c9bb9d4dca3e0dc268b4f7fc59dcd9ffe70033c8b15c773e
6
+ metadata.gz: 367327d170a40465f8df9ff8bd41efb8c673068898dce752958557cf3cdc0c28f14f3fb8f4b0c8d2efe71ac18f321010f7f6814e679c4739010297daa7ab6fe1
7
+ data.tar.gz: a2900f8d02ca4d99aed0f5180ba87489da2d9ca260434b7bd582d019eed30ec8f502f2c8c142a78f83d06da596d603057fc68425d768cd83530662cc442cd4e0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ Oct 22, 2014 - 0.0.2:
2
+ Added AssertWithNil
3
+
1
4
  Oct 22, 2014 - 0.0.1:
2
5
  Initial release.
3
6
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pippi (0.0.1)
4
+ pippi (0.0.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,9 +1,24 @@
1
1
  Pippi is a utility for finding suboptimal Ruby class API usage.
2
2
 
3
- <a href="http://thomasleecopeland.com/2014/10/22/finding-suboptimal-api-usage.html">Here's a project overview.</a>.
3
+ <a href="http://thomasleecopeland.com/2014/10/22/finding-suboptimal-api-usage.html">Here's a project overview</a>.
4
4
 
5
5
  ## Checks
6
6
 
7
+ ### AssertWithNil
8
+
9
+ Don't use assert_equal with nil as a first argument; use assert_nil instead
10
+
11
+ For example, rather than doing this:
12
+
13
+ ```ruby
14
+ x = nil ; assert_equal(nil, x)
15
+ ```
16
+
17
+ Instead, consider doing this:
18
+
19
+ ```ruby
20
+ x = nil ; assert_nil(x)
21
+
7
22
  ### MapFollowedByFlatten
8
23
 
9
24
  Don't use map followed by flatten; use flat_map instead
@@ -92,11 +107,6 @@ bundle exec ruby -rpippi/auto_runner -e "MyClass.new.exercise_some_code"
92
107
 
93
108
  ```ruby
94
109
  # Don't use select followed by compact, use select with the nil inside the block
95
- # Use assert_nil rather than assert_equals
96
- # wrong
97
- assert_equals(nil, foo)
98
- # right
99
- assert_nil foo
100
110
 
101
111
  # unnecessary assignment since String#strip! mutates receiver
102
112
  # wrong
data/doc/docs.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ### AssertWithNil
3
+
4
+ Don't use assert_equal with nil as a first argument; use assert_nil instead
5
+
6
+ For example, rather than doing this:
7
+
8
+ ```ruby
9
+ x = nil ; assert_equal(nil, x)
10
+ ```
11
+
12
+ Instead, consider doing this:
13
+
14
+ ```ruby
15
+ x = nil ; assert_nil(x)
16
+ ```
17
+
2
18
  ### MapFollowedByFlatten
3
19
 
4
20
  Don't use map followed by flatten; use flat_map instead
@@ -22,6 +22,7 @@ module Pippi
22
22
  "SelectFollowedByFirst",
23
23
  "SelectFollowedBySize",
24
24
  "ReverseFollowedByEach",
25
+ "AssertWithNil"
25
26
  ],
26
27
  "training" => [
27
28
  ],
@@ -0,0 +1,43 @@
1
+ module Pippi::Checks
2
+
3
+ class AssertWithNil < Check
4
+
5
+ module MyAssertEqual
6
+ def assert_equal(*args)
7
+ result = super
8
+ if args.size > 1 && args[0].object_id == 8
9
+ self.class._pippi_check_assert_with_nil.add_problem
10
+ end
11
+ result
12
+ end
13
+ end
14
+
15
+ def decorate
16
+ if defined?(ActiveSupport::TestCase)
17
+ ActiveSupport::TestCase.class_exec(self) do |my_check|
18
+ @_pippi_check_assert_with_nil = my_check
19
+ def self._pippi_other_check_assert_with_nil
20
+ @_pippi_check_assert_with_nil
21
+ end
22
+ def self._pippi_check_assert_with_nil
23
+ self.ancestors.detect {|x| x == ActiveSupport::TestCase }._pippi_other_check_assert_with_nil
24
+ end
25
+ end
26
+ ActiveSupport::TestCase.prepend Pippi::Checks::AssertWithNil::MyAssertEqual
27
+ end
28
+ end
29
+
30
+ class Documentation
31
+ def description
32
+ "Don't use assert_equal with nil as a first argument; use assert_nil instead"
33
+ end
34
+ def sample
35
+ "x = nil ; assert_equal(nil, x)"
36
+ end
37
+ def instead_use
38
+ "x = nil ; assert_nil(x)"
39
+ end
40
+ end
41
+ end
42
+
43
+ end
data/lib/pippi/tasks.rb CHANGED
@@ -7,7 +7,8 @@ module Pippi
7
7
  [Pippi::Checks::SelectFollowedBySize::Documentation,
8
8
  Pippi::Checks::SelectFollowedByFirst::Documentation,
9
9
  Pippi::Checks::ReverseFollowedByEach::Documentation,
10
- Pippi::Checks::MapFollowedByFlatten::Documentation
10
+ Pippi::Checks::MapFollowedByFlatten::Documentation,
11
+ Pippi::Checks::AssertWithNil::Documentation,
11
12
  ].sort {|a,b| a.name <=> b.name }.each do |clz|
12
13
  obj = clz.new
13
14
  str << %Q{
data/lib/pippi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pippi
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/pippi.rb CHANGED
@@ -12,4 +12,5 @@ require 'pippi/checks/map_followed_by_flatten'
12
12
  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
+ require 'pippi/checks/assert_with_nil'
15
16
  require 'pippi/checks/debug_check'
data/test/check_test.rb CHANGED
@@ -4,12 +4,12 @@ class CheckTest < MiniTest::Test
4
4
 
5
5
  CodeSample = Struct.new(:code_text, :eval_to_execute)
6
6
 
7
- def assert_no_problems(str)
8
- assert execute_pippi_on(foo_bar_code_sample(str)).empty?
7
+ def assert_no_problems(str, opts={})
8
+ assert execute_pippi_on(foo_bar_code_sample(str, opts[:subclass] || ""), opts).empty?
9
9
  end
10
10
 
11
11
  def assert_problems(str, opts={})
12
- assert_equal opts[:count] || 1, execute_pippi_on(foo_bar_code_sample(str), opts).size
12
+ assert_equal opts[:count] || 1, execute_pippi_on(foo_bar_code_sample(str, opts[:subclass] || ""), opts).size
13
13
  end
14
14
 
15
15
  def output_file_name
@@ -20,8 +20,8 @@ class CheckTest < MiniTest::Test
20
20
  @tmp_code_sample_file_name ||= Tempfile.new("pippi_codesample").path
21
21
  end
22
22
 
23
- def foo_bar_code_sample(code)
24
- CodeSample.new.tap {|c| c.code_text = "class Foo ; def bar ; #{code} ; end ; end" ; c.eval_to_execute = "Foo.new.bar" }
23
+ def foo_bar_code_sample(code, subclass="")
24
+ CodeSample.new.tap {|c| c.code_text = "class Foo #{subclass.size > 0 ? "< #{subclass}" : ""}; def bar ; #{code} ; end ; end" ; c.eval_to_execute = "Foo.new.bar" }
25
25
  end
26
26
 
27
27
  def execute_pippi_on(code, opts={})
@@ -3,3 +3,11 @@ class Object
3
3
  self.nil? || self.size == 0
4
4
  end
5
5
  end
6
+
7
+
8
+ module ActiveSupport
9
+ class TestCase
10
+ def assert_equal(*args)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require "test_helper"
2
+
3
+ class AssertWithNilTest < CheckTest
4
+
5
+ def test_canonical_case_is_found
6
+ assert_problems "x = 42 ; assert_equal(nil, x)", :include_rails_core_extensions => true, :subclass => "ActiveSupport::TestCase"
7
+ end
8
+
9
+ def test_non_nil_first_arg_doesnt_flag
10
+ assert_no_problems "x = 42 ; assert_equal(42, x)", :include_rails_core_extensions => true, :subclass => "ActiveSupport::TestCase"
11
+ end
12
+
13
+ def test_three_arg_is_flagged
14
+ assert_problems "x = 42 ; assert_equal(nil, x, 'whatevs')", :include_rails_core_extensions => true, :subclass => "ActiveSupport::TestCase"
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pippi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Copeland
@@ -74,6 +74,7 @@ files:
74
74
  - lib/pippi/auto_runner.rb
75
75
  - lib/pippi/check_loader.rb
76
76
  - lib/pippi/check_set_mapper.rb
77
+ - lib/pippi/checks/assert_with_nil.rb
77
78
  - lib/pippi/checks/check.rb
78
79
  - lib/pippi/checks/debug_check.rb
79
80
  - lib/pippi/checks/map_followed_by_flatten.rb
@@ -91,6 +92,7 @@ files:
91
92
  - test/check_test.rb
92
93
  - test/rails_core_extensions.rb
93
94
  - test/test_helper.rb
95
+ - test/unit/assert_with_nil_test.rb
94
96
  - test/unit/map_followed_by_flatten_test.rb
95
97
  - test/unit/problem_test.rb
96
98
  - test/unit/report_test.rb
@@ -131,6 +133,7 @@ test_files:
131
133
  - test/check_test.rb
132
134
  - test/rails_core_extensions.rb
133
135
  - test/test_helper.rb
136
+ - test/unit/assert_with_nil_test.rb
134
137
  - test/unit/map_followed_by_flatten_test.rb
135
138
  - test/unit/problem_test.rb
136
139
  - test/unit/report_test.rb