reek 3.10.1 → 3.10.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +26 -25
  4. data/.simplecov +10 -0
  5. data/CHANGELOG.md +4 -0
  6. data/Gemfile +3 -2
  7. data/README.md +11 -0
  8. data/bin/code_climate_reek +1 -1
  9. data/docs/Feature-Envy.md +1 -1
  10. data/docs/style-guide.md +1 -7
  11. data/lib/reek/ast/ast_node_class_map.rb +1 -1
  12. data/lib/reek/ast/node.rb +4 -4
  13. data/lib/reek/ast/object_refs.rb +1 -3
  14. data/lib/reek/ast/reference_collector.rb +2 -4
  15. data/lib/reek/ast/sexp_extensions/send.rb +1 -1
  16. data/lib/reek/ast/sexp_extensions/variables.rb +1 -1
  17. data/lib/reek/cli/application.rb +3 -12
  18. data/lib/reek/cli/command.rb +1 -5
  19. data/lib/reek/cli/option_interpreter.rb +5 -2
  20. data/lib/reek/cli/reek_command.rb +5 -1
  21. data/lib/reek/cli/warning_collector.rb +1 -2
  22. data/lib/reek/code_comment.rb +3 -3
  23. data/lib/reek/configuration/app_configuration.rb +3 -3
  24. data/lib/reek/context/attribute_context.rb +3 -1
  25. data/lib/reek/context/code_context.rb +2 -3
  26. data/lib/reek/context/statement_counter.rb +4 -2
  27. data/lib/reek/context/visibility_tracker.rb +6 -6
  28. data/lib/reek/context_builder.rb +7 -6
  29. data/lib/reek/examiner.rb +2 -1
  30. data/lib/reek/rake/task.rb +1 -2
  31. data/lib/reek/report.rb +4 -4
  32. data/lib/reek/report/code_climate/code_climate_formatter.rb +2 -3
  33. data/lib/reek/report/formatter.rb +4 -3
  34. data/lib/reek/report/report.rb +2 -2
  35. data/lib/reek/smells/control_parameter.rb +4 -4
  36. data/lib/reek/smells/data_clump.rb +4 -4
  37. data/lib/reek/smells/duplicate_method_call.rb +5 -5
  38. data/lib/reek/smells/long_parameter_list.rb +1 -1
  39. data/lib/reek/smells/long_yield_list.rb +1 -1
  40. data/lib/reek/smells/nested_iterators.rb +5 -5
  41. data/lib/reek/smells/nil_check.rb +1 -1
  42. data/lib/reek/smells/repeated_conditional.rb +1 -1
  43. data/lib/reek/smells/smell_configuration.rb +4 -6
  44. data/lib/reek/smells/smell_detector.rb +4 -3
  45. data/lib/reek/smells/smell_repository.rb +2 -2
  46. data/lib/reek/smells/smell_warning.rb +1 -1
  47. data/lib/reek/smells/too_many_instance_variables.rb +1 -1
  48. data/lib/reek/smells/too_many_methods.rb +1 -1
  49. data/lib/reek/smells/too_many_statements.rb +1 -1
  50. data/lib/reek/smells/uncommunicative_method_name.rb +4 -4
  51. data/lib/reek/smells/uncommunicative_module_name.rb +4 -4
  52. data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -4
  53. data/lib/reek/smells/uncommunicative_variable_name.rb +5 -5
  54. data/lib/reek/source/source_code.rb +3 -3
  55. data/lib/reek/source/source_locator.rb +3 -4
  56. data/lib/reek/spec/should_reek.rb +4 -2
  57. data/lib/reek/spec/should_reek_of.rb +4 -4
  58. data/lib/reek/spec/should_reek_only_of.rb +1 -1
  59. data/lib/reek/spec/smell_matcher.rb +1 -1
  60. data/lib/reek/tree_dresser.rb +1 -1
  61. data/lib/reek/version.rb +1 -1
  62. data/reek.gemspec +1 -2
  63. data/spec/reek/cli/application_spec.rb +31 -0
  64. data/spec/reek/cli/reek_command_spec.rb +45 -0
  65. data/spec/reek/rake/task_spec.rb +33 -0
  66. data/spec/reek/smells/utility_function_spec.rb +1 -1
  67. data/spec/spec_helper.rb +3 -2
  68. data/tasks/configuration.rake +1 -1
  69. data/tasks/test.rake +1 -1
  70. metadata +11 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf831607e9695f0bd26f4cd6ba2c5e155c43bbdf
4
- data.tar.gz: d8288adc73c7bfbd81af8d81546f1e0583181a74
3
+ metadata.gz: a251ceb10b65df518731985aac57a7f73b29961b
4
+ data.tar.gz: 9490529cdf278161c31bf009b99bbb39dd9d633f
5
5
  SHA512:
6
- metadata.gz: 408e265b23ef389a7d8a1f651c1b1c3d6cd77a3521abcb5cdd7233043ae389b709f48dbb1509cfceed38c815266b97acfcb0d2376811cc36da32fe71edec1534
7
- data.tar.gz: af007da9b29b3c6f3bd70ccb0caec7aa7b8177a09ac3036cccb7725d2e208bd060bb167dba0e165df708f48aac87717d9fb645540da281c6de3ee36690d48ba1
6
+ metadata.gz: f1a8f22deef9a74aa7eb9938e637372e276b5af8ede419383364579950b4d59d3632bce86b8c023749282bd527fe7e27074f7a18154f8a7356157518c4b690c0
7
+ data.tar.gz: c2057985478a62c26b33b6e45db1c0dffc11ede4fa188ce6df4191369b8b5d0aba6d3f7b76f3d91004305f965e67e08b31339e6d9f89c3ca65dc2ad209a1ac76
data/.gitignore CHANGED
@@ -2,6 +2,7 @@ pkg
2
2
  spec/output
3
3
  tmp
4
4
  doc
5
+ coverage
5
6
  .yardoc
6
7
  .bundle
7
8
  .rspec
@@ -22,21 +22,15 @@ Metrics/LineLength:
22
22
  Metrics/ParameterLists:
23
23
  CountKeywordArgs: false
24
24
 
25
- # Indent one level for follow-up lines
26
- Style/MultilineOperationIndentation:
27
- EnforcedStyle: indented
28
-
29
- # Allow small arrays of words with quotes
30
- Style/WordArray:
31
- MinSize: 3
32
-
33
- # Allow single-line method definitions
34
- Style/SingleLineMethods:
35
- Enabled: false
25
+ Style/AccessorMethodName:
26
+ Exclude:
27
+ - 'lib/reek/context/visibility_tracker.rb'
36
28
 
37
- # Always use raise to signal exceptions
38
- Style/SignalException:
39
- EnforcedStyle: only_raise
29
+ Style/Documentation:
30
+ Exclude:
31
+ - 'lib/reek/ast/sexp_extensions/send.rb'
32
+ - 'lib/reek/ast/sexp_extensions/super.rb'
33
+ - 'lib/reek/ast/sexp_extensions/variables.rb'
40
34
 
41
35
  # Place . on the previous line
42
36
  Style/DotPosition:
@@ -50,19 +44,26 @@ Style/EmptyLineBetweenDefs:
50
44
  Style/MultilineBlockChain:
51
45
  Enabled: false
52
46
 
47
+ # Indent one level for follow-up lines
48
+ Style/MultilineMethodCallIndentation:
49
+ EnforcedStyle: indented
50
+
51
+ # Indent one level for follow-up lines
52
+ Style/MultilineOperationIndentation:
53
+ EnforcedStyle: indented
54
+
55
+ # There's nothing wrong with parallel assignment
56
+ Style/ParallelAssignment:
57
+ Enabled: false
58
+
53
59
  # Allow Perl-style references to regex matches
54
60
  Style/PerlBackrefs:
55
61
  Enabled: false
56
62
 
57
- Style/Documentation:
58
- Exclude:
59
- - 'lib/reek/ast/sexp_extensions/send.rb'
60
- - 'lib/reek/ast/sexp_extensions/super.rb'
61
- - 'lib/reek/ast/sexp_extensions/variables.rb'
62
-
63
- Style/AccessorMethodName:
64
- Exclude:
65
- - 'lib/reek/context/visibility_tracker.rb'
66
-
67
- Style/ParallelAssignment:
63
+ # Allow single-line method definitions
64
+ Style/SingleLineMethods:
68
65
  Enabled: false
66
+
67
+ # Allow small arrays of words with quotes
68
+ Style/WordArray:
69
+ MinSize: 4
@@ -0,0 +1,10 @@
1
+ SimpleCov.start do
2
+ track_files 'lib/**/*.rb'
3
+ add_filter 'lib/reek/version.rb' # version.rb is loaded too early to test
4
+ end
5
+
6
+ SimpleCov.at_exit do
7
+ SimpleCov.result.format!
8
+ SimpleCov.minimum_coverage 98.9
9
+ SimpleCov.minimum_coverage_by_file 81.4
10
+ end
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.10.2 (2016-02-15)
6
+
7
+ * (troessner) Bump parser to 2.3.0.6 as minimum to fix problems with invalid syntax.
8
+
5
9
  ## 3.10.1 (2016-02-07)
6
10
 
7
11
  * (mvz) Fix edge case syntax problems
data/Gemfile CHANGED
@@ -3,14 +3,15 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem 'aruba', '~> 0.10.0'
6
+ gem 'aruba', '~> 0.12.0'
7
7
  gem 'ataru', '~> 0.2.0'
8
8
  gem 'cucumber', '~> 2.0'
9
9
  gem 'factory_girl', '~> 4.0'
10
10
  gem 'rake', '~> 10.0'
11
11
  gem 'rspec', '~> 3.0'
12
- gem 'rubocop', '~> 0.34.0'
12
+ gem 'rubocop', '~> 0.37.0'
13
13
  gem 'yard', '~> 0.8.7'
14
+ gem 'simplecov', '~> 0.11.1'
14
15
 
15
16
  platforms :mri do
16
17
  gem 'redcarpet', '~> 3.3.1'
data/README.md CHANGED
@@ -61,6 +61,17 @@ demo.rb -- 8 warnings:
61
61
  [3]:Dirty#awful has unused parameter 'y' (UnusedParameters)
62
62
  ```
63
63
 
64
+ ## Supported rubies
65
+
66
+ `Reek` is officially running on the following MRI rubies:
67
+
68
+ - 2.0
69
+ - 2.1
70
+ - 2.2
71
+ - 2.3
72
+
73
+ Other rubies like Rubinius or JRuby are not officially supported but should work as well.
74
+
64
75
  ## Fixing Smell Warnings
65
76
 
66
77
  Reek focuses on high-level code smells, so we can't tell you how to fix warnings in
@@ -13,7 +13,7 @@ class CodeClimateToReek
13
13
  '-f', 'code_climate',
14
14
  '--failure-exit-code', '0',
15
15
  '--success-exit-code', '0'
16
- ]
16
+ ].freeze
17
17
 
18
18
  attr_reader :configuration_file_path, :include_paths_key, :include_paths_default
19
19
 
@@ -42,7 +42,7 @@ _Feature Envy_ reports any method that refers to self less often than it refers
42
42
 
43
43
  ## Differences to _Utility Function_
44
44
 
45
- _Feature Envy_ is only triggered if there are some references to self and _[Utility Function](Utility Function.md)_ is triggered if there are no references to self.
45
+ _Feature Envy_ is only triggered if there are some references to self and _[Utility Function](Utility-Function.md)_ is triggered if there are no references to self.
46
46
 
47
47
  ## Configuration
48
48
 
@@ -9,10 +9,4 @@ We use instance vars only:
9
9
 
10
10
  For everything else we use proper getters / setters.
11
11
 
12
- If possible those should be private. We use the [private_attr](https://github.com/jswanner/private_attr) for this, e.g.:
13
-
14
- ```Ruby
15
- private_attr_reader :configuration
16
- private_attr_writer :failure_message
17
- private_attr_accessor :examiner
18
- ```
12
+ If possible those should be private.
@@ -34,7 +34,7 @@ module Reek
34
34
 
35
35
  private
36
36
 
37
- private_attr_reader :klass_map
37
+ attr_reader :klass_map
38
38
  end
39
39
  end
40
40
  end
@@ -1,4 +1,3 @@
1
- require 'private_attr/everywhere'
2
1
  require_relative '../cli/silencer'
3
2
 
4
3
  Reek::CLI::Silencer.silently do
@@ -12,7 +11,6 @@ module Reek
12
11
  #
13
12
  class Node < ::Parser::AST::Node
14
13
  attr_reader :parent
15
- private_attr_reader :comments
16
14
 
17
15
  def initialize(type, children = [], options = {})
18
16
  @comments = options.fetch(:comments, [])
@@ -109,14 +107,14 @@ module Reek
109
107
  each_sexp do |elem|
110
108
  elem.look_for_type(target_type, ignoring, &blk) unless ignoring.include?(elem.type)
111
109
  end
112
- blk.call(self) if type == target_type
110
+ yield self if type == target_type
113
111
  end
114
112
 
115
113
  # See ".find_nodes" for documentation.
116
114
  def look_for_types(target_types, ignoring = [], &blk)
117
115
  return if ignoring.include?(type)
118
116
  if target_types.include? type
119
- blk.call(self)
117
+ yield self
120
118
  else
121
119
  each_sexp do |elem|
122
120
  elem.look_for_types(target_types, ignoring, &blk)
@@ -126,6 +124,8 @@ module Reek
126
124
 
127
125
  private
128
126
 
127
+ attr_reader :comments
128
+
129
129
  def each_sexp
130
130
  children.each { |elem| yield elem if elem.is_a? ::Parser::AST::Node }
131
131
  end
@@ -1,5 +1,3 @@
1
- require 'private_attr/everywhere'
2
-
3
1
  module Reek
4
2
  # Represents functionality related to an Abstract Syntax Tree.
5
3
  module AST
@@ -55,7 +53,7 @@ module Reek
55
53
 
56
54
  private
57
55
 
58
- private_attr_reader :refs
56
+ attr_reader :refs
59
57
  end
60
58
  end
61
59
  end
@@ -1,5 +1,3 @@
1
- require 'private_attr/everywhere'
2
-
3
1
  module Reek
4
2
  module AST
5
3
  #
@@ -7,7 +5,7 @@ module Reek
7
5
  # of an abstract syntax tree.
8
6
  #
9
7
  class ReferenceCollector
10
- STOP_NODES = [:class, :module, :def, :defs]
8
+ STOP_NODES = [:class, :module, :def, :defs].freeze
11
9
 
12
10
  def initialize(ast)
13
11
  @ast = ast
@@ -19,7 +17,7 @@ module Reek
19
17
 
20
18
  private
21
19
 
22
- private_attr_reader :ast
20
+ attr_reader :ast
23
21
 
24
22
  def explicit_self_calls
25
23
  [:self, :super, :zsuper, :ivar, :ivasgn].flat_map do |node_type|
@@ -3,7 +3,7 @@ module Reek
3
3
  module SexpExtensions
4
4
  # Utility methods for :send nodes.
5
5
  module SendNode
6
- ATTR_DEFN_METHODS = [:attr_writer, :attr_accessor]
6
+ ATTR_DEFN_METHODS = [:attr_writer, :attr_accessor].freeze
7
7
 
8
8
  def receiver
9
9
  children.first
@@ -27,7 +27,7 @@ module Reek
27
27
  module LvarNode
28
28
  include VariableBase
29
29
 
30
- alias_method :var_name, :name
30
+ alias var_name name
31
31
  end
32
32
 
33
33
  # Utility methods for :gvar nodes.
@@ -13,9 +13,6 @@ module Reek
13
13
  class Application
14
14
  attr_reader :configuration
15
15
 
16
- private_attr_accessor :status
17
- private_attr_reader :command, :options
18
-
19
16
  def initialize(argv)
20
17
  @options = configure_options(argv)
21
18
  @status = options.success_exit_code
@@ -25,19 +22,13 @@ module Reek
25
22
 
26
23
  def execute
27
24
  command.execute self
28
- status
29
- end
30
-
31
- def report_success
32
- self.status = options.success_exit_code
33
- end
34
-
35
- def report_smells
36
- self.status = options.failure_exit_code
37
25
  end
38
26
 
39
27
  private
40
28
 
29
+ attr_accessor :status
30
+ attr_reader :command, :options
31
+
41
32
  def configure_options(argv)
42
33
  Options.new(argv).parse
43
34
  rescue OptionParser::InvalidOption => error
@@ -1,20 +1,16 @@
1
- require 'private_attr/everywhere'
2
-
3
1
  module Reek
4
2
  module CLI
5
3
  #
6
4
  # Base class for all commands
7
5
  #
8
6
  class Command
9
- attr_reader :options
10
-
11
7
  def initialize(options)
12
8
  @options = options
13
9
  end
14
10
 
15
11
  private
16
12
 
17
- private_attr_reader :options
13
+ attr_reader :options
18
14
  end
19
15
  end
20
16
  end
@@ -10,8 +10,7 @@ module Reek
10
10
  class OptionInterpreter
11
11
  include Input
12
12
  extend Forwardable
13
- def_delegators :options, :smells_to_detect
14
- private_attr_reader :argv, :options
13
+ def_delegators :options, :smells_to_detect, :success_exit_code, :failure_exit_code
15
14
 
16
15
  def initialize(options)
17
16
  @options = options
@@ -50,6 +49,10 @@ module Reek
50
49
  def sort_by_issue_count
51
50
  options.sorting == :smelliness
52
51
  end
52
+
53
+ private
54
+
55
+ attr_reader :argv, :options
53
56
  end
54
57
  end
55
58
  end
@@ -12,12 +12,16 @@ module Reek
12
12
  options.sources.each do |source|
13
13
  reporter.add_examiner Examiner.new(source, smell_names, configuration: app.configuration)
14
14
  end
15
- reporter.smells? ? app.report_smells : app.report_success
16
15
  reporter.show
16
+ result_code
17
17
  end
18
18
 
19
19
  private
20
20
 
21
+ def result_code
22
+ reporter.smells? ? options.failure_exit_code : options.success_exit_code
23
+ end
24
+
21
25
  def reporter
22
26
  @reporter ||= options.reporter
23
27
  end
@@ -1,4 +1,3 @@
1
- require 'private_attr/everywhere'
2
1
  require 'set'
3
2
 
4
3
  module Reek
@@ -21,7 +20,7 @@ module Reek
21
20
 
22
21
  private
23
22
 
24
- private_attr_reader :warnings_set
23
+ attr_reader :warnings_set
25
24
  end
26
25
  end
27
26
  end
@@ -1,5 +1,4 @@
1
1
  require 'yaml'
2
- require 'private_attr/everywhere'
3
2
 
4
3
  module Reek
5
4
  #
@@ -9,11 +8,10 @@ module Reek
9
8
  class CodeComment
10
9
  CONFIGURATION_REGEX = /:reek:(\w+)(:\s*\{.*?\})?/
11
10
  SANITIZE_REGEX = /(#|\n|\s)+/ # Matches '#', newlines and > 1 whitespaces.
12
- DISABLE_DETECTOR_CONFIGURATION = ': { enabled: false }'
11
+ DISABLE_DETECTOR_CONFIGURATION = ': { enabled: false }'.freeze
13
12
  MINIMUM_CONTENT_LENGTH = 2
14
13
 
15
14
  attr_reader :config
16
- private_attr_reader :original_comment
17
15
 
18
16
  #
19
17
  # @param comment [String] - the original comment as found in the source code
@@ -35,6 +33,8 @@ module Reek
35
33
 
36
34
  private
37
35
 
36
+ attr_reader :original_comment
37
+
38
38
  def sanitized_comment
39
39
  @sanitized_comment ||= original_comment.
40
40
  gsub(CONFIGURATION_REGEX, '').
@@ -1,5 +1,4 @@
1
1
  require 'pathname'
2
- require 'private_attr/everywhere'
3
2
  require_relative './configuration_file_finder'
4
3
  require_relative './configuration_validator'
5
4
  require_relative './default_directive'
@@ -14,8 +13,7 @@ module Reek
14
13
  # @public
15
14
  class AppConfiguration
16
15
  include ConfigurationValidator
17
- EXCLUDE_PATHS_KEY = 'exclude_paths'
18
- private_attr_writer :directory_directives, :default_directive, :excluded_paths
16
+ EXCLUDE_PATHS_KEY = 'exclude_paths'.freeze
19
17
 
20
18
  # Instantiate a configuration via given path.
21
19
  #
@@ -103,6 +101,8 @@ module Reek
103
101
 
104
102
  private
105
103
 
104
+ attr_writer :directory_directives, :default_directive, :excluded_paths
105
+
106
106
  def directory_directives
107
107
  @directory_directives ||= {}.extend(DirectoryDirectives)
108
108
  end