reek 1.3.5 → 1.3.6
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 +4 -4
- data/CHANGELOG +4 -0
- data/config/defaults.reek +3 -0
- data/lib/reek/core/code_context.rb +4 -0
- data/lib/reek/core/smell_repository.rb +1 -0
- data/lib/reek/smells.rb +1 -0
- data/lib/reek/smells/prima_donna_method.rb +41 -0
- data/lib/reek/smells/smell_detector.rb +4 -0
- data/lib/reek/source/sexp_extensions.rb +8 -0
- data/lib/reek/version.rb +1 -1
- data/spec/reek/smells/feature_envy_spec.rb +1 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +31 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd6196b99429388642049ac970d159ca81066a08
|
4
|
+
data.tar.gz: 45ec008b56f8a42ca8edeaa9951ecc8b03fd5d7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a09c19c44892cd6d2b8cc82b0fa82c8563fbed0c8734b8f12dfbb5906c223b664ab15e95cdeea8d2270004e06a182968d161bd644a044b157236e69141b8be80
|
7
|
+
data.tar.gz: a6ff074ebe7abd1a2029ffd6a3f04571ee75beb5709cef297a221bc37b3427fa84c5d53de767ccecf2f248e70a0cdf75fb8e363eb776ddec0b0aa9f1d2018c93
|
data/CHANGELOG
CHANGED
data/config/defaults.reek
CHANGED
data/lib/reek/smells.rb
CHANGED
@@ -10,6 +10,7 @@ require 'reek/smells/long_parameter_list'
|
|
10
10
|
require 'reek/smells/long_yield_list'
|
11
11
|
require 'reek/smells/nested_iterators'
|
12
12
|
require 'reek/smells/nil_check'
|
13
|
+
require 'reek/smells/prima_donna_method'
|
13
14
|
require 'reek/smells/repeated_conditional'
|
14
15
|
require 'reek/smells/too_many_instance_variables'
|
15
16
|
require 'reek/smells/too_many_methods'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'reek/smells/smell_detector'
|
2
|
+
require 'reek/smell_warning'
|
3
|
+
|
4
|
+
module Reek
|
5
|
+
module Smells
|
6
|
+
# Excerpt from:
|
7
|
+
# http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist
|
8
|
+
# since this sums it up really well:
|
9
|
+
# ------------------------------
|
10
|
+
# The ! in method names that end with ! means, “This method is dangerous”
|
11
|
+
# or, more precisely, this method is the “dangerous” version of an
|
12
|
+
# equivalent method, with the same name minus the !. “Danger” is relative;
|
13
|
+
# the ! doesn’t mean anything at all unless the method name it’s in
|
14
|
+
# corresponds to a similar but bang-less method name. Don’t add ! to your
|
15
|
+
# destructive (receiver-changing) methods’ names, unless you consider the
|
16
|
+
# changing to be “dangerous” and you have a “non-dangerous” equivalent
|
17
|
+
# method without the !. If some arbitrary subset of destructive methods end
|
18
|
+
# with !, then the whole point of ! gets distorted and diluted, and ! ceases
|
19
|
+
# to convey any information whatsoever
|
20
|
+
# ------------------------------
|
21
|
+
# Such a method is called PrimaDonnaMethod and is reported as a smell.
|
22
|
+
class PrimaDonnaMethod < SmellDetector
|
23
|
+
SMELL_CLASS = smell_class_name
|
24
|
+
SMELL_SUBCLASS = smell_class_name
|
25
|
+
|
26
|
+
def self.contexts
|
27
|
+
[:class]
|
28
|
+
end
|
29
|
+
|
30
|
+
def examine_context(ctx)
|
31
|
+
ctx.node_instance_methods.map do |method_sexp|
|
32
|
+
if method_sexp.ends_with_bang?
|
33
|
+
SmellWarning.new(SMELL_CLASS, ctx.full_name, [ctx.exp.line],
|
34
|
+
%Q!has prima donna method `#{method_sexp.name}`!,
|
35
|
+
@source, SMELL_SUBCLASS) unless ctx.node_instance_methods.detect {|sexp_item| sexp_item.name.to_s == method_sexp.name_without_bang }
|
36
|
+
end
|
37
|
+
end.compact
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -46,6 +46,14 @@ module Reek
|
|
46
46
|
def parameter_names
|
47
47
|
@param_names ||= argslist[1..-1].map { |param| Sexp === param ? param[1] : param }
|
48
48
|
end
|
49
|
+
|
50
|
+
def name_without_bang
|
51
|
+
name.to_s.chop
|
52
|
+
end
|
53
|
+
|
54
|
+
def ends_with_bang?
|
55
|
+
name[-1] == '!'
|
56
|
+
end
|
49
57
|
end
|
50
58
|
|
51
59
|
module DefnNode
|
data/lib/reek/version.rb
CHANGED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'reek/smells/smell_detector_shared'
|
4
|
+
|
5
|
+
include Reek
|
6
|
+
include Reek::Smells
|
7
|
+
|
8
|
+
describe PrimaDonnaMethod do
|
9
|
+
it 'should report nothing when method and bang counterpart exist' do
|
10
|
+
'class C; def m; end; def m!; end; end'.should_not smell_of(PrimaDonnaMethod)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should report PrimaDonnaMethod when only bang method exists' do
|
14
|
+
'class C; def m!; end; end'.should smell_of(PrimaDonnaMethod)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'the right smell' do
|
18
|
+
let(:detector) { PrimaDonnaMethod.new('dummy_source') }
|
19
|
+
let(:src) { 'class C; def m!; end; end' }
|
20
|
+
let(:ctx) { CodeContext.new(nil, src.to_reek_source.syntax_tree) }
|
21
|
+
|
22
|
+
it 'should be reported' do
|
23
|
+
smells = detector.examine_context(ctx)
|
24
|
+
warning = smells[0]
|
25
|
+
|
26
|
+
warning.smell['class'].should == 'PrimaDonnaMethod'
|
27
|
+
warning.smell['subclass'].should == 'PrimaDonnaMethod'
|
28
|
+
warning.lines.should == [1]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-12-
|
13
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ruby_parser
|
@@ -187,6 +187,7 @@ files:
|
|
187
187
|
- lib/reek/version.rb
|
188
188
|
- lib/reek/smells/boolean_parameter.rb
|
189
189
|
- lib/reek/smells/uncommunicative_parameter_name.rb
|
190
|
+
- lib/reek/smells/prima_donna_method.rb
|
190
191
|
- lib/reek/smells/unused_parameters.rb
|
191
192
|
- lib/reek/smells/long_yield_list.rb
|
192
193
|
- lib/reek/smells/attribute.rb
|
@@ -245,6 +246,7 @@ files:
|
|
245
246
|
- spec/reek/cli/yaml_command_spec.rb
|
246
247
|
- spec/reek/cli/report_spec.rb
|
247
248
|
- spec/reek/cli/version_command_spec.rb
|
249
|
+
- spec/reek/smells/prima_donna_method_spec.rb
|
248
250
|
- spec/reek/smells/boolean_parameter_spec.rb
|
249
251
|
- spec/reek/smells/uncommunicative_method_name_spec.rb
|
250
252
|
- spec/reek/smells/uncommunicative_module_name_spec.rb
|