inspecstyle 0.1.3 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +37 -0
- data/config/default.yml +95 -2
- data/doc/RuboCop.html +3 -3
- data/doc/RuboCop/Cop.html +3 -3
- data/doc/RuboCop/Cop/InSpecStyle.html +4 -4
- data/doc/RuboCop/Cop/InSpecStyle/Apache.html +306 -0
- data/doc/RuboCop/Cop/InSpecStyle/AwsIamUserProperty.html +358 -0
- data/doc/RuboCop/Cop/InSpecStyle/AzureGenericResource.html +6 -5
- data/doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes.html +3 -2
- data/doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes1.html +311 -0
- data/doc/RuboCop/Cop/InSpecStyle/FileBeMounted.html +250 -0
- data/doc/RuboCop/Cop/InSpecStyle/FileSize.html +315 -0
- data/doc/RuboCop/Cop/InSpecStyle/HostProto.html +315 -0
- data/doc/RuboCop/Cop/InSpecStyle/IisWebsite.html +294 -0
- data/doc/RuboCop/Cop/InSpecStyle/LinuxKernelParameter.html +296 -0
- data/doc/RuboCop/Cop/InSpecStyle/MSSQLSessionPass.html +319 -0
- data/doc/RuboCop/Cop/InSpecStyle/OracleDbSessionPass.html +319 -0
- data/doc/RuboCop/Cop/InSpecStyle/PPAResource.html +294 -0
- data/doc/RuboCop/Cop/InSpecStyle/ProcessesList.html +315 -0
- data/doc/RuboCop/Cop/InSpecStyle/ScriptResource.html +298 -0
- data/doc/RuboCop/Cop/InSpecStyle/ShadowProperties.html +334 -0
- data/doc/RuboCop/Cop/InSpecStyle/UsersResourceMatchers.html +357 -0
- data/doc/RuboCop/Cop/InSpecStyle/WindowsRegistryKey.html +294 -0
- data/doc/RuboCop/Cop/InSpecStyle/WmiWmisClass.html +294 -0
- data/doc/RuboCop/InSpecStyle.html +2 -2
- data/doc/RuboCop/InSpecStyle/Error.html +1 -1
- data/doc/RuboCop/InSpecStyle/Inject.html +1 -1
- data/doc/_index.html +181 -2
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +24 -2
- data/doc/index.html +24 -2
- data/doc/method_list.html +254 -6
- data/doc/top-level-namespace.html +1 -1
- 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 +2 -1
- data/lib/rubocop/cop/inspecstyle/deprecated_attributes.rb +2 -2
- data/lib/rubocop/cop/inspecstyle/deprecated_attributes1.rb +52 -0
- 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 +18 -2
- data/lib/rubocop/inspecstyle/version.rb +1 -1
- data/notes-for-development.md +10 -0
- metadata +36 -3
- data/lib/rubocop/cop/inspecstyle/first_cop.rb +0 -69
@@ -100,7 +100,7 @@
|
|
100
100
|
</div>
|
101
101
|
|
102
102
|
<div id="footer">
|
103
|
-
Generated on Thu
|
103
|
+
Generated on Thu Jul 2 15:33:00 2020 by
|
104
104
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
105
105
|
0.9.25 (ruby-2.6.6).
|
106
106
|
</div>
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# Do not use apache
|
7
|
+
#
|
8
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
9
|
+
# # apache 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
|
+
# apache
|
15
|
+
#
|
16
|
+
# # good
|
17
|
+
# azurerm_virtual_machine # use a specific resource pack resource
|
18
|
+
#
|
19
|
+
class Apache < Cop
|
20
|
+
MSG = 'Use a `apache_conf` instead of `#apache`. '\
|
21
|
+
'This resource will be removed in InSpec 5.'
|
22
|
+
|
23
|
+
def_node_matcher :spec?, <<-PATTERN
|
24
|
+
(block
|
25
|
+
(send nil? :describe ...)
|
26
|
+
...)
|
27
|
+
PATTERN
|
28
|
+
|
29
|
+
def_node_matcher :apache?, <<~PATTERN
|
30
|
+
(send nil? :apache ...)
|
31
|
+
PATTERN
|
32
|
+
|
33
|
+
def on_send(node)
|
34
|
+
return unless apache?(node)
|
35
|
+
|
36
|
+
add_offense(node, location: :selector)
|
37
|
+
end
|
38
|
+
|
39
|
+
def autocorrect(node)
|
40
|
+
lambda do |corrector|
|
41
|
+
corrector.replace(node.loc.selector, preferred_replacement)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def inside_spec?(root)
|
48
|
+
spec?(root)
|
49
|
+
end
|
50
|
+
|
51
|
+
def preferred_replacement
|
52
|
+
cop_config.fetch('PreferredReplacement')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -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
|
@@ -8,6 +8,7 @@ module RuboCop
|
|
8
8
|
# @example EnforcedStyle: InSpecStyle (default)
|
9
9
|
# # azure_generic_resource has been deprecated
|
10
10
|
# # 'https://github.com/inspec/inspec/issues/3131'
|
11
|
+
# # Since there are multiples replacements autocorrect is not supported.
|
11
12
|
#
|
12
13
|
# # bad
|
13
14
|
# azure_generic_resource
|
@@ -26,7 +27,7 @@ module RuboCop
|
|
26
27
|
def on_send(node)
|
27
28
|
return unless azure_generic_resource?(node)
|
28
29
|
|
29
|
-
add_offense(node, location:
|
30
|
+
add_offense(node, location: :selector)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
@@ -1,6 +1,5 @@
|
|
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
|
@@ -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 ...)
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RuboCop
|
4
|
+
module Cop
|
5
|
+
module InSpecStyle
|
6
|
+
# Checks if deprecated method attribute1 is used.
|
7
|
+
#
|
8
|
+
# @example EnforcedStyle: InSpecStyle (default)
|
9
|
+
# # Attributes have been deprecated for inputs
|
10
|
+
# # https://github.com/inspec/inspec/issues/3802
|
11
|
+
#
|
12
|
+
# # bad
|
13
|
+
# attribute1('my_element', value: 10)
|
14
|
+
#
|
15
|
+
# # good
|
16
|
+
# input('my_element', value: 10)
|
17
|
+
#
|
18
|
+
class DeprecatedAttributes1 < Cop
|
19
|
+
include RangeHelp
|
20
|
+
|
21
|
+
MSG = 'Use `#input` instead of `#attribute1`. This will be removed in '\
|
22
|
+
'InSpec 5'
|
23
|
+
|
24
|
+
def_node_matcher :attribute1?, <<~PATTERN
|
25
|
+
(send nil? :attribute1 ...)
|
26
|
+
PATTERN
|
27
|
+
|
28
|
+
def on_send(node)
|
29
|
+
return unless attribute1?(node)
|
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
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def offense_range(node)
|
43
|
+
node.loc.selector
|
44
|
+
end
|
45
|
+
|
46
|
+
def preferred_replacement
|
47
|
+
cop_config.fetch('PreferredReplacement')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
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
|