reek 3.8.1 → 3.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +3 -1
- data/features/command_line_interface/options.feature +14 -0
- data/features/step_definitions/reek_steps.rb +7 -3
- data/features/step_definitions/sample_file_steps.rb +19 -0
- data/lib/reek/cli/application.rb +5 -13
- data/lib/reek/cli/options.rb +35 -9
- data/lib/reek/source/source_code.rb +5 -5
- data/lib/reek/source/source_locator.rb +6 -2
- data/lib/reek/version.rb +1 -1
- data/spec/reek/source/source_code_spec.rb +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b0a5ac6a8b0b3a7b7c68c09462e3337c8914e9e
|
4
|
+
data.tar.gz: 519f5ade29783ce076e8b6ee58b126ccef9afc27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 336a10dfe8f830398b76dc288aab1eaad282d6f6e83d904d5292ee08436ea932e14090f791f9eee039fea211b772aee472ca66a0f31f4b10c5742db147b5e414
|
7
|
+
data.tar.gz: 8a120730d0611c4ca5e23bbddfca5c0ea76badf734dfe925588b299e2d5508298cbeae7be1c943e6e3b8dfe21e813907085eda4fcf15024c96dd32926edd0f4d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,7 @@ Reek is a tool that examines Ruby classes, modules and methods and reports any
|
|
17
17
|
|
18
18
|
For an excellent introduction to
|
19
19
|
[Code Smells](docs/Code-Smells.md) and `Reek` check out [this blog post](https://blog.codeship.com/how-to-find-ruby-code-smells-with-reek/)
|
20
|
-
or [this talk](https://www.youtube.com/watch?v=ZzqOuHI5MkA).
|
20
|
+
or [that one](https://troessner.wordpress.com/2016/01/01/the-latest-and-greatest-additions-to-reek/). There is also [this talk](https://www.youtube.com/watch?v=ZzqOuHI5MkA) from the RUBYCONF Porto.
|
21
21
|
|
22
22
|
Install it via rubygems:
|
23
23
|
|
@@ -385,6 +385,8 @@ Just add this to your configuration file:
|
|
385
385
|
enabled: false
|
386
386
|
NestedIterators:
|
387
387
|
max_allowed_nesting: 2
|
388
|
+
UnusedPrivateMethod:
|
389
|
+
enabled: false
|
388
390
|
"app/helpers":
|
389
391
|
IrresponsibleModule:
|
390
392
|
enabled: false
|
@@ -14,6 +14,16 @@ Feature: Reek can be controlled using command-line options
|
|
14
14
|
Then it succeeds
|
15
15
|
And it reports the current version
|
16
16
|
|
17
|
+
Scenario: return given status code when using --failure-exit-code
|
18
|
+
Given the smelly file 'smelly.rb'
|
19
|
+
When I run reek smelly.rb --failure-exit-code 23
|
20
|
+
Then the exit status is 23
|
21
|
+
|
22
|
+
Scenario: return given status code when using --success-exit-code
|
23
|
+
Given the clean file 'clean.rb'
|
24
|
+
When I run reek clean.rb --success-exit-code 42
|
25
|
+
Then the exit status is 42
|
26
|
+
|
17
27
|
Scenario: display the help information
|
18
28
|
When I run reek --help
|
19
29
|
Then it succeeds
|
@@ -52,6 +62,10 @@ Feature: Reek can be controlled using command-line options
|
|
52
62
|
smelliness ("smelliest" files first)
|
53
63
|
none (default - output in processing order)
|
54
64
|
|
65
|
+
Exit codes:
|
66
|
+
--success-exit-code CODE The exit code when no smells are found (default: 0)
|
67
|
+
--failure-exit-code CODE The exit code when smells are found (default: 2)
|
68
|
+
|
55
69
|
Utility options:
|
56
70
|
-h, --help Show this message
|
57
71
|
-v, --version Show version
|
@@ -23,20 +23,24 @@ Then /^stdout includes "(.*)"$/ do |text|
|
|
23
23
|
end
|
24
24
|
|
25
25
|
Then /^it succeeds$/ do
|
26
|
-
success = Reek::CLI::
|
26
|
+
success = Reek::CLI::Options::DEFAULT_SUCCESS_EXIT_CODE
|
27
27
|
expect(last_command_started).to have_exit_status(success)
|
28
28
|
end
|
29
29
|
|
30
30
|
Then /^the exit status indicates an error$/ do
|
31
|
-
error = Reek::CLI::
|
31
|
+
error = Reek::CLI::Options::DEFAULT_ERROR_EXIT_CODE
|
32
32
|
expect(last_command_started).to have_exit_status(error)
|
33
33
|
end
|
34
34
|
|
35
35
|
Then /^the exit status indicates smells$/ do
|
36
|
-
smells = Reek::CLI::
|
36
|
+
smells = Reek::CLI::Options::DEFAULT_FAILURE_EXIT_CODE
|
37
37
|
expect(last_command_started).to have_exit_status(smells)
|
38
38
|
end
|
39
39
|
|
40
|
+
Then(/^the exit status is (\d+)$/) do |status|
|
41
|
+
expect(last_command_started).to have_exit_status(status.to_i)
|
42
|
+
end
|
43
|
+
|
40
44
|
Then /^it reports:$/ do |report|
|
41
45
|
expect(last_command_started).to have_output_on_stdout(report.gsub('\n', "\n"))
|
42
46
|
end
|
@@ -1,3 +1,22 @@
|
|
1
|
+
Given(/^the smelly file 'smelly.rb'$/) do
|
2
|
+
contents = <<-EOS.strip_heredoc
|
3
|
+
class Smelly
|
4
|
+
def x; end
|
5
|
+
end
|
6
|
+
EOS
|
7
|
+
write_file('smelly.rb', contents)
|
8
|
+
end
|
9
|
+
|
10
|
+
Given(/^the clean file 'clean.rb'$/) do
|
11
|
+
contents = <<-EOS.strip_heredoc
|
12
|
+
# Explanatory comment
|
13
|
+
class Clean
|
14
|
+
def foo; end
|
15
|
+
end
|
16
|
+
EOS
|
17
|
+
write_file('clean.rb', contents)
|
18
|
+
end
|
19
|
+
|
1
20
|
Given(/^the smelly file 'demo.rb' from the example in the README$/) do
|
2
21
|
contents = <<-EOS.strip_heredoc
|
3
22
|
class Dirty
|
data/lib/reek/cli/application.rb
CHANGED
@@ -11,53 +11,45 @@ module Reek
|
|
11
11
|
# command line.
|
12
12
|
#
|
13
13
|
class Application
|
14
|
-
STATUS_SUCCESS = 0
|
15
|
-
STATUS_ERROR = 1
|
16
|
-
STATUS_SMELLS = 2
|
17
14
|
attr_reader :configuration
|
18
15
|
|
19
16
|
private_attr_accessor :status
|
20
17
|
private_attr_reader :command, :options
|
21
18
|
|
22
19
|
def initialize(argv)
|
23
|
-
@status = STATUS_SUCCESS
|
24
20
|
@options = configure_options(argv)
|
21
|
+
@status = options.success_exit_code
|
25
22
|
@configuration = configure_app_configuration(options.config_file)
|
26
23
|
@command = ReekCommand.new(OptionInterpreter.new(options))
|
27
24
|
end
|
28
25
|
|
29
26
|
def execute
|
30
|
-
return status if error_occured?
|
31
27
|
command.execute self
|
32
28
|
status
|
33
29
|
end
|
34
30
|
|
35
31
|
def report_success
|
36
|
-
self.status =
|
32
|
+
self.status = options.success_exit_code
|
37
33
|
end
|
38
34
|
|
39
35
|
def report_smells
|
40
|
-
self.status =
|
36
|
+
self.status = options.failure_exit_code
|
41
37
|
end
|
42
38
|
|
43
39
|
private
|
44
40
|
|
45
|
-
def error_occured?
|
46
|
-
status == STATUS_ERROR
|
47
|
-
end
|
48
|
-
|
49
41
|
def configure_options(argv)
|
50
42
|
Options.new(argv).parse
|
51
43
|
rescue OptionParser::InvalidOption => error
|
52
44
|
$stderr.puts "Error: #{error}"
|
53
|
-
exit
|
45
|
+
exit Options::DEFAULT_ERROR_EXIT_CODE
|
54
46
|
end
|
55
47
|
|
56
48
|
def configure_app_configuration(config_file)
|
57
49
|
Configuration::AppConfiguration.from_path(config_file)
|
58
50
|
rescue Reek::Configuration::ConfigFileException => error
|
59
51
|
$stderr.puts "Error: #{error}"
|
60
|
-
exit
|
52
|
+
exit Options::DEFAULT_ERROR_EXIT_CODE
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
data/lib/reek/cli/options.rb
CHANGED
@@ -9,9 +9,14 @@ module Reek
|
|
9
9
|
#
|
10
10
|
# See {file:docs/Command-Line-Options.md} for details.
|
11
11
|
#
|
12
|
-
# :reek:TooManyInstanceVariables: { max_instance_variables:
|
12
|
+
# :reek:TooManyInstanceVariables: { max_instance_variables: 9 }
|
13
13
|
# :reek:Attribute: { enabled: false }
|
14
|
+
#
|
14
15
|
class Options
|
16
|
+
DEFAULT_SUCCESS_EXIT_CODE = 0
|
17
|
+
DEFAULT_ERROR_EXIT_CODE = 1
|
18
|
+
DEFAULT_FAILURE_EXIT_CODE = 2
|
19
|
+
|
15
20
|
attr_reader :argv, :parser, :smells_to_detect
|
16
21
|
attr_accessor :colored,
|
17
22
|
:config_file,
|
@@ -19,16 +24,20 @@ module Reek
|
|
19
24
|
:report_format,
|
20
25
|
:show_empty,
|
21
26
|
:show_links,
|
22
|
-
:sorting
|
27
|
+
:sorting,
|
28
|
+
:success_exit_code,
|
29
|
+
:failure_exit_code
|
23
30
|
|
24
31
|
def initialize(argv = [])
|
25
|
-
@argv
|
26
|
-
@parser
|
27
|
-
@report_format
|
28
|
-
@location_format
|
29
|
-
@show_links
|
30
|
-
@smells_to_detect
|
31
|
-
@colored
|
32
|
+
@argv = argv
|
33
|
+
@parser = OptionParser.new
|
34
|
+
@report_format = :text
|
35
|
+
@location_format = :numbers
|
36
|
+
@show_links = true
|
37
|
+
@smells_to_detect = []
|
38
|
+
@colored = color_support?
|
39
|
+
@success_exit_code = DEFAULT_SUCCESS_EXIT_CODE
|
40
|
+
@failure_exit_code = DEFAULT_FAILURE_EXIT_CODE
|
32
41
|
|
33
42
|
set_up_parser
|
34
43
|
end
|
@@ -46,11 +55,13 @@ module Reek
|
|
46
55
|
$stdout.tty?
|
47
56
|
end
|
48
57
|
|
58
|
+
# :reek:TooManyStatements: { max_statements: 6 }
|
49
59
|
def set_up_parser
|
50
60
|
set_banner
|
51
61
|
set_configuration_options
|
52
62
|
set_alternative_formatter_options
|
53
63
|
set_report_formatting_options
|
64
|
+
set_exit_codes
|
54
65
|
set_utility_options
|
55
66
|
end
|
56
67
|
|
@@ -138,6 +149,21 @@ module Reek
|
|
138
149
|
end
|
139
150
|
end
|
140
151
|
|
152
|
+
# :reek:DuplicateMethodCall: { max_calls: 2 }
|
153
|
+
def set_exit_codes
|
154
|
+
parser.separator "\nExit codes:"
|
155
|
+
parser.on('--success-exit-code CODE',
|
156
|
+
'The exit code when no smells are found '\
|
157
|
+
"(default: #{DEFAULT_SUCCESS_EXIT_CODE})") do |option|
|
158
|
+
self.success_exit_code = Integer(option)
|
159
|
+
end
|
160
|
+
parser.on('--failure-exit-code CODE',
|
161
|
+
'The exit code when smells are found '\
|
162
|
+
"(default: #{DEFAULT_FAILURE_EXIT_CODE})") do |option|
|
163
|
+
self.failure_exit_code = Integer(option)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
141
167
|
# :reek:TooManyStatements: { max_statements: 7 }
|
142
168
|
def set_utility_options
|
143
169
|
parser.separator "\nUtility options:"
|
@@ -21,7 +21,7 @@ module Reek
|
|
21
21
|
# code - Ruby code as String
|
22
22
|
# origin - 'STDIN', 'string' or a filepath as String
|
23
23
|
# parser - the parser to use for generating AST's out of the given source
|
24
|
-
def initialize(code, origin, parser: Parser::Ruby22)
|
24
|
+
def initialize(code: raise, origin: raise, parser: Parser::Ruby22)
|
25
25
|
@source = code
|
26
26
|
@origin = origin
|
27
27
|
@parser = parser
|
@@ -39,10 +39,10 @@ module Reek
|
|
39
39
|
# :reek:DuplicateMethodCall: { max_calls: 2 }
|
40
40
|
def self.from(source)
|
41
41
|
case source
|
42
|
-
when File then new(source.read, source.path)
|
43
|
-
when IO then new(source.readlines.join, IO_IDENTIFIER)
|
44
|
-
when Pathname then new(source.read, source.to_s)
|
45
|
-
when String then new(source, STRING_IDENTIFIER)
|
42
|
+
when File then new(code: source.read, origin: source.path)
|
43
|
+
when IO then new(code: source.readlines.join, origin: IO_IDENTIFIER)
|
44
|
+
when Pathname then new(code: source.read, origin: source.to_s)
|
45
|
+
when String then new(code: source, origin: STRING_IDENTIFIER)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -31,11 +31,15 @@ module Reek
|
|
31
31
|
|
32
32
|
private_attr_reader :configuration, :paths
|
33
33
|
|
34
|
-
# :reek:TooManyStatements: { max_statements:
|
34
|
+
# :reek:TooManyStatements: { max_statements: 7 }
|
35
35
|
# :reek:NestedIterators: { max_allowed_nesting: 2 }
|
36
36
|
def source_paths
|
37
37
|
paths.each_with_object([]) do |given_path, relevant_paths|
|
38
|
-
|
38
|
+
unless given_path.exist?
|
39
|
+
print_no_such_file_error(given_path)
|
40
|
+
next
|
41
|
+
end
|
42
|
+
|
39
43
|
given_path.find do |path|
|
40
44
|
if path.directory?
|
41
45
|
ignore_path?(path) ? Find.prune : next
|
data/lib/reek/version.rb
CHANGED
@@ -6,20 +6,20 @@ RSpec.describe Reek::Source::SourceCode do
|
|
6
6
|
describe '#syntax_tree' do
|
7
7
|
it 'associates comments with the AST' do
|
8
8
|
source = "# this is\n# a comment\ndef foo; end"
|
9
|
-
source_code = Reek::Source::SourceCode.new(source, '(string)')
|
9
|
+
source_code = Reek::Source::SourceCode.new(code: source, origin: '(string)')
|
10
10
|
result = source_code.syntax_tree
|
11
11
|
expect(result.leading_comment).to eq "# this is\n# a comment"
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'cleanly processes empty source' do
|
15
|
-
source_code = Reek::Source::SourceCode.new('', '(string)')
|
15
|
+
source_code = Reek::Source::SourceCode.new(code: '', origin: '(string)')
|
16
16
|
result = source_code.syntax_tree
|
17
17
|
expect(result).to be_nil
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'cleanly processes empty source with comments' do
|
21
21
|
source = "# this is\n# a comment\n"
|
22
|
-
source_code = Reek::Source::SourceCode.new(source, '(string)')
|
22
|
+
source_code = Reek::Source::SourceCode.new(code: source, origin: '(string)')
|
23
23
|
result = source_code.syntax_tree
|
24
24
|
expect(result).to be_nil
|
25
25
|
end
|
@@ -30,7 +30,7 @@ RSpec.describe Reek::Source::SourceCode do
|
|
30
30
|
let(:source_name) { 'Test source' }
|
31
31
|
let(:error_message) { 'Error message' }
|
32
32
|
let(:parser) { double('parser') }
|
33
|
-
let(:src) { Reek::Source::SourceCode.new('', source_name, parser: parser) }
|
33
|
+
let(:src) { Reek::Source::SourceCode.new(code: '', origin: source_name, parser: parser) }
|
34
34
|
|
35
35
|
before { $stderr = catcher }
|
36
36
|
|
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: 3.8.
|
4
|
+
version: 3.8.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:
|
14
|
+
date: 2016-01-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: codeclimate-engine-rb
|
@@ -538,7 +538,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
538
538
|
version: '0'
|
539
539
|
requirements: []
|
540
540
|
rubyforge_project:
|
541
|
-
rubygems_version: 2.4.5
|
541
|
+
rubygems_version: 2.4.5
|
542
542
|
signing_key:
|
543
543
|
specification_version: 4
|
544
544
|
summary: Code smell detector for Ruby
|