rubocop-itamae 0.1.2 → 0.1.3

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: 67e536a274f4c88ae9d0b18095a4e82f3d899943a505527471e6ac609b993a88
4
- data.tar.gz: 4813442b27ccc9cd5f038db98ba50b5d59687cfc44df720d648b6466efce9ac0
3
+ metadata.gz: cb63640ad762db35c994b12f23659776f327c7438ce5b54cc256ca7610b785f2
4
+ data.tar.gz: 33a51ae10a510c3bc23c7c7398b8b679bf0ae9afd08ee8e58d1a25a2cba011b4
5
5
  SHA512:
6
- metadata.gz: a62bc0ec04985dabe2a245c7fef5af0b94856d2461c51fc63bb4e50bf1ddf3be4620dc72867fb3170ae90108bc50ac7a011f8606d266c3b499cc401c697e90ea
7
- data.tar.gz: 6307e1794b5a6c48008a7b8d554bd1020d770c91757518d0be4b71ebe196efb295aa5113431773c3fc1a87f333b8cc2f30fc379cd9584462fb788c07b8fe0dff
6
+ metadata.gz: f54fbdd0c2d8853dcc261aba5e6dc5082cfff91d87d4d51764c5030aa521692885f36ce01f25b2c2778afb59ded3d22c4cbe5df8c03afc6f3209baf10e62d2ee
7
+ data.tar.gz: 24bef86116fb59ab749e567ac3cb103369d37ebea55d508043c6dc35c43a81df3a6b1fdc646e39b0dcd32af5bfb4ed711697a9cd030887d3dda78511ba6dd66f
@@ -1,4 +1,6 @@
1
1
  AllCops:
2
+ NewCops: enable
3
+
2
4
  # rubocop 0.82.0+ requires ruby 2.4+
3
5
  TargetRubyVersion: 2.4
4
6
 
@@ -1,5 +1,13 @@
1
1
  ## master
2
- [full changelog](http://github.com/sue445/rubocop-itamae/compare/v0.1.2...master)
2
+ [full changelog](http://github.com/sue445/rubocop-itamae/compare/v0.1.3...master)
3
+
4
+ ## v0.1.3
5
+ [full changelog](http://github.com/sue445/rubocop-itamae/compare/v0.1.2...v0.1.3)
6
+
7
+ * Fixed. failed spec since rubocop v0.87.0
8
+ * https://github.com/sue445/rubocop-itamae/pull/47
9
+ * Migrate to rubocop v1 syntax
10
+ * https://github.com/sue445/rubocop-itamae/pull/46
3
11
 
4
12
  ## v0.1.2
5
13
  [full changelog](http://github.com/sue445/rubocop-itamae/compare/v0.1.1...v0.1.2)
@@ -13,7 +13,7 @@ module RuboCop
13
13
  # execute 'rm -rf /tmp/*' do
14
14
  # cwd '/tmp'
15
15
  # end
16
- class CdInExecute < Cop
16
+ class CdInExecute < Base
17
17
  MSG = "Insert `cwd '%<dir>s'` and remove this."
18
18
 
19
19
  def_node_search :find_execute_with_block, <<-PATTERN
@@ -58,7 +58,6 @@ module RuboCop
58
58
  end
59
59
  end
60
60
 
61
- # rubocop:disable Layout/LineLength
62
61
  # def autocorrect(node)
63
62
  # if node.block_type?
64
63
  # lambda do |corrector|
@@ -103,7 +102,6 @@ module RuboCop
103
102
  # end
104
103
  # end
105
104
  # end
106
- # rubocop:enable Layout/LineLength
107
105
 
108
106
  private
109
107
 
@@ -112,7 +110,7 @@ module RuboCop
112
110
  return unless dir
113
111
 
114
112
  loc = cd_location(node.child_nodes.first, name)
115
- add_offense(node, message: format(MSG, dir: dir), location: loc)
113
+ add_offense(loc, message: format(MSG, dir: dir))
116
114
  end
117
115
 
118
116
  def add_offence_for_execute_block_name(node, name)
@@ -120,7 +118,7 @@ module RuboCop
120
118
  return unless dir
121
119
 
122
120
  loc = cd_location(node.child_nodes.first.child_nodes.first, name)
123
- add_offense(node, message: format(MSG, dir: dir), location: loc)
121
+ add_offense(loc, message: format(MSG, dir: dir))
124
122
  end
125
123
 
126
124
  def add_offense_for_command_param(param_node, command)
@@ -135,7 +133,7 @@ module RuboCop
135
133
  end
136
134
 
137
135
  loc = cd_location(command_node, command)
138
- add_offense(param_node, message: format(MSG, dir: dir), location: loc)
136
+ add_offense(loc, message: format(MSG, dir: dir))
139
137
  end
140
138
 
141
139
  def cd_dir_in_command(command)
@@ -17,8 +17,9 @@ module RuboCop
17
17
  # execute 'Remove temporary files' do
18
18
  # command 'rm -rf /tmp/*'
19
19
  # end
20
- class CommandEqualsToName < Cop
20
+ class CommandEqualsToName < Base
21
21
  include RangeHelp
22
+ extend AutoCorrector
22
23
 
23
24
  MSG = 'Prefer to omit `command` if `command` equals to ' \
24
25
  'name of `execute`'
@@ -45,27 +46,27 @@ module RuboCop
45
46
  find_command(param_node) do |command|
46
47
  next unless name == command
47
48
 
48
- add_offense(param_node, location: :expression)
49
+ add_param_node_offense(param_node)
49
50
  end
50
51
  end
51
52
  end
52
53
  end
53
54
 
54
- def autocorrect(node)
55
- lambda do |corrector|
56
- if node.begin_type?
57
- node.each_child_node do |param_node|
58
- remove_command_param(corrector, node.parent, param_node)
55
+ private
56
+
57
+ def add_param_node_offense(param_node)
58
+ add_offense(param_node.loc.expression) do |corrector|
59
+ if param_node.begin_type?
60
+ param_node.each_child_node do |child_param_node|
61
+ remove_command_param(corrector, param_node.parent, child_param_node)
59
62
  end
60
63
 
61
- elsif node.send_type?
62
- remove_command_param(corrector, node.parent, node)
64
+ elsif param_node.send_type?
65
+ remove_command_param(corrector, param_node.parent, param_node)
63
66
  end
64
67
  end
65
68
  end
66
69
 
67
- private
68
-
69
70
  def remove_command_param(corrector, parent_node, param_node)
70
71
  find_execute(parent_node) do |name|
71
72
  find_command(param_node) do |command|
@@ -17,8 +17,9 @@ module RuboCop
17
17
  #
18
18
  # package 'git'
19
19
  #
20
- class NeedlessDefaultAction < Cop
20
+ class NeedlessDefaultAction < Base
21
21
  include RangeHelp
22
+ extend AutoCorrector
22
23
 
23
24
  MSG = 'Prefer to omit the default action.'
24
25
 
@@ -62,18 +63,14 @@ module RuboCop
62
63
  find_action(param_node) do |action|
63
64
  next unless action == RESOURCE_DEFAULT_ACTIONS[resource]
64
65
 
65
- add_offense(param_node, location: :expression)
66
+ add_offense(param_node.loc.expression) do |corrector|
67
+ remove_action_param(corrector, param_node.parent, param_node) if param_node.send_type?
68
+ end
66
69
  end
67
70
  end
68
71
  end
69
72
  end
70
73
 
71
- def autocorrect(node)
72
- lambda do |corrector|
73
- remove_action_param(corrector, node.parent, node) if node.send_type?
74
- end
75
- end
76
-
77
74
  private
78
75
 
79
76
  def remove_action_param(corrector, parent_node, param_node)
@@ -17,28 +17,25 @@ module RuboCop
17
17
  # cookbooks/nginx/default.rb
18
18
  # roles/web.rb
19
19
  #
20
- class RecipePath < Cop
20
+ class RecipePath < Base
21
21
  include RangeHelp
22
22
 
23
23
  MSG = 'Prefer recipe to placed under `cookbooks` dir' \
24
24
  ' or `roles` dir.'
25
25
 
26
- def investigate(processed_source)
26
+ def on_new_investigation
27
27
  file_path = processed_source.file_path
28
28
  return if config.file_to_include?(file_path)
29
29
 
30
- for_bad_filename(file_path) do |range, msg|
31
- add_offense(nil, location: range, message: msg)
32
- end
30
+ add_global_offense if bad_filename?(file_path)
33
31
  end
34
32
 
35
33
  private
36
34
 
37
- def for_bad_filename(file_path)
35
+ def bad_filename?(file_path)
38
36
  return unless File.extname(file_path) == '.rb'
39
- return if file_path =~ %r{/(cookbooks|roles)/}
40
37
 
41
- yield source_range(processed_source.buffer, 1, 0), MSG
38
+ !file_path.match?(%r{/(cookbooks|roles)/})
42
39
  end
43
40
  end
44
41
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Itamae
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.3'
6
6
  end
7
7
  end
@@ -24,12 +24,13 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = '>= 2.4.0'
26
26
 
27
- spec.add_dependency 'rubocop', '>= 0.82.0'
27
+ spec.add_dependency 'rubocop', '>= 0.87.0'
28
28
 
29
29
  spec.add_development_dependency 'bundler', '>= 1.16'
30
30
  spec.add_development_dependency 'coveralls'
31
31
  spec.add_development_dependency 'rake', '>= 11.0'
32
32
  spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'rubocop', '>= 0.84.0'
33
34
  spec.add_development_dependency 'rubocop_auto_corrector'
34
35
  spec.add_development_dependency 'simplecov', '< 0.18.0'
35
36
  spec.add_development_dependency 'yard'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - sue445
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2020-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.82.0
19
+ version: 0.87.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.82.0
26
+ version: 0.87.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.84.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 0.84.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rubocop_auto_corrector
85
99
  requirement: !ruby/object:Gem::Requirement