cookstyle 6.17.6 → 6.17.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba71cee9089746fb000cf88734c03cd0017265baba00f7559ad9f31453ec8d78
4
- data.tar.gz: 57599dee847f9240cd882bf777cdc5b6a45649851725f0520c9f2704ff181b14
3
+ metadata.gz: '0385aed05c2f7b990958984ace106ea1f8b12d62feae5ba63fc0c382a880f678'
4
+ data.tar.gz: e7888f5a8f5959069e00a5d3be8ce8a80325b34fe0d943baddb8a414f97947fd
5
5
  SHA512:
6
- metadata.gz: e54c382931bae26f96ddad4d54ed69f630d4ab02464dae8f5bbce300d0a0b552d765151dbc912456a34e8344b4517e98f520a839d20266d0f9a7e1d09b4eac0d
7
- data.tar.gz: 2ed745d40e3538b0681cdce2e896a8ae1b99c29fd0ca7d74dd0c007ebf1b13458cbf39d383a26aa26a932289e1badf796e06ab6f145046f305c301b9b634a792
6
+ metadata.gz: a89eab0482fd1c1c158b9f5ead6f61b4693a391fd88855bba6b5e46f60ae3ebb28074ef7782e4d249cd097ebd8093461c25baaff2c699ae214bc12d8584b95ef
7
+ data.tar.gz: b125b09055b3388353ac3374ea1aa5061dc6dfe75f051a538004ed13d064820e40920d2d13fd2a0557cfe3b602237f346b7316adaa2e1174f9b0e4400ff7e71b
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.17.6" # rubocop: disable Style/StringLiterals
3
+ VERSION = "6.17.7" # rubocop: disable Style/StringLiterals
4
4
  RUBOCOP_VERSION = '0.90.0'
5
5
  end
@@ -33,30 +33,58 @@ module RuboCop
33
33
  # ::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
34
34
  #
35
35
  class IncorrectLibraryInjection < Base
36
+ include RangeHelp
36
37
  extend AutoCorrector
37
38
 
38
39
  MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
39
40
 
41
+ def_node_search :correct_send?, <<-PATTERN
42
+ (send
43
+ (const
44
+ (const
45
+ (const {cbase nil?} :Chef) :DSL) :Recipe) :send
46
+ (sym :include)
47
+ ... )
48
+ PATTERN
49
+
50
+ def_node_search :correct_include?, <<-PATTERN
51
+ (send
52
+ (const
53
+ (const
54
+ (const {cbase nil?} :Chef) :DSL) :Recipe) :include
55
+ ... )
56
+ PATTERN
57
+
40
58
  def_node_matcher :legacy_class_sends?, <<-PATTERN
41
59
  (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
42
60
  PATTERN
43
61
 
44
- def_node_matcher :legacy_class_includes?, <<-PATTERN
62
+ def_node_matcher :legacy_class_include?, <<-PATTERN
45
63
  (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )
46
64
  PATTERN
47
65
 
66
+ # @todo: This is highly repetitive and could be simplified into a single node_matcher
67
+ # call with some matcher magic that should be figured out
48
68
  def on_send(node)
49
69
  legacy_class_sends?(node) do
50
70
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
51
- corrector.replace(node.loc.expression,
52
- node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
71
+ if node.parent && correct_send?(node.parent)
72
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
73
+ else
74
+ corrector.replace(node.loc.expression,
75
+ node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
76
+ end
53
77
  end
54
78
  end
55
79
 
56
- legacy_class_includes?(node) do
80
+ legacy_class_include?(node) do
57
81
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
58
- corrector.replace(node.loc.expression,
59
- node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
82
+ if node.parent && correct_include?(node.parent)
83
+ corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
84
+ else
85
+ corrector.replace(node.loc.expression,
86
+ node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
87
+ end
60
88
  end
61
89
  end
62
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cookstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.17.6
4
+ version: 6.17.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May