reek 4.5.3 → 4.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +2 -0
- data/CHANGELOG.md +4 -0
- data/Dockerfile +5 -5
- data/Gemfile +7 -5
- data/docs/Prima-Donna-Method.md +27 -0
- data/docs/Unused-Private-Method.md +27 -0
- data/features/command_line_interface/options.feature +3 -1
- data/lib/reek/ast/reference_collector.rb +2 -4
- data/lib/reek/cli/options.rb +5 -1
- data/lib/reek/context/ghost_context.rb +1 -2
- data/lib/reek/smell_detectors/prima_donna_method.rb +30 -0
- data/lib/reek/version.rb +1 -1
- data/spec/reek/ast/reference_collector_spec.rb +0 -17
- data/spec/reek/smell_detectors/prima_donna_method_spec.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 779579909e4877e391f86f92756b1ce1b45a3202
|
4
|
+
data.tar.gz: a7f30fb8db30c839c335c47be2eb00ce0f321bac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e10d6f4cf3e8f9bc0cf499261647cd167eb5bed0296c97d79263408b4f82b371904da23927e6853ddf2d5643137a513b9f947ce2c3593f3b7b89d602baae21e
|
7
|
+
data.tar.gz: 8b3e07023d3001002650fd4489aa130d1350093f4e604ba3ee5a33fa71c916618f2fc14d037c5e4eb737823e64ebc054166db2b6643b0e832c906210e85fd6c6
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Dockerfile
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Build and run via:
|
4
4
|
# docker build -t codeclimate/codeclimate-reek . && docker run codeclimate/codeclimate-reek
|
5
5
|
|
6
|
-
FROM
|
6
|
+
FROM ruby:2.3.3-alpine
|
7
7
|
|
8
8
|
MAINTAINER The Reek core team
|
9
9
|
|
@@ -12,17 +12,17 @@ ENV app_dir /usr/src/app
|
|
12
12
|
ENV user app
|
13
13
|
|
14
14
|
RUN apk --update add git
|
15
|
-
|
16
15
|
ADD . ${app_dir}
|
17
16
|
|
17
|
+
RUN adduser -u 9000 -D ${user}
|
18
|
+
RUN chown -R ${user}:${user} ${app_dir}
|
19
|
+
USER ${user}
|
20
|
+
|
18
21
|
WORKDIR ${app_dir}
|
19
22
|
|
20
23
|
RUN bundle install --without debugging development
|
21
|
-
RUN adduser -u 9000 -D ${user}
|
22
|
-
RUN chown -R ${user}:${user} ${app_dir}
|
23
24
|
|
24
25
|
VOLUME ${code_dir}
|
25
26
|
WORKDIR ${code_dir}
|
26
|
-
USER ${user}
|
27
27
|
|
28
28
|
CMD [ "/usr/src/app/bin/code_climate_reek" ]
|
data/Gemfile
CHANGED
@@ -2,25 +2,27 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
ruby RUBY_VERSION
|
6
|
+
|
5
7
|
group :development do
|
8
|
+
gem 'activesupport', '>= 4.2'
|
6
9
|
gem 'aruba', '~> 0.14.0'
|
7
10
|
gem 'ataru', '~> 0.2.0'
|
8
11
|
gem 'cucumber', '~> 2.0'
|
9
12
|
gem 'factory_girl', '~> 4.0'
|
10
13
|
gem 'mutant-rspec', '~> 0.8.8'
|
11
|
-
gem 'rake', '~>
|
14
|
+
gem 'rake', '~> 12.0'
|
12
15
|
gem 'rspec', '~> 3.0'
|
13
16
|
gem 'simplecov', '~> 0.12.0'
|
14
17
|
gem 'yard', '~> 0.9.5'
|
15
|
-
gem 'activesupport', '~> 4.2'
|
16
18
|
|
17
19
|
if RUBY_VERSION >= '2.3'
|
18
|
-
gem 'rubocop', '~> 0.
|
19
|
-
gem 'rubocop-rspec', '~> 1.
|
20
|
+
gem 'rubocop', '~> 0.46.0'
|
21
|
+
gem 'rubocop-rspec', '~> 1.9.0'
|
20
22
|
end
|
21
23
|
|
22
24
|
platforms :mri do
|
23
|
-
gem 'redcarpet', '~> 3.
|
25
|
+
gem 'redcarpet', '~> 3.4.0'
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
data/docs/Prima-Donna-Method.md
CHANGED
@@ -61,3 +61,30 @@ method `foo` of the `Dangerous` module.
|
|
61
61
|
## Configuration
|
62
62
|
|
63
63
|
_Prima Donna Method_ offers the [Basic Smell Options](Basic-Smell-Options.md).
|
64
|
+
|
65
|
+
## Example configuration via source comment
|
66
|
+
|
67
|
+
Imagine code like this:
|
68
|
+
|
69
|
+
```Ruby
|
70
|
+
class Alfa
|
71
|
+
def bravo!
|
72
|
+
end
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
This would report:
|
77
|
+
|
78
|
+
>>
|
79
|
+
ruby.rb -- 1 warning:
|
80
|
+
[1]:PrimaDonnaMethod: Alfa has prima donna method 'bravo!'
|
81
|
+
|
82
|
+
If you want to suppress this warning you can do this via source comment like this:
|
83
|
+
|
84
|
+
```Ruby
|
85
|
+
# :reek:PrimaDonnaMethod: { exclude: [ bravo! ] }
|
86
|
+
class Alfa
|
87
|
+
def bravo!
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
@@ -48,6 +48,33 @@ end
|
|
48
48
|
Note that disabling this detector via comment works on a class scope, not
|
49
49
|
a method scope (like you can see above).
|
50
50
|
|
51
|
+
Another simple example would be:
|
52
|
+
|
53
|
+
```Ruby
|
54
|
+
class Alfa
|
55
|
+
private
|
56
|
+
def bravo
|
57
|
+
end
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
This would report:
|
62
|
+
|
63
|
+
>>
|
64
|
+
ruby.rb -- 1 warning:
|
65
|
+
[3]:UnusedPrivateMethod: Alfa has the unused private instance method 'bravo'
|
66
|
+
|
67
|
+
If you want to suppress this warning you can do this via source comment like this:
|
68
|
+
|
69
|
+
```Ruby
|
70
|
+
# :reek:UnusedPrivateMethod: { exclude: bravo }
|
71
|
+
class Alfa
|
72
|
+
private
|
73
|
+
def bravo
|
74
|
+
end
|
75
|
+
end
|
76
|
+
```
|
77
|
+
|
51
78
|
## Known limitations
|
52
79
|
|
53
80
|
* Method calls via dynamic dispatch (e.g. via `send`) is something Reek (or any other
|
@@ -41,7 +41,9 @@ Feature: Reek can be controlled using command-line options
|
|
41
41
|
|
42
42
|
Configuration:
|
43
43
|
-c, --config FILE Read configuration options from FILE
|
44
|
-
--smell SMELL
|
44
|
+
--smell SMELL Only look for a specific smell.
|
45
|
+
Call it like this: reek --smell PrimaDonnaMethod source.rb
|
46
|
+
Check out https://github.com/troessner/reek/blob/master/docs/Code-Smells.md for a list of smells
|
45
47
|
|
46
48
|
Generate a todo list:
|
47
49
|
-t, --todo Generate a todo list
|
@@ -6,8 +6,6 @@ module Reek
|
|
6
6
|
# of an abstract syntax tree.
|
7
7
|
#
|
8
8
|
class ReferenceCollector
|
9
|
-
STOP_NODES = [:class, :module, :def, :defs].freeze
|
10
|
-
|
11
9
|
def initialize(ast)
|
12
10
|
@ast = ast
|
13
11
|
end
|
@@ -22,12 +20,12 @@ module Reek
|
|
22
20
|
|
23
21
|
def explicit_self_calls
|
24
22
|
[:self, :super, :zsuper, :ivar, :ivasgn].flat_map do |node_type|
|
25
|
-
ast.each_node(node_type
|
23
|
+
ast.each_node(node_type)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
|
29
27
|
def implicit_self_calls
|
30
|
-
ast.each_node(:send
|
28
|
+
ast.each_node(:send).reject(&:receiver)
|
31
29
|
end
|
32
30
|
end
|
33
31
|
end
|
data/lib/reek/cli/options.rb
CHANGED
@@ -95,7 +95,11 @@ module Reek
|
|
95
95
|
parser.on('-c', '--config FILE', 'Read configuration options from FILE') do |file|
|
96
96
|
self.config_file = Pathname.new(file)
|
97
97
|
end
|
98
|
-
parser.on('--smell SMELL',
|
98
|
+
parser.on('--smell SMELL',
|
99
|
+
'Only look for a specific smell.',
|
100
|
+
'Call it like this: reek --smell PrimaDonnaMethod source.rb',
|
101
|
+
'Check out https://github.com/troessner/reek/blob/master/docs/Code-Smells.md '\
|
102
|
+
'for a list of smells') do |smell|
|
99
103
|
smells_to_detect << smell
|
100
104
|
end
|
101
105
|
end
|
@@ -28,6 +28,24 @@ module Reek
|
|
28
28
|
[:class]
|
29
29
|
end
|
30
30
|
|
31
|
+
#
|
32
|
+
# @param ctx [Context::ModuleContext]
|
33
|
+
# @return [Array<SmellWarning>]
|
34
|
+
#
|
35
|
+
# Given this code:
|
36
|
+
#
|
37
|
+
# class Alfa
|
38
|
+
# def bravo!
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# An example `ctx` could look like this:
|
43
|
+
#
|
44
|
+
# s(:class,
|
45
|
+
# s(:const, nil, :Alfa), nil,
|
46
|
+
# s(:def, :bravo!,
|
47
|
+
# s(:args), nil))
|
48
|
+
#
|
31
49
|
def sniff(ctx)
|
32
50
|
ctx.node_instance_methods.select do |method_sexp|
|
33
51
|
prima_donna_method?(method_sexp, ctx)
|
@@ -45,6 +63,7 @@ module Reek
|
|
45
63
|
|
46
64
|
def prima_donna_method?(method_sexp, ctx)
|
47
65
|
return false unless method_sexp.ends_with_bang?
|
66
|
+
return false if ignore_method?(method_sexp, ctx)
|
48
67
|
return false if version_without_bang_exists?(method_sexp, ctx)
|
49
68
|
true
|
50
69
|
end
|
@@ -55,6 +74,17 @@ module Reek
|
|
55
74
|
sexp_item.name.to_s == method_sexp.name_without_bang
|
56
75
|
end
|
57
76
|
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# @param method_node [Reek::AST::Node],
|
80
|
+
# e.g. s(:def, :bravo!, s(:args), nil)
|
81
|
+
# @param ctx [Context::ModuleContext]
|
82
|
+
# @return [Boolean]
|
83
|
+
#
|
84
|
+
def ignore_method?(method_node, ctx)
|
85
|
+
ignore_method_names = value(EXCLUDE_KEY, ctx) # e.g. ["bravo!"]
|
86
|
+
ignore_method_names.include? method_node.name.to_s # method_node.name is e.g.: :bravo!
|
87
|
+
end
|
58
88
|
end
|
59
89
|
end
|
60
90
|
end
|
data/lib/reek/version.rb
CHANGED
@@ -43,22 +43,5 @@ RSpec.describe Reek::AST::ReferenceCollector do
|
|
43
43
|
it 'ignores global variables' do
|
44
44
|
expect(refs_to_self('def no_envy(arga) $s2.to_a; $s2[arga] end')).to eq(0)
|
45
45
|
end
|
46
|
-
|
47
|
-
it 'ignores global variables' do
|
48
|
-
src = <<-EOS
|
49
|
-
def accept(t, pat = /.*/nm, &block)
|
50
|
-
if pat
|
51
|
-
pat.respond_to?(:match) or raise TypeError, "has no `match'"
|
52
|
-
else
|
53
|
-
pat = t if t.respond_to?(:match)
|
54
|
-
end
|
55
|
-
unless block
|
56
|
-
block = pat.method(:convert).to_proc if pat.respond_to?(:convert)
|
57
|
-
end
|
58
|
-
@atype[t] = [pat, block]
|
59
|
-
end
|
60
|
-
EOS
|
61
|
-
expect(refs_to_self(src)).to eq(2)
|
62
|
-
end
|
63
46
|
end
|
64
47
|
end
|
@@ -47,4 +47,16 @@ RSpec.describe Reek::SmellDetectors::PrimaDonnaMethod do
|
|
47
47
|
|
48
48
|
expect(src).not_to reek_of(:PrimaDonnaMethod)
|
49
49
|
end
|
50
|
+
|
51
|
+
it 'does not report methods we excluded via comment' do
|
52
|
+
source = <<-EOF
|
53
|
+
# :reek:PrimaDonnaMethod: { exclude: [ bravo! ] }
|
54
|
+
class Alfa
|
55
|
+
def bravo!
|
56
|
+
end
|
57
|
+
end
|
58
|
+
EOF
|
59
|
+
|
60
|
+
expect(source).not_to reek_of(:PrimaDonnaMethod)
|
61
|
+
end
|
50
62
|
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: 4.5.
|
4
|
+
version: 4.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Rutherford
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: codeclimate-engine-rb
|