reek 4.8.0 → 4.8.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 03a8001a3b22bcc9d88119e88b42854baec8a7e6
4
- data.tar.gz: 51eeaee185f5d97ef76ba341a875aad0202c14ad
2
+ SHA256:
3
+ metadata.gz: 2d66c9a36e561c26a8a5cd27af9780ded54de1fdfe9b00b289701027403330b3
4
+ data.tar.gz: 592050ff0e9af5744467c2299cb085246059fbdc96358dbadbad68a0f2e36763
5
5
  SHA512:
6
- metadata.gz: a8302cbf65eb954433fb21243998da37fdc1755a7a82f10a465f7205c9b697f8498b593584d3fbc857c6d8544bbd49441c42f62ea5049916ad2a02bdf7a6ef94
7
- data.tar.gz: 3150c68090b560dbdd91e51dc520c63bc6d6367c3efa4772e64205969b22fb0cdf292ed297a3f09ef271f32b9594d9380bc817cc855021e003c641a561606143
6
+ metadata.gz: 431ee00e3a0021baa1c752d0a2393b84bdf873d7be702c428f57b1b538ff9dceb11957551674be4031ddd26d9ddb7aa9a01a00b84aa53cd1650f76f045243370
7
+ data.tar.gz: 58c93de891eec497652eda081101a7b77a93eee296c4824b379beb4982de4064c9488d67fa9dd9fe2cfe822f428be305befd65a80b77fe5ec3eb2a4d428a3b5a
@@ -2,7 +2,9 @@ sudo: false
2
2
  dist: trusty
3
3
  cache: bundler
4
4
  language: ruby
5
- before_install: gem update --system
5
+ before_install:
6
+ - gem update --system
7
+ - gem install bundler
6
8
  bundler_args: --without debugging
7
9
  script: bundle exec rake ci
8
10
  rvm:
@@ -1,6 +1,8 @@
1
1
  # Change log
2
2
 
3
- ## Unreleased
3
+ ## 4.8.1 (2018-04-12)
4
+
5
+ * (mvz) Loosen dependency on rainbow
4
6
 
5
7
  ## 4.8.0 (2018-03-05)
6
8
 
data/Gemfile CHANGED
@@ -12,11 +12,11 @@ group :development do
12
12
  gem 'factory_bot', '~> 4.0'
13
13
  gem 'rake', '~> 12.0'
14
14
  gem 'rspec', '~> 3.0'
15
- gem 'simplecov', '~> 0.15.0'
15
+ gem 'simplecov', '~> 0.16.1'
16
16
  gem 'yard', '~> 0.9.5'
17
17
 
18
18
  if RUBY_VERSION >= '2.3'
19
- gem 'rubocop', '~> 0.52.0'
19
+ gem 'rubocop', '~> 0.53.0'
20
20
  gem 'rubocop-rspec', '~> 1.20'
21
21
  end
22
22
 
@@ -84,7 +84,7 @@ end
84
84
 
85
85
  ```Ruby
86
86
  class BankController < ActionController::Base
87
- before_filter :audit
87
+ before_action :audit
88
88
 
89
89
  private
90
90
  def audit
@@ -14,12 +14,11 @@ module Reek
14
14
  FILE_NAME = '.todo.reek'.freeze
15
15
 
16
16
  def execute
17
- smells = scan_for_smells
18
17
  if smells.empty?
19
18
  puts "\n'.todo.reek' not generated because "\
20
19
  'there were no smells found!'
21
20
  else
22
- File.write FILE_NAME, groups_for(smells).to_yaml
21
+ File.write FILE_NAME, groups.to_yaml
23
22
  puts "\n'.todo.reek' generated! You can now use "\
24
23
  'this as a starting point for your configuration.'
25
24
  end
@@ -28,14 +27,13 @@ module Reek
28
27
 
29
28
  private
30
29
 
31
- def scan_for_smells
32
- sources.map do |source|
33
- Examiner.new(source,
34
- filter_by_smells: smell_names)
30
+ def smells
31
+ @smells ||= sources.map do |source|
32
+ Examiner.new(source, filter_by_smells: smell_names)
35
33
  end.map(&:smells).flatten
36
34
  end
37
35
 
38
- def groups_for(smells)
36
+ def groups
39
37
  @groups ||=
40
38
  begin
41
39
  todos = smells.group_by(&:smell_class).map do |smell_class, smells_for_class|
@@ -206,7 +206,7 @@ module Reek
206
206
  #
207
207
  # def self.foo; end
208
208
  #
209
- def process_self(_, _parent)
209
+ def process_self(_exp, _parent)
210
210
  current_context.record_use_of_self
211
211
  end
212
212
 
@@ -226,7 +226,7 @@ module Reek
226
226
  #
227
227
  # We record one reference to `self`.
228
228
  #
229
- def process_zsuper(_, _parent)
229
+ def process_zsuper(_exp, _parent)
230
230
  current_context.record_use_of_self
231
231
  end
232
232
 
@@ -5,7 +5,7 @@ module Reek
5
5
  # loads the smell type metadata to present in Code Climate
6
6
  module CodeClimateConfiguration
7
7
  def self.load
8
- config_file = File.expand_path('../code_climate_configuration.yml', __FILE__)
8
+ config_file = File.expand_path('code_climate_configuration.yml', __dir__)
9
9
  YAML.load_file config_file
10
10
  end
11
11
  end
@@ -59,7 +59,7 @@ module Reek
59
59
  end
60
60
 
61
61
  def source_line
62
- @line ||= expression.line
62
+ @source_line ||= expression.line
63
63
  end
64
64
 
65
65
  def exception?
@@ -17,6 +17,21 @@ module Reek
17
17
  # A +Source+ object represents a chunk of Ruby source code.
18
18
  #
19
19
  class SourceCode
20
+ # Consume and store parser diagnostics
21
+ class DiagnosticsConsumer
22
+ def initialize
23
+ @diagnostics = []
24
+ end
25
+
26
+ def call(item)
27
+ @diagnostics << item
28
+ end
29
+
30
+ def result
31
+ @diagnostics
32
+ end
33
+ end
34
+
20
35
  IO_IDENTIFIER = 'STDIN'.freeze
21
36
  STRING_IDENTIFIER = 'string'.freeze
22
37
 
@@ -26,11 +41,11 @@ module Reek
26
41
  #
27
42
  # code - Ruby code as String
28
43
  # origin - 'STDIN', 'string' or a filepath as String
29
- # parser - the parser to use for generating AST's out of the given source
30
- def initialize(code:, origin:, parser: default_parser)
44
+ # parser - the parser to use for generating AST's out of the given code
45
+ def initialize(code:, origin:, parser: self.class.default_parser)
31
46
  @origin = origin
32
- @diagnostics = []
33
47
  @parser = parser
48
+ code.force_encoding(Encoding::UTF_8)
34
49
  @code = code
35
50
  end
36
51
 
@@ -54,23 +69,32 @@ module Reek
54
69
  end
55
70
 
56
71
  def diagnostics
57
- parse_if_needed
58
- @diagnostics
72
+ parse_result.last
59
73
  end
60
74
 
61
75
  def syntax_tree
62
- parse_if_needed
76
+ parse_result.first
77
+ end
78
+
79
+ def self.default_parser
80
+ Parser::Ruby25.new(AST::Builder.new).tap do |parser|
81
+ diagnostics = parser.diagnostics
82
+ diagnostics.all_errors_are_fatal = false
83
+ diagnostics.ignore_warnings = false
84
+ diagnostics.consumer = DiagnosticsConsumer.new
85
+ end
63
86
  end
64
87
 
65
88
  private
66
89
 
67
- def parse_if_needed
68
- @syntax_tree ||= parse(@parser, @code)
90
+ def parse_result
91
+ @parse_result ||= parse
69
92
  end
70
93
 
71
- attr_reader :source
94
+ attr_reader :code
95
+ attr_reader :parser
72
96
 
73
- # Parses the given source into an AST and associates the source code comments with it.
97
+ # Parses the given code into an AST and associates the source code comments with it.
74
98
  # This AST is then traversed by a TreeDresser which adorns the nodes in the AST
75
99
  # with our SexpExtensions.
76
100
  # Finally this AST is returned where each node is an anonymous subclass of Reek::AST::Node
@@ -78,7 +102,7 @@ module Reek
78
102
  # Important to note is that Reek will not fail on unparseable files but rather register a
79
103
  # parse error to @diagnostics and then just continue.
80
104
  #
81
- # Given this @source:
105
+ # Given this @code:
82
106
  #
83
107
  # # comment about C
84
108
  # class C
@@ -99,33 +123,16 @@ module Reek
99
123
  # where each node is possibly adorned with our SexpExtensions (see ast/ast_node_class_map
100
124
  # and ast/sexp_extensions for details).
101
125
  #
102
- # @param parser [Parser::Ruby25]
103
- # @param source [String] - Ruby code
104
- # @return [Anonymous subclass of Reek::AST::Node] the AST presentation
105
- # for the given source
106
- # :reek:TooManyStatements { max_statements: 6 }
107
- def parse(parser, source)
126
+ # @return [Anonymous subclass of Reek::AST::Node, Array] the AST presentation
127
+ # for the given code, List of diagnostics messages
128
+ def parse
108
129
  buffer = Parser::Source::Buffer.new(origin, 1)
109
- source.force_encoding(Encoding::UTF_8)
110
- buffer.source = source
130
+ buffer.source = code
111
131
  ast, comments = parser.parse_with_comments(buffer)
112
132
 
113
133
  # See https://whitequark.github.io/parser/Parser/Source/Comment/Associator.html
114
134
  comment_map = Parser::Source::Comment.associate(ast, comments)
115
- TreeDresser.new.dress(ast, comment_map)
116
- end
117
-
118
- # :reek:TooManyStatements: { max_statements: 6 }
119
- # :reek:FeatureEnvy
120
- def default_parser
121
- Parser::Ruby25.new(AST::Builder.new).tap do |parser|
122
- diagnostics = parser.diagnostics
123
- diagnostics.all_errors_are_fatal = false
124
- diagnostics.ignore_warnings = false
125
- diagnostics.consumer = lambda do |diagnostic|
126
- @diagnostics << diagnostic
127
- end
128
- end
135
+ [TreeDresser.new.dress(ast, comment_map), parser.diagnostics.consumer.result]
129
136
  end
130
137
  end
131
138
  end
@@ -8,6 +8,6 @@ module Reek
8
8
  # @public
9
9
  module Version
10
10
  # @public
11
- STRING = '4.8.0'.freeze
11
+ STRING = '4.8.1'.freeze
12
12
  end
13
13
  end
@@ -22,5 +22,5 @@ Gem::Specification.new do |s|
22
22
 
23
23
  s.add_runtime_dependency 'codeclimate-engine-rb', '~> 0.4.0'
24
24
  s.add_runtime_dependency 'parser', '< 2.6', '>= 2.5.0.0'
25
- s.add_runtime_dependency 'rainbow', '~> 3.0'
25
+ s.add_runtime_dependency 'rainbow', '>= 2.0', '< 4.0'
26
26
  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.8.0
4
+ version: 4.8.1
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: 2018-03-05 00:00:00.000000000 Z
14
+ date: 2018-04-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: codeclimate-engine-rb
@@ -51,16 +51,22 @@ dependencies:
51
51
  name: rainbow
52
52
  requirement: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - "~>"
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '2.0'
57
+ - - "<"
55
58
  - !ruby/object:Gem::Version
56
- version: '3.0'
59
+ version: '4.0'
57
60
  type: :runtime
58
61
  prerelease: false
59
62
  version_requirements: !ruby/object:Gem::Requirement
60
63
  requirements:
61
- - - "~>"
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ - - "<"
62
68
  - !ruby/object:Gem::Version
63
- version: '3.0'
69
+ version: '4.0'
64
70
  description: Reek is a tool that examines Ruby classes, modules and methods and reports
65
71
  any code smells it finds.
66
72
  email:
@@ -447,7 +453,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
447
453
  version: '0'
448
454
  requirements: []
449
455
  rubyforge_project:
450
- rubygems_version: 2.5.1
456
+ rubygems_version: 2.7.6
451
457
  signing_key:
452
458
  specification_version: 4
453
459
  summary: Code smell detector for Ruby