reek 4.6.1 → 4.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +2 -2
- data/README.md +3 -2
- data/bin/code_climate_reek +1 -0
- data/bin/reek +1 -0
- data/lib/reek.rb +1 -0
- data/lib/reek/ast/ast_node_class_map.rb +1 -0
- data/lib/reek/ast/builder.rb +16 -0
- data/lib/reek/ast/node.rb +1 -0
- data/lib/reek/ast/object_refs.rb +1 -0
- data/lib/reek/ast/reference_collector.rb +1 -0
- data/lib/reek/ast/sexp_extensions.rb +1 -0
- data/lib/reek/ast/sexp_extensions/arguments.rb +1 -0
- data/lib/reek/ast/sexp_extensions/attribute_assignments.rb +1 -0
- data/lib/reek/ast/sexp_extensions/block.rb +1 -0
- data/lib/reek/ast/sexp_extensions/case.rb +1 -0
- data/lib/reek/ast/sexp_extensions/constant.rb +1 -0
- data/lib/reek/ast/sexp_extensions/if.rb +1 -0
- data/lib/reek/ast/sexp_extensions/lambda.rb +1 -0
- data/lib/reek/ast/sexp_extensions/literal.rb +1 -0
- data/lib/reek/ast/sexp_extensions/logical_operators.rb +1 -0
- data/lib/reek/ast/sexp_extensions/methods.rb +1 -0
- data/lib/reek/ast/sexp_extensions/module.rb +1 -0
- data/lib/reek/ast/sexp_extensions/nested_assignables.rb +1 -0
- data/lib/reek/ast/sexp_extensions/self.rb +1 -0
- data/lib/reek/ast/sexp_extensions/send.rb +1 -0
- data/lib/reek/ast/sexp_extensions/super.rb +1 -0
- data/lib/reek/ast/sexp_extensions/symbols.rb +1 -0
- data/lib/reek/ast/sexp_extensions/variables.rb +1 -0
- data/lib/reek/ast/sexp_extensions/when.rb +1 -0
- data/lib/reek/ast/sexp_extensions/yield.rb +1 -0
- data/lib/reek/cli/application.rb +1 -0
- data/lib/reek/cli/command/base_command.rb +1 -0
- data/lib/reek/cli/command/report_command.rb +1 -0
- data/lib/reek/cli/command/todo_list_command.rb +1 -0
- data/lib/reek/cli/options.rb +1 -0
- data/lib/reek/cli/silencer.rb +1 -0
- data/lib/reek/cli/status.rb +1 -0
- data/lib/reek/configuration/app_configuration.rb +1 -0
- data/lib/reek/configuration/configuration_file_finder.rb +1 -0
- data/lib/reek/configuration/configuration_validator.rb +1 -0
- data/lib/reek/configuration/default_directive.rb +1 -0
- data/lib/reek/configuration/directory_directives.rb +1 -0
- data/lib/reek/configuration/excluded_paths.rb +1 -0
- data/lib/reek/context/attribute_context.rb +1 -0
- data/lib/reek/context/class_context.rb +1 -0
- data/lib/reek/context/code_context.rb +2 -1
- data/lib/reek/context/ghost_context.rb +1 -0
- data/lib/reek/context/method_context.rb +5 -4
- data/lib/reek/context/module_context.rb +1 -0
- data/lib/reek/context/root_context.rb +1 -0
- data/lib/reek/context/send_context.rb +1 -0
- data/lib/reek/context/singleton_attribute_context.rb +1 -0
- data/lib/reek/context/singleton_method_context.rb +1 -0
- data/lib/reek/context/statement_counter.rb +1 -0
- data/lib/reek/context/visibility_tracker.rb +1 -0
- data/lib/reek/context_builder.rb +1 -0
- data/lib/reek/detector_repository.rb +1 -0
- data/lib/reek/errors/bad_detector_configuration_key_in_comment_error.rb +1 -0
- data/lib/reek/errors/bad_detector_in_comment_error.rb +1 -0
- data/lib/reek/errors/garbage_detector_configuration_in_comment_error.rb +1 -0
- data/lib/reek/errors/incomprehensible_source_error.rb +1 -0
- data/lib/reek/errors/parse_error.rb +1 -0
- data/lib/reek/examiner.rb +1 -0
- data/lib/reek/logging_error_handler.rb +1 -0
- data/lib/reek/report.rb +1 -0
- data/lib/reek/report/base_report.rb +1 -0
- data/lib/reek/report/code_climate.rb +1 -0
- data/lib/reek/report/code_climate/code_climate_configuration.rb +1 -0
- data/lib/reek/report/code_climate/code_climate_fingerprint.rb +1 -0
- data/lib/reek/report/code_climate/code_climate_formatter.rb +1 -0
- data/lib/reek/report/code_climate/code_climate_report.rb +1 -0
- data/lib/reek/report/formatter.rb +1 -0
- data/lib/reek/report/formatter/heading_formatter.rb +1 -0
- data/lib/reek/report/formatter/location_formatter.rb +1 -0
- data/lib/reek/report/formatter/progress_formatter.rb +1 -0
- data/lib/reek/report/formatter/wiki_link_warning_formatter.rb +1 -0
- data/lib/reek/report/html_report.rb +1 -0
- data/lib/reek/report/json_report.rb +1 -0
- data/lib/reek/report/text_report.rb +1 -0
- data/lib/reek/report/xml_report.rb +1 -0
- data/lib/reek/report/yaml_report.rb +1 -0
- data/lib/reek/smell_configuration.rb +1 -0
- data/lib/reek/smell_detectors.rb +1 -0
- data/lib/reek/smell_detectors/attribute.rb +1 -0
- data/lib/reek/smell_detectors/base_detector.rb +1 -0
- data/lib/reek/smell_detectors/boolean_parameter.rb +1 -0
- data/lib/reek/smell_detectors/class_variable.rb +1 -0
- data/lib/reek/smell_detectors/control_parameter.rb +1 -0
- data/lib/reek/smell_detectors/data_clump.rb +1 -0
- data/lib/reek/smell_detectors/duplicate_method_call.rb +1 -0
- data/lib/reek/smell_detectors/feature_envy.rb +1 -0
- data/lib/reek/smell_detectors/instance_variable_assumption.rb +1 -0
- data/lib/reek/smell_detectors/irresponsible_module.rb +1 -0
- data/lib/reek/smell_detectors/long_parameter_list.rb +1 -0
- data/lib/reek/smell_detectors/long_yield_list.rb +1 -0
- data/lib/reek/smell_detectors/manual_dispatch.rb +1 -0
- data/lib/reek/smell_detectors/module_initialize.rb +1 -0
- data/lib/reek/smell_detectors/nested_iterators.rb +1 -0
- data/lib/reek/smell_detectors/nil_check.rb +1 -0
- data/lib/reek/smell_detectors/prima_donna_method.rb +1 -0
- data/lib/reek/smell_detectors/repeated_conditional.rb +1 -0
- data/lib/reek/smell_detectors/subclassed_from_core_class.rb +1 -0
- data/lib/reek/smell_detectors/too_many_constants.rb +1 -0
- data/lib/reek/smell_detectors/too_many_instance_variables.rb +1 -0
- data/lib/reek/smell_detectors/too_many_methods.rb +1 -0
- data/lib/reek/smell_detectors/too_many_statements.rb +1 -0
- data/lib/reek/smell_detectors/uncommunicative_method_name.rb +1 -0
- data/lib/reek/smell_detectors/uncommunicative_module_name.rb +1 -0
- data/lib/reek/smell_detectors/uncommunicative_parameter_name.rb +1 -0
- data/lib/reek/smell_detectors/uncommunicative_variable_name.rb +1 -0
- data/lib/reek/smell_detectors/unused_parameters.rb +1 -0
- data/lib/reek/smell_detectors/unused_private_method.rb +3 -2
- data/lib/reek/smell_detectors/utility_function.rb +1 -0
- data/lib/reek/smell_warning.rb +1 -0
- data/lib/reek/source/source_code.rb +17 -3
- data/lib/reek/source/source_locator.rb +1 -0
- data/lib/reek/spec.rb +1 -0
- data/lib/reek/spec/should_reek.rb +1 -0
- data/lib/reek/spec/should_reek_of.rb +1 -0
- data/lib/reek/spec/should_reek_only_of.rb +1 -0
- data/lib/reek/spec/smell_matcher.rb +2 -1
- data/lib/reek/tree_dresser.rb +1 -0
- data/lib/reek/version.rb +2 -1
- data/reek.gemspec +2 -1
- data/spec/reek/ast/sexp_extensions_spec.rb +1 -0
- data/spec/reek/context/statement_counter_spec.rb +1 -0
- data/spec/reek/examiner_spec.rb +1 -0
- data/spec/reek/report/code_climate/code_climate_fingerprint_spec.rb +2 -0
- data/spec/reek/report/code_climate/code_climate_report_spec.rb +22 -22
- data/spec/reek/report/yaml_report_spec.rb +32 -32
- data/spec/reek/source/source_code_spec.rb +8 -1
- metadata +5 -4
data/lib/reek/smell_warning.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require_relative '../cli/silencer'
|
3
4
|
Reek::CLI::Silencer.silently do
|
4
|
-
require 'parser/
|
5
|
+
require 'parser/ruby24'
|
5
6
|
end
|
6
7
|
require_relative '../tree_dresser'
|
7
8
|
require_relative '../ast/node'
|
9
|
+
require_relative '../ast/builder'
|
8
10
|
require_relative '../errors/parse_error'
|
9
11
|
|
10
12
|
# Opt in to new way of representing lambdas
|
@@ -26,7 +28,7 @@ module Reek
|
|
26
28
|
# code - Ruby code as String
|
27
29
|
# origin - 'STDIN', 'string' or a filepath as String
|
28
30
|
# parser - the parser to use for generating AST's out of the given source
|
29
|
-
def initialize(code:, origin:, parser:
|
31
|
+
def initialize(code:, origin:, parser: default_parser)
|
30
32
|
@source = code
|
31
33
|
@origin = origin
|
32
34
|
@parser = parser
|
@@ -82,11 +84,14 @@ module Reek
|
|
82
84
|
#
|
83
85
|
# @return [Anonymous subclass of Reek::AST::Node] the AST presentation
|
84
86
|
# for the given source
|
87
|
+
# :reek:TooManyStatements: { max_statements: 7 }
|
85
88
|
def syntax_tree
|
86
89
|
@syntax_tree ||=
|
87
90
|
begin
|
91
|
+
buffer = Parser::Source::Buffer.new(origin, 1)
|
92
|
+
buffer.source = source
|
88
93
|
begin
|
89
|
-
ast, comments = parser.parse_with_comments(
|
94
|
+
ast, comments = parser.parse_with_comments(buffer)
|
90
95
|
rescue Racc::ParseError, Parser::SyntaxError => error
|
91
96
|
raise Errors::ParseError, origin: origin, original_exception: error
|
92
97
|
end
|
@@ -100,6 +105,15 @@ module Reek
|
|
100
105
|
private
|
101
106
|
|
102
107
|
attr_reader :parser, :source
|
108
|
+
|
109
|
+
# :reek:UtilityFunction
|
110
|
+
def default_parser
|
111
|
+
Parser::Ruby24.new(AST::Builder.new).tap do |parser|
|
112
|
+
diagnostics = parser.diagnostics
|
113
|
+
diagnostics.all_errors_are_fatal = true
|
114
|
+
diagnostics.ignore_warnings = true
|
115
|
+
end
|
116
|
+
end
|
103
117
|
end
|
104
118
|
end
|
105
119
|
end
|
data/lib/reek/spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module Reek
|
3
4
|
module Spec
|
4
5
|
#
|
@@ -7,7 +8,7 @@ module Reek
|
|
7
8
|
class SmellMatcher
|
8
9
|
attr_reader :smell_warning
|
9
10
|
|
10
|
-
COMPARABLE_ATTRIBUTES =
|
11
|
+
COMPARABLE_ATTRIBUTES = [:message, :lines, :context, :source].freeze
|
11
12
|
|
12
13
|
def initialize(smell_warning)
|
13
14
|
@smell_warning = smell_warning
|
data/lib/reek/tree_dresser.rb
CHANGED
data/lib/reek/version.rb
CHANGED
data/reek.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
|
2
3
|
require File.join(File.dirname(__FILE__), 'lib/reek/version')
|
3
4
|
|
4
5
|
Gem::Specification.new do |s|
|
@@ -22,6 +23,6 @@ Gem::Specification.new do |s|
|
|
22
23
|
s.summary = 'Code smell detector for Ruby'
|
23
24
|
|
24
25
|
s.add_runtime_dependency 'codeclimate-engine-rb', '~> 0.4.0'
|
25
|
-
s.add_runtime_dependency 'parser', '< 2.5', '>= 2.
|
26
|
+
s.add_runtime_dependency 'parser', '< 2.5', '>= 2.4.0.0'
|
26
27
|
s.add_runtime_dependency 'rainbow', '~> 2.0'
|
27
28
|
end
|
data/spec/reek/examiner_spec.rb
CHANGED
@@ -23,11 +23,13 @@ RSpec.describe Reek::Report::CodeClimateFingerprint do
|
|
23
23
|
|
24
24
|
context 'with code at a specific location' do
|
25
25
|
let(:lines) { [1] }
|
26
|
+
|
26
27
|
it_behaves_like 'computes a fingerprint with no parameters'
|
27
28
|
end
|
28
29
|
|
29
30
|
context 'with code at a different location' do
|
30
31
|
let(:lines) { [5] }
|
32
|
+
|
31
33
|
it_behaves_like 'computes a fingerprint with no parameters'
|
32
34
|
end
|
33
35
|
|
@@ -26,28 +26,28 @@ RSpec.describe Reek::Report::CodeClimateReport do
|
|
26
26
|
let(:source) { 'def simple(a) a[3] end' }
|
27
27
|
|
28
28
|
it 'prints smells as json' do
|
29
|
-
expected = <<-EOS.delete("\n")
|
30
|
-
{\"type\":\"issue\",
|
31
|
-
\"check_name\":\"UncommunicativeParameterName\",
|
32
|
-
\"description\":\"simple has the parameter name 'a'\",
|
33
|
-
\"categories\":[\"Complexity\"],
|
34
|
-
\"location\":{\"path\":\"string\",\"lines\":{\"begin\":1,\"end\":1}},
|
35
|
-
\"remediation_points\":150000,
|
36
|
-
\"content\":{\"body\":\"An `Uncommunicative Parameter Name` is a parameter name that
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
\"fingerprint\":\"09970037d92b5a628bf682a3e2bb126d\"}\u0000
|
42
|
-
{\"type\":\"issue\",
|
43
|
-
\"check_name\":\"UtilityFunction\",
|
44
|
-
\"description\":\"simple doesn't depend on instance state (maybe move it to another class?)\",
|
45
|
-
\"categories\":[\"Complexity\"],
|
46
|
-
\"location\":{\"path\":\"string\",\"lines\":{\"begin\":1,\"end\":1}},
|
47
|
-
\"remediation_points\":250000,
|
48
|
-
\"content\":{\"body\":\"A _Utility Function_ is any instance method that has no
|
49
|
-
|
50
|
-
\"fingerprint\":\"db456db7cb344bb5a98b8fc54a2f382e\"}\u0000
|
29
|
+
expected = <<-EOS.strip_heredoc.delete("\n")
|
30
|
+
{\"type\":\"issue\",
|
31
|
+
\"check_name\":\"UncommunicativeParameterName\",
|
32
|
+
\"description\":\"simple has the parameter name 'a'\",
|
33
|
+
\"categories\":[\"Complexity\"],
|
34
|
+
\"location\":{\"path\":\"string\",\"lines\":{\"begin\":1,\"end\":1}},
|
35
|
+
\"remediation_points\":150000,
|
36
|
+
\"content\":{\"body\":\"An `Uncommunicative Parameter Name` is a parameter name that
|
37
|
+
doesn't communicate its intent well enough.\\n\\nPoor names make it hard for the reader
|
38
|
+
to build a mental picture of what's going on in the code. They can also be
|
39
|
+
mis-interpreted; and they hurt the flow of reading, because the reader must slow down
|
40
|
+
to interpret the names.\\n\"},
|
41
|
+
\"fingerprint\":\"09970037d92b5a628bf682a3e2bb126d\"}\u0000
|
42
|
+
{\"type\":\"issue\",
|
43
|
+
\"check_name\":\"UtilityFunction\",
|
44
|
+
\"description\":\"simple doesn't depend on instance state (maybe move it to another class?)\",
|
45
|
+
\"categories\":[\"Complexity\"],
|
46
|
+
\"location\":{\"path\":\"string\",\"lines\":{\"begin\":1,\"end\":1}},
|
47
|
+
\"remediation_points\":250000,
|
48
|
+
\"content\":{\"body\":\"A _Utility Function_ is any instance method that has no
|
49
|
+
dependency on the state of the instance.\\n\"},
|
50
|
+
\"fingerprint\":\"db456db7cb344bb5a98b8fc54a2f382e\"}\u0000
|
51
51
|
EOS
|
52
52
|
|
53
53
|
expect { instance.show }.to output(expected).to_stdout
|
@@ -31,21 +31,21 @@ RSpec.describe Reek::Report::YAMLReport do
|
|
31
31
|
instance.show(out)
|
32
32
|
out.rewind
|
33
33
|
result = YAML.safe_load(out.read)
|
34
|
-
expected = YAML.safe_load <<-EOS
|
35
|
-
---
|
36
|
-
- context: "simple"
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
- context: "simple"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
34
|
+
expected = YAML.safe_load <<-EOS.strip_heredoc
|
35
|
+
---
|
36
|
+
- context: "simple"
|
37
|
+
lines:
|
38
|
+
- 1
|
39
|
+
message: "has the parameter name 'a'"
|
40
|
+
smell_type: "UncommunicativeParameterName"
|
41
|
+
source: "string"
|
42
|
+
name: "a"
|
43
|
+
- context: "simple"
|
44
|
+
lines:
|
45
|
+
- 1
|
46
|
+
message: "doesn't depend on instance state (maybe move it to another class?)"
|
47
|
+
smell_type: "UtilityFunction"
|
48
|
+
source: "string"
|
49
49
|
EOS
|
50
50
|
|
51
51
|
expect(result).to eq expected
|
@@ -58,23 +58,23 @@ RSpec.describe Reek::Report::YAMLReport do
|
|
58
58
|
instance.show(out)
|
59
59
|
out.rewind
|
60
60
|
result = YAML.safe_load(out.read)
|
61
|
-
expected = YAML.safe_load <<-EOS
|
62
|
-
---
|
63
|
-
- context: "simple"
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
- context: "simple"
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
expected = YAML.safe_load <<-EOS.strip_heredoc
|
62
|
+
---
|
63
|
+
- context: "simple"
|
64
|
+
lines:
|
65
|
+
- 1
|
66
|
+
message: "has the parameter name 'a'"
|
67
|
+
smell_type: "UncommunicativeParameterName"
|
68
|
+
source: "string"
|
69
|
+
name: "a"
|
70
|
+
wiki_link: "https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Parameter-Name.md"
|
71
|
+
- context: "simple"
|
72
|
+
lines:
|
73
|
+
- 1
|
74
|
+
message: "doesn't depend on instance state (maybe move it to another class?)"
|
75
|
+
smell_type: "UtilityFunction"
|
76
|
+
source: "string"
|
77
|
+
wiki_link: "https://github.com/troessner/reek/blob/master/docs/Utility-Function.md"
|
78
78
|
EOS
|
79
79
|
|
80
80
|
expect(result).to eq expected
|
@@ -23,12 +23,19 @@ RSpec.describe Reek::Source::SourceCode do
|
|
23
23
|
result = source_code.syntax_tree
|
24
24
|
expect(result).to be_nil
|
25
25
|
end
|
26
|
+
|
27
|
+
it 'does not crash with sequences incompatible with UTF-8' do
|
28
|
+
source = '"\xFF"'
|
29
|
+
source_code = described_class.new(code: source, origin: '(string)')
|
30
|
+
result = source_code.syntax_tree
|
31
|
+
expect(result.children.first).to eq "\xFF"
|
32
|
+
end
|
26
33
|
end
|
27
34
|
|
28
35
|
context 'when the parser fails' do
|
29
36
|
let(:source_name) { 'Test source' }
|
30
37
|
let(:error_message) { 'Error message' }
|
31
|
-
let(:parser) {
|
38
|
+
let(:parser) { instance_double('Parser::Ruby24') }
|
32
39
|
let(:src) { described_class.new(code: '', origin: source_name, parser: parser) }
|
33
40
|
|
34
41
|
shared_examples_for 'handling and recording the error' do
|
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.6.
|
4
|
+
version: 4.6.2
|
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: 2017-04-
|
14
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: codeclimate-engine-rb
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
version: '2.5'
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 2.
|
39
|
+
version: 2.4.0.0
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -46,7 +46,7 @@ dependencies:
|
|
46
46
|
version: '2.5'
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 2.
|
49
|
+
version: 2.4.0.0
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: rainbow
|
52
52
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- features/todo_list.feature
|
174
174
|
- lib/reek.rb
|
175
175
|
- lib/reek/ast/ast_node_class_map.rb
|
176
|
+
- lib/reek/ast/builder.rb
|
176
177
|
- lib/reek/ast/node.rb
|
177
178
|
- lib/reek/ast/object_refs.rb
|
178
179
|
- lib/reek/ast/reference_collector.rb
|