inspecstyle 0.1.2 → 0.2.0
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 +4 -4
- data/.gitignore +0 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -7
- data/README.md +39 -1
- data/Rakefile +3 -0
- data/config/default.yml +95 -2
- data/doc/RuboCop.html +128 -0
- data/doc/RuboCop/Cop.html +117 -0
- data/doc/RuboCop/Cop/InSpecStyle.html +117 -0
- data/doc/RuboCop/Cop/InSpecStyle/AzureGenericResource.html +249 -0
- data/doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes.html +310 -0
- data/doc/RuboCop/Cop/InSpecStyle/FirstCop.html +345 -0
- data/doc/RuboCop/InSpecStyle.html +140 -0
- data/doc/RuboCop/InSpecStyle/Error.html +124 -0
- data/doc/RuboCop/InSpecStyle/Inject.html +195 -0
- data/doc/_index.html +211 -0
- data/doc/class_list.html +51 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +58 -0
- data/doc/css/style.css +496 -0
- data/doc/file.README.html +131 -0
- data/doc/file_list.html +56 -0
- data/doc/frames.html +17 -0
- data/doc/index.html +131 -0
- data/doc/js/app.js +314 -0
- data/doc/js/full_list.js +216 -0
- data/doc/js/jquery.js +4 -0
- data/doc/method_list.html +99 -0
- data/doc/top-level-namespace.html +110 -0
- data/lib/rubocop/cop/inspecstyle/apache.rb +57 -0
- data/lib/rubocop/cop/inspecstyle/aws_iam_user_property.rb +96 -0
- data/lib/rubocop/cop/inspecstyle/azure_generic_resource.rb +35 -0
- data/lib/rubocop/cop/inspecstyle/deprecated_attributes.rb +16 -16
- data/lib/rubocop/cop/inspecstyle/file_be_mounted.rb +65 -0
- data/lib/rubocop/cop/inspecstyle/file_size.rb +77 -0
- data/lib/rubocop/cop/inspecstyle/host_proto.rb +71 -0
- data/lib/rubocop/cop/inspecstyle/iis_website.rb +36 -0
- data/lib/rubocop/cop/inspecstyle/linux_kernel_parameter.rb +41 -0
- data/lib/rubocop/cop/inspecstyle/mssql_session_pass.rb +59 -0
- data/lib/rubocop/cop/inspecstyle/oracle_db_session_pass.rb +59 -0
- data/lib/rubocop/cop/inspecstyle/ppa_resource.rb +36 -0
- data/lib/rubocop/cop/inspecstyle/processes_list.rb +77 -0
- data/lib/rubocop/cop/inspecstyle/script_resource.rb +48 -0
- data/lib/rubocop/cop/inspecstyle/shadow_properties.rb +83 -0
- data/lib/rubocop/cop/inspecstyle/users_resource_matchers.rb +98 -0
- data/lib/rubocop/cop/inspecstyle/windows_registry_key.rb +36 -0
- data/lib/rubocop/cop/inspecstyle/wmi_wmis_class.rb +37 -0
- data/lib/rubocop/cop/inspecstyle_cops.rb +17 -1
- data/lib/rubocop/inspecstyle/version.rb +1 -1
- data/notes-for-development.md +10 -0
- data/tasks/cops_documentation.rake +300 -0
- metadata +43 -3
- data/lib/rubocop/cop/inspecstyle/first_cop.rb +0 -69
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# aws_iam_users resource properties `user|password|last_change|expiry_date|line` is deprecated in favor of `users|passwords|last_changes|expiry_dates|lines`
|
7
|
+
#
|
8
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
9
|
+
# # Use users instead
|
10
|
+
#
|
11
|
+
# # bad
|
12
|
+
# describe aws_iam_user('/etc/my-custom-place/aws_iam_user') do
|
13
|
+
# its('name') { should eq 'user' }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# describe aws_iam_user('/etc/my-custom-place/aws_iam_user') do
|
18
|
+
# its('username') { should eq 'user' }
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
class AwsIamUserProperty < Cop
|
22
|
+
include RangeHelp
|
23
|
+
|
24
|
+
MSG = 'Use `:%<solution>s` instead of `:%<violation>s` as a property ' \
|
25
|
+
'for the `aws_iam_user` resource. This property will be removed in InSpec 5'
|
26
|
+
|
27
|
+
MAP = {
|
28
|
+
user: "aws_user_struct",
|
29
|
+
name: "username"
|
30
|
+
}
|
31
|
+
|
32
|
+
def_node_matcher :deprecated_aws_iam_users_property?, <<~PATTERN
|
33
|
+
(block
|
34
|
+
(send _ :its
|
35
|
+
(str ${"name" "user"}) ...)
|
36
|
+
...)
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
def_node_matcher :spec?, <<-PATTERN
|
40
|
+
(block
|
41
|
+
(send nil? :describe ...)
|
42
|
+
...)
|
43
|
+
PATTERN
|
44
|
+
|
45
|
+
def_node_matcher :aws_iam_users_resource?, <<-PATTERN
|
46
|
+
(block
|
47
|
+
(send nil? :describe
|
48
|
+
(send nil? :aws_iam_users ...)
|
49
|
+
...)
|
50
|
+
...)
|
51
|
+
PATTERN
|
52
|
+
|
53
|
+
def on_block(node)
|
54
|
+
return unless inside_aws_iam_users_spec?(node)
|
55
|
+
node.descendants.each do |descendant|
|
56
|
+
deprecated_aws_iam_users_property?(descendant) do |violation|
|
57
|
+
add_offense(
|
58
|
+
descendant,
|
59
|
+
location: offense_range(descendant),
|
60
|
+
message: format(
|
61
|
+
MSG,
|
62
|
+
violation: violation,
|
63
|
+
solution: MAP[violation.to_sym]
|
64
|
+
)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def autocorrect(node)
|
71
|
+
lambda do |corrector|
|
72
|
+
case node.children[0].children[-1].inspect
|
73
|
+
when "s(:str, \"name\")"
|
74
|
+
corrector.replace(offense_range(node), 'username')
|
75
|
+
when "s(:str, \"user\")"
|
76
|
+
corrector.replace(offense_range(node), 'aws_user_struct')
|
77
|
+
else
|
78
|
+
break
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def inside_aws_iam_users_spec?(root)
|
86
|
+
spec?(root) && aws_iam_users_resource?(root)
|
87
|
+
end
|
88
|
+
|
89
|
+
def offense_range(node)
|
90
|
+
source = node.children[0].children[-1].loc.expression
|
91
|
+
range_between(source.begin_pos+1, source.end_pos-1)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# Do not use azure_generic_resource
|
7
|
+
#
|
8
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
9
|
+
# # azure_generic_resource has been deprecated
|
10
|
+
# # 'https://github.com/inspec/inspec/issues/3131'
|
11
|
+
# # Since there are multiples replacements autocorrect is not supported.
|
12
|
+
#
|
13
|
+
# # bad
|
14
|
+
# azure_generic_resource
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# azurerm_virtual_machine # use a specific resource pack resource
|
18
|
+
#
|
19
|
+
class AzureGenericResource < Cop
|
20
|
+
MSG = 'Use a specific resource instead of `#azure_generic_resource`. '\
|
21
|
+
'This resource will be removed in InSpec 5.'
|
22
|
+
|
23
|
+
def_node_matcher :azure_generic_resource?, <<~PATTERN
|
24
|
+
(send nil? :azure_generic_resource ...)
|
25
|
+
PATTERN
|
26
|
+
|
27
|
+
def on_send(node)
|
28
|
+
return unless azure_generic_resource?(node)
|
29
|
+
|
30
|
+
add_offense(node, location: :selector)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,12 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# TODO: when finished, run `rake generate_cops_documentation` to update the docs
|
4
3
|
module RuboCop
|
5
4
|
module Cop
|
6
5
|
module InSpecStyle
|
7
6
|
# Checks if deprecated method attribute is used.
|
8
7
|
#
|
9
|
-
# @example
|
8
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
10
9
|
# # Attributes have been deprecated for inputs
|
11
10
|
# # https://github.com/inspec/inspec/issues/3802
|
12
11
|
#
|
@@ -19,7 +18,8 @@ module RuboCop
|
|
19
18
|
class DeprecatedAttributes < Cop
|
20
19
|
include RangeHelp
|
21
20
|
|
22
|
-
MSG = 'Use `#input` instead of `#attribute`.'
|
21
|
+
MSG = 'Use `#input` instead of `#attribute`. This will be removed in '\
|
22
|
+
'InSpec 5'
|
23
23
|
|
24
24
|
def_node_matcher :attribute?, <<~PATTERN
|
25
25
|
(send nil? :attribute ...)
|
@@ -27,25 +27,25 @@ module RuboCop
|
|
27
27
|
|
28
28
|
def on_send(node)
|
29
29
|
return unless attribute?(node)
|
30
|
-
|
30
|
+
|
31
|
+
add_offense(node, location: node.loc.selector)
|
32
|
+
end
|
33
|
+
|
34
|
+
def autocorrect(node)
|
35
|
+
lambda do |corrector|
|
36
|
+
corrector.replace(offense_range(node), preferred_replacement)
|
37
|
+
end
|
31
38
|
end
|
32
39
|
|
33
40
|
private
|
34
41
|
|
35
|
-
def
|
36
|
-
|
37
|
-
range_between(
|
38
|
-
node.source_range.begin_pos,
|
39
|
-
node.source_range.begin_pos+9
|
40
|
-
)
|
42
|
+
def offense_range(node)
|
43
|
+
node.loc.selector
|
41
44
|
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
# corrector.remove(node.source_range, 'attribute')
|
47
|
-
# end
|
48
|
-
# end
|
46
|
+
def preferred_replacement
|
47
|
+
cop_config.fetch('PreferredReplacement')
|
48
|
+
end
|
49
49
|
end
|
50
50
|
end
|
51
51
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# NOTE TO SELF - this one works BUT not if other its statements are defined. Needs
|
4
|
+
# to work in any arrangement. This is a powerful one to crack as this pattern
|
5
|
+
# will be used in a LOT of other cops.
|
6
|
+
|
7
|
+
module RuboCop
|
8
|
+
module Cop
|
9
|
+
module InSpecStyle
|
10
|
+
# file resource deprecates matchers `be_mounted.with` and `be_mounted.only_with` in favor of the mount resource
|
11
|
+
#
|
12
|
+
|
13
|
+
class FileBeMounted < Cop
|
14
|
+
MSG = 'Use the `:mount` resource instead of `be_mounted.%<violation>s` ' \
|
15
|
+
"\nThis matcher will be removed in InSpec 5"
|
16
|
+
|
17
|
+
def_node_matcher :deprecated_file_matcher?, <<~PATTERN
|
18
|
+
(send
|
19
|
+
(send _ :be_mounted ...) ${:with :only_with}
|
20
|
+
...)
|
21
|
+
PATTERN
|
22
|
+
|
23
|
+
def_node_matcher :spec?, <<-PATTERN
|
24
|
+
(block
|
25
|
+
(send nil? :describe ...)
|
26
|
+
...)
|
27
|
+
PATTERN
|
28
|
+
|
29
|
+
def_node_matcher :file_resource?, <<-PATTERN
|
30
|
+
(block
|
31
|
+
(send nil? :describe
|
32
|
+
(send nil? :file ...)
|
33
|
+
...)
|
34
|
+
...)
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
def on_block(node)
|
38
|
+
return unless inside_file_spec?(node)
|
39
|
+
node.descendants.each do |descendant|
|
40
|
+
deprecated_file_matcher?(descendant) do |violation|
|
41
|
+
add_offense(
|
42
|
+
descendant,
|
43
|
+
location: offense_range(descendant),
|
44
|
+
message: format(
|
45
|
+
MSG,
|
46
|
+
violation: violation
|
47
|
+
)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def inside_file_spec?(root)
|
56
|
+
spec?(root) && file_resource?(root)
|
57
|
+
end
|
58
|
+
|
59
|
+
def offense_range(node)
|
60
|
+
node.loc.selector
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
7
|
+
# `size` property for `file` resource is deprecated for `size_kb` and will be removed in InSpec5
|
8
|
+
#
|
9
|
+
# # bad
|
10
|
+
# describe file('my_file.txt') do
|
11
|
+
# its('size') { should eq 12345 }
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# describe file('my_file.txt') do
|
16
|
+
# its('size_kb') { should eq 12345 }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
class FileSize < Cop
|
20
|
+
include RangeHelp
|
21
|
+
|
22
|
+
MSG = '`size` property for `file` resource is deprecated for `size_kb` and will be removed in InSpec5'
|
23
|
+
|
24
|
+
def_node_matcher :file_resource_size_property?, <<~PATTERN
|
25
|
+
(block
|
26
|
+
(send _ :its
|
27
|
+
(str "size") ...)
|
28
|
+
...)
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def_node_matcher :spec?, <<-PATTERN
|
32
|
+
(block
|
33
|
+
(send nil? :describe ...)
|
34
|
+
...)
|
35
|
+
PATTERN
|
36
|
+
|
37
|
+
def_node_matcher :file_resource?, <<-PATTERN
|
38
|
+
(block
|
39
|
+
(send nil? :describe
|
40
|
+
(send nil? :file ...)
|
41
|
+
...)
|
42
|
+
...)
|
43
|
+
PATTERN
|
44
|
+
|
45
|
+
|
46
|
+
def on_block(node)
|
47
|
+
return unless inside_file_spec?(node)
|
48
|
+
node.descendants.each do |descendant|
|
49
|
+
next unless file_resource_size_property?(descendant)
|
50
|
+
add_offense(descendant, location: offense_range(descendant))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def autocorrect(node)
|
55
|
+
lambda do |corrector|
|
56
|
+
corrector.replace(offense_range(node), preferred_replacement)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def inside_file_spec?(root)
|
63
|
+
spec?(root) && file_resource?(root)
|
64
|
+
end
|
65
|
+
|
66
|
+
def preferred_replacement
|
67
|
+
cop_config.fetch('PreferredReplacement')
|
68
|
+
end
|
69
|
+
|
70
|
+
def offense_range(node)
|
71
|
+
source = node.children[0].children[-1].loc.expression
|
72
|
+
range_between(source.begin_pos+1, source.end_pos-1)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
7
|
+
# `proto` property for `host` resource is deprecated for `protocol` and will be removed in InSpec5
|
8
|
+
#
|
9
|
+
# # bad
|
10
|
+
# describe host('my_host.txt') do
|
11
|
+
# its('proto') { should eq 12345 }
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# # good
|
15
|
+
# describe host('my_host.txt') do
|
16
|
+
# its('protocol') { should eq 12345 }
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
class HostProto < Cop
|
20
|
+
include RangeHelp
|
21
|
+
|
22
|
+
MSG = '`proto` property for `host` resource is deprecated for `protocol` and will be removed in InSpec5'
|
23
|
+
|
24
|
+
def_node_matcher :host_resource_proto_property?, <<~PATTERN
|
25
|
+
(block
|
26
|
+
(send _ :its
|
27
|
+
(str "proto") ...)
|
28
|
+
...)
|
29
|
+
PATTERN
|
30
|
+
|
31
|
+
def_node_matcher :host_resource?, <<-PATTERN
|
32
|
+
(block
|
33
|
+
(send nil? :describe
|
34
|
+
(send nil? :host ...)
|
35
|
+
...)
|
36
|
+
...)
|
37
|
+
PATTERN
|
38
|
+
|
39
|
+
|
40
|
+
def on_block(node)
|
41
|
+
return unless inside_resource_spec?(node)
|
42
|
+
node.descendants.each do |descendant|
|
43
|
+
next unless host_resource_proto_property?(descendant)
|
44
|
+
add_offense(descendant, location: offense_range(descendant))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def autocorrect(node)
|
49
|
+
lambda do |corrector|
|
50
|
+
corrector.replace(offense_range(node), preferred_replacement)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def inside_resource_spec?(root)
|
57
|
+
host_resource?(root)
|
58
|
+
end
|
59
|
+
|
60
|
+
def preferred_replacement
|
61
|
+
cop_config.fetch('PreferredReplacement')
|
62
|
+
end
|
63
|
+
|
64
|
+
def offense_range(node)
|
65
|
+
source = node.children[0].children[-1].loc.expression
|
66
|
+
range_between(source.begin_pos+1, source.end_pos-1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
7
|
+
# # iis_website has been deprecated as a resource. Use iis_site instead
|
8
|
+
#
|
9
|
+
class IisWebsite < Cop
|
10
|
+
MSG = 'Use `iis_site` instead of `iis_website`. '\
|
11
|
+
'This resource will be removed in InSpec 5.'
|
12
|
+
|
13
|
+
def_node_matcher :iis_website?, <<~PATTERN
|
14
|
+
(send _ :iis_website ...)
|
15
|
+
PATTERN
|
16
|
+
|
17
|
+
def on_send(node)
|
18
|
+
return unless iis_website?(node)
|
19
|
+
add_offense(node, location: :selector)
|
20
|
+
end
|
21
|
+
|
22
|
+
def autocorrect(node)
|
23
|
+
lambda do |corrector|
|
24
|
+
corrector.replace(node.loc.selector, preferred_replacement)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def preferred_replacement
|
31
|
+
cop_config.fetch('PreferredReplacement')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|