cookstyle 5.0.4 → 5.1.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +9 -0
  3. data/bin/cookstyle +7 -0
  4. data/config/cookstyle.yml +195 -7
  5. data/config/upstream.yml +1 -1
  6. data/lib/cookstyle.rb +1 -0
  7. data/lib/cookstyle/version.rb +1 -1
  8. data/lib/rubocop/chef/cookbook_only.rb +4 -3
  9. data/lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb +60 -0
  10. data/lib/rubocop/cop/chef/correctness/name_property_and_required.rb +94 -0
  11. data/lib/rubocop/cop/chef/correctness/node_normal.rb +53 -0
  12. data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +53 -0
  13. data/lib/rubocop/cop/chef/correctness/property_with_default_and_required.rb +67 -0
  14. data/lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb +59 -0
  15. data/lib/rubocop/cop/chef/{service_resource.rb → correctness/service_resource.rb} +1 -1
  16. data/lib/rubocop/cop/chef/{tmp_path.rb → correctness/tmp_path.rb} +1 -1
  17. data/lib/rubocop/cop/chef/deprecation/attribute_metadata.rb +49 -0
  18. data/lib/rubocop/cop/chef/deprecation/conflicts_metadata.rb +44 -0
  19. data/lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb +48 -0
  20. data/lib/rubocop/cop/chef/deprecation/depends_partial_search.rb +42 -0
  21. data/lib/rubocop/cop/chef/deprecation/depends_poise.rb +42 -0
  22. data/lib/rubocop/cop/chef/deprecation/easy_install.rb +39 -0
  23. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +50 -0
  24. data/lib/rubocop/cop/chef/deprecation/erl_call.rb +39 -0
  25. data/lib/rubocop/cop/chef/{node_set.rb → deprecation/node_set.rb} +2 -2
  26. data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +53 -0
  27. data/lib/rubocop/cop/chef/deprecation/provides_metadata.rb +44 -0
  28. data/lib/rubocop/cop/chef/deprecation/replaces_metadata.rb +44 -0
  29. data/lib/rubocop/cop/chef/deprecation/suggests_metadata.rb +44 -0
  30. data/lib/rubocop/cop/chef/effortless/data_bags.rb +36 -0
  31. data/lib/rubocop/cop/chef/effortless/search_used.rb +36 -0
  32. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +59 -0
  33. data/lib/rubocop/cop/chef/modernize/build_essential.rb +52 -0
  34. data/lib/rubocop/cop/chef/modernize/chef_14_resources.rb +54 -0
  35. data/lib/rubocop/cop/chef/modernize/why_run_supported_true.rb +46 -0
  36. data/lib/rubocop/cop/chef/{attribute_keys.rb → style/attribute_keys.rb} +2 -2
  37. data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +42 -0
  38. data/lib/rubocop/cop/chef/{comments_copyright_format.rb → style/comments_copyright_format.rb} +5 -2
  39. data/lib/rubocop/cop/chef/{comments_format.rb → style/comments_format.rb} +4 -2
  40. data/lib/rubocop/cop/chef/{file_mode.rb → style/file_mode.rb} +1 -3
  41. metadata +34 -9
@@ -0,0 +1,59 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Over the course of years there have been many different valid community site / Supermarket
21
+ # URLs to use in a cookbook's Berksfile. These old URLs continue to function via redirects,
22
+ # but should be updated to point to the latest Supermarket URL.
23
+ #
24
+ # @example
25
+ #
26
+ # # bad
27
+ # source 'http://community.opscode.com/api/v3'
28
+ # source 'https://supermarket.getchef.com'
29
+ # source 'https://api.berkshelf.com'
30
+ #
31
+ # # good
32
+ # source 'https://supermarket.chef.io'
33
+ #
34
+ class LegacyBerksfileSource < Cop
35
+ MSG = 'Do not use legacy Berksfile community sources. Use Chef Supermarket instead.'.freeze
36
+
37
+ def_node_matcher :berksfile_source?, <<-PATTERN
38
+ (send nil? :source (str #old_berkshelf_url?))
39
+ PATTERN
40
+
41
+ def old_berkshelf_url?(url)
42
+ %w(http://community.opscode.com/api/v3 https://supermarket.getchef.com https://api.berkshelf.com).include?(url)
43
+ end
44
+
45
+ def on_send(node)
46
+ berksfile_source?(node) do
47
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
48
+ end
49
+ end
50
+
51
+ def autocorrect(node)
52
+ lambda do |corrector|
53
+ corrector.replace(node.loc.expression, "source 'https://supermarket.chef.io'")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,52 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Use secure Github and Gitlab URLs for source_url and issues_url
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # depends 'build-essential'
26
+ # include_recipe 'build-essential::default'
27
+ # include_recipe 'build-essential'
28
+ #
29
+ # # good
30
+ # build_essential 'install compilation tools'
31
+ class UseBuildEssentialResource < Cop
32
+ MSG = 'Use the build_essential resource built into Chef 14+ instead of the legacy build-essential recipe'.freeze
33
+
34
+ def_node_matcher :build_essential_recipe_usage?, <<-PATTERN
35
+ (send nil? :include_recipe (str {"build-essential" "build-essential::default"}))
36
+ PATTERN
37
+
38
+ def on_send(node)
39
+ build_essential_recipe_usage?(node) do
40
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
41
+ end
42
+ end
43
+
44
+ def autocorrect(node)
45
+ lambda do |corrector|
46
+ corrector.replace(node.loc.expression, "build_essential 'install compilation tools'")
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # Don't depend on cookbooks made obsolete by Chef 14
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # depends 'build-essential'
26
+ # depends 'chef_handler'
27
+ # depends 'chef_hostname'
28
+ # depends 'dmg'
29
+ # depends 'mac_os_x'
30
+ # depends 'swap'
31
+ # depends 'sysctl'
32
+ #
33
+ class UnnecessaryDependsChef14 < Cop
34
+ MSG = "Don't depend on cookbooks made obsolete by Chef 14".freeze
35
+
36
+ def_node_matcher :legacy_depends?, <<-PATTERN
37
+ (send nil? :depends (str {"build-essential" "chef_handler" "chef_hostname" "dmg" "mac_os_x" "swap" "sysctl"}))
38
+ PATTERN
39
+
40
+ def on_send(node)
41
+ legacy_depends?(node) do
42
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
43
+ end
44
+ end
45
+
46
+ def autocorrect(node)
47
+ lambda do |corrector|
48
+ corrector.remove(node.loc.expression)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,46 @@
1
+ #
2
+ # Copyright:: 2019, Chef Software Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+ module RuboCop
18
+ module Cop
19
+ module Chef
20
+ # why_run_supported? no longer needs to be set to true as that is the default in Chef 13+
21
+ #
22
+ # @example
23
+ #
24
+ # # bad
25
+ # def why_run_supported?
26
+ # true
27
+ # end
28
+ #
29
+ class WhyRunSupportedTrue < Cop
30
+ MSG = 'why_run_supported? no longer needs to be set to true as it is the default in Chef 13+'.freeze
31
+
32
+ def on_def(node)
33
+ if node.method_name == :why_run_supported? && node.body == s(:true) # rubocop: disable Lint/BooleanSymbol
34
+ add_offense(node, location: :expression, message: MSG, severity: :refactor)
35
+ end
36
+ end
37
+
38
+ def autocorrect(node)
39
+ lambda do |corrector|
40
+ corrector.remove(node.loc.expression)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -68,10 +68,10 @@ module RuboCop
68
68
  def on_node_attribute_access(node)
69
69
  if node.type == :str
70
70
  style_detected(:strings)
71
- add_offense(node, location: :expression, message: MSG % style, severity: :warning) if style == :symbols
71
+ add_offense(node, location: :expression, message: MSG % style, severity: :refactor) if style == :symbols
72
72
  elsif node.type == :sym
73
73
  style_detected(:symbols)
74
- add_offense(node, location: :expression, message: MSG % style, severity: :warning) if style == :strings
74
+ add_offense(node, location: :expression, message: MSG % style, severity: :refactor) if style == :strings
75
75
  end
76
76
  end
77
77
 
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright:: 2016-2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ module RuboCop
19
+ module Cop
20
+ module Chef
21
+ # Replaces double spaces between sentences with a single space.
22
+ # Note: This is DISABLED by default.
23
+ class CommentSentenceSpacing < Cop
24
+ MSG = 'Use a single space after sentences in comments'.freeze
25
+
26
+ def investigate(processed_source)
27
+ return unless processed_source.ast
28
+
29
+ processed_source.comments.each do |comment|
30
+ if comment.text.match?(/(.|\?)\s{2}/) # https://rubular.com/r/8o3SiDrQMJSzuU
31
+ add_offense(comment, location: comment.loc.expression, message: MSG, severity: :refactor)
32
+ end
33
+ end
34
+ end
35
+
36
+ def autocorrect(comment)
37
+ ->(corrector) { corrector.replace(comment.loc.expression, comment.text.gsub('. ', '. ').gsub('? ', '? ')) }
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,6 @@
1
1
  #
2
- # Copyright:: 2016, Tim Smith
2
+ # Copyright:: 2016-2019, Chef Software, Inc.
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
4
  #
4
5
  # Licensed under the Apache License, Version 2.0 (the "License");
5
6
  # you may not use this file except in compliance with the License.
@@ -42,11 +43,12 @@ module RuboCop
42
43
 
43
44
  def investigate(processed_source)
44
45
  return unless processed_source.ast
46
+
45
47
  processed_source.comments.each do |comment|
46
48
  next unless comment.inline? # headers aren't in blocks
47
49
 
48
50
  if invalid_copyright_comment?(comment)
49
- add_offense(comment, location: comment.loc.expression, message: MSG, severity: :warning)
51
+ add_offense(comment, location: comment.loc.expression, message: MSG, severity: :refactor)
50
52
  end
51
53
  end
52
54
  end
@@ -63,6 +65,7 @@ module RuboCop
63
65
 
64
66
  # no copyright year present so return this year
65
67
  return Time.new.year if dates.empty?
68
+
66
69
  oldest_date = dates.min[0].to_i
67
70
 
68
71
  # Avoid returning THIS_YEAR - THIS_YEAR
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright 2016, Tim Smith
2
+ # Copyright:: 2016, Tim Smith
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -42,11 +42,13 @@ module RuboCop
42
42
 
43
43
  def investigate(processed_source)
44
44
  return unless processed_source.ast
45
+
45
46
  processed_source.comments.each do |comment|
47
+ next if comment.loc.first_line > 10 # avoid false positives when we were checking further down the file
46
48
  next unless comment.inline? # headers aren't in blocks
47
49
 
48
50
  if invalid_comment?(comment)
49
- add_offense(comment, location: comment.loc.expression, message: MSG, severity: :warning)
51
+ add_offense(comment, location: comment.loc.expression, message: MSG, severity: :refactor)
50
52
  end
51
53
  end
52
54
  end
@@ -37,9 +37,7 @@ module RuboCop
37
37
 
38
38
  def on_send(node)
39
39
  resource_mode?(node) do |mode_int|
40
- # for post April 2020
41
- # add_offense(mode_int, location: :expression, message: MSG, severity: octal?(mode_int) ? :warning : :error)
42
- add_offense(mode_int, location: :expression, message: MSG, severity: :warning)
40
+ add_offense(mode_int, location: :expression, message: MSG, severity: :refactor)
43
41
  end
44
42
  end
45
43
 
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: 5.0.4
4
+ version: 5.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thom May
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-07-15 00:00:00.000000000 Z
12
+ date: 2019-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -74,13 +74,38 @@ files:
74
74
  - lib/cookstyle/version.rb
75
75
  - lib/rubocop/chef.rb
76
76
  - lib/rubocop/chef/cookbook_only.rb
77
- - lib/rubocop/cop/chef/attribute_keys.rb
78
- - lib/rubocop/cop/chef/comments_copyright_format.rb
79
- - lib/rubocop/cop/chef/comments_format.rb
80
- - lib/rubocop/cop/chef/file_mode.rb
81
- - lib/rubocop/cop/chef/node_set.rb
82
- - lib/rubocop/cop/chef/service_resource.rb
83
- - lib/rubocop/cop/chef/tmp_path.rb
77
+ - lib/rubocop/cop/chef/correctness/insecure_cookbook_url.rb
78
+ - lib/rubocop/cop/chef/correctness/name_property_and_required.rb
79
+ - lib/rubocop/cop/chef/correctness/node_normal.rb
80
+ - lib/rubocop/cop/chef/correctness/node_normal_unless.rb
81
+ - lib/rubocop/cop/chef/correctness/property_with_default_and_required.rb
82
+ - lib/rubocop/cop/chef/correctness/property_with_name_attribute.rb
83
+ - lib/rubocop/cop/chef/correctness/service_resource.rb
84
+ - lib/rubocop/cop/chef/correctness/tmp_path.rb
85
+ - lib/rubocop/cop/chef/deprecation/attribute_metadata.rb
86
+ - lib/rubocop/cop/chef/deprecation/conflicts_metadata.rb
87
+ - lib/rubocop/cop/chef/deprecation/depends_compat_resource.rb
88
+ - lib/rubocop/cop/chef/deprecation/depends_partial_search.rb
89
+ - lib/rubocop/cop/chef/deprecation/depends_poise.rb
90
+ - lib/rubocop/cop/chef/deprecation/easy_install.rb
91
+ - lib/rubocop/cop/chef/deprecation/epic_fail.rb
92
+ - lib/rubocop/cop/chef/deprecation/erl_call.rb
93
+ - lib/rubocop/cop/chef/deprecation/node_set.rb
94
+ - lib/rubocop/cop/chef/deprecation/node_set_unless.rb
95
+ - lib/rubocop/cop/chef/deprecation/provides_metadata.rb
96
+ - lib/rubocop/cop/chef/deprecation/replaces_metadata.rb
97
+ - lib/rubocop/cop/chef/deprecation/suggests_metadata.rb
98
+ - lib/rubocop/cop/chef/effortless/data_bags.rb
99
+ - lib/rubocop/cop/chef/effortless/search_used.rb
100
+ - lib/rubocop/cop/chef/modernize/berksfile_source.rb
101
+ - lib/rubocop/cop/chef/modernize/build_essential.rb
102
+ - lib/rubocop/cop/chef/modernize/chef_14_resources.rb
103
+ - lib/rubocop/cop/chef/modernize/why_run_supported_true.rb
104
+ - lib/rubocop/cop/chef/style/attribute_keys.rb
105
+ - lib/rubocop/cop/chef/style/comment_sentence_spacing.rb
106
+ - lib/rubocop/cop/chef/style/comments_copyright_format.rb
107
+ - lib/rubocop/cop/chef/style/comments_format.rb
108
+ - lib/rubocop/cop/chef/style/file_mode.rb
84
109
  homepage: https://github.com/chef/cookstyle
85
110
  licenses:
86
111
  - Apache-2.0