inspecstyle 0.1.3 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/README.md +37 -0
  4. data/config/default.yml +95 -2
  5. data/doc/RuboCop.html +3 -3
  6. data/doc/RuboCop/Cop.html +3 -3
  7. data/doc/RuboCop/Cop/InSpecStyle.html +4 -4
  8. data/doc/RuboCop/Cop/InSpecStyle/Apache.html +306 -0
  9. data/doc/RuboCop/Cop/InSpecStyle/AwsIamUserProperty.html +358 -0
  10. data/doc/RuboCop/Cop/InSpecStyle/AzureGenericResource.html +6 -5
  11. data/doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes.html +3 -2
  12. data/doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes1.html +311 -0
  13. data/doc/RuboCop/Cop/InSpecStyle/FileBeMounted.html +250 -0
  14. data/doc/RuboCop/Cop/InSpecStyle/FileSize.html +315 -0
  15. data/doc/RuboCop/Cop/InSpecStyle/HostProto.html +315 -0
  16. data/doc/RuboCop/Cop/InSpecStyle/IisWebsite.html +294 -0
  17. data/doc/RuboCop/Cop/InSpecStyle/LinuxKernelParameter.html +296 -0
  18. data/doc/RuboCop/Cop/InSpecStyle/MSSQLSessionPass.html +319 -0
  19. data/doc/RuboCop/Cop/InSpecStyle/OracleDbSessionPass.html +319 -0
  20. data/doc/RuboCop/Cop/InSpecStyle/PPAResource.html +294 -0
  21. data/doc/RuboCop/Cop/InSpecStyle/ProcessesList.html +315 -0
  22. data/doc/RuboCop/Cop/InSpecStyle/ScriptResource.html +298 -0
  23. data/doc/RuboCop/Cop/InSpecStyle/ShadowProperties.html +334 -0
  24. data/doc/RuboCop/Cop/InSpecStyle/UsersResourceMatchers.html +357 -0
  25. data/doc/RuboCop/Cop/InSpecStyle/WindowsRegistryKey.html +294 -0
  26. data/doc/RuboCop/Cop/InSpecStyle/WmiWmisClass.html +294 -0
  27. data/doc/RuboCop/InSpecStyle.html +2 -2
  28. data/doc/RuboCop/InSpecStyle/Error.html +1 -1
  29. data/doc/RuboCop/InSpecStyle/Inject.html +1 -1
  30. data/doc/_index.html +181 -2
  31. data/doc/class_list.html +1 -1
  32. data/doc/file.README.html +24 -2
  33. data/doc/index.html +24 -2
  34. data/doc/method_list.html +254 -6
  35. data/doc/top-level-namespace.html +1 -1
  36. data/lib/rubocop/cop/inspecstyle/apache.rb +57 -0
  37. data/lib/rubocop/cop/inspecstyle/aws_iam_user_property.rb +96 -0
  38. data/lib/rubocop/cop/inspecstyle/azure_generic_resource.rb +2 -1
  39. data/lib/rubocop/cop/inspecstyle/deprecated_attributes.rb +2 -2
  40. data/lib/rubocop/cop/inspecstyle/deprecated_attributes1.rb +52 -0
  41. data/lib/rubocop/cop/inspecstyle/file_be_mounted.rb +65 -0
  42. data/lib/rubocop/cop/inspecstyle/file_size.rb +77 -0
  43. data/lib/rubocop/cop/inspecstyle/host_proto.rb +71 -0
  44. data/lib/rubocop/cop/inspecstyle/iis_website.rb +36 -0
  45. data/lib/rubocop/cop/inspecstyle/linux_kernel_parameter.rb +41 -0
  46. data/lib/rubocop/cop/inspecstyle/mssql_session_pass.rb +59 -0
  47. data/lib/rubocop/cop/inspecstyle/oracle_db_session_pass.rb +59 -0
  48. data/lib/rubocop/cop/inspecstyle/ppa_resource.rb +36 -0
  49. data/lib/rubocop/cop/inspecstyle/processes_list.rb +77 -0
  50. data/lib/rubocop/cop/inspecstyle/script_resource.rb +48 -0
  51. data/lib/rubocop/cop/inspecstyle/shadow_properties.rb +83 -0
  52. data/lib/rubocop/cop/inspecstyle/users_resource_matchers.rb +98 -0
  53. data/lib/rubocop/cop/inspecstyle/windows_registry_key.rb +36 -0
  54. data/lib/rubocop/cop/inspecstyle/wmi_wmis_class.rb +37 -0
  55. data/lib/rubocop/cop/inspecstyle_cops.rb +18 -2
  56. data/lib/rubocop/inspecstyle/version.rb +1 -1
  57. data/notes-for-development.md +10 -0
  58. metadata +36 -3
  59. data/lib/rubocop/cop/inspecstyle/first_cop.rb +0 -69
@@ -0,0 +1,98 @@
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
+ # Users resource deprecated matchers
11
+ #
12
+ # @example EnforcedStyle: InSpecStyle (default)
13
+ #
14
+ # # bad
15
+ # describe users('/etc/my-custom-place/users') do
16
+ # its('has_home_directory?') { should eq 'foo' }
17
+ # end
18
+ #
19
+ # # good
20
+ # describe users('/etc/my-custom-place/users') do
21
+ # its('users') { should eq 'foo' }
22
+ # end
23
+ #
24
+ class UsersResourceMatchers < Cop
25
+ MSG = 'Use `%<solution>s` instead of `%<violation>s` as a matcher ' \
26
+ "for the `users` resource. \nThis matcher will be removed in InSpec 5"
27
+
28
+ MAP = {
29
+ has_home_directory?: "its('home')",
30
+ has_login_shell?: "its('shell')",
31
+ has_authorized_key?: "another matcher",
32
+ maximum_days_between_password_change: :maxdays,
33
+ has_uid?: "another matcher",
34
+ minimum_days_between_password_change: "mindays"
35
+ }
36
+
37
+ def_node_matcher :deprecated_users_matcher?, <<~PATTERN
38
+ (send _ ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
39
+ PATTERN
40
+
41
+ def_node_matcher :spec?, <<-PATTERN
42
+ (block
43
+ (send nil? :describe ...)
44
+ ...)
45
+ PATTERN
46
+
47
+ def_node_matcher :users_resource?, <<-PATTERN
48
+ (block
49
+ (send nil? :describe
50
+ (send nil? :users ...)
51
+ ...)
52
+ ...)
53
+ PATTERN
54
+
55
+ def on_block(node)
56
+ return unless inside_users_spec?(node)
57
+ node.descendants.each do |descendant|
58
+ deprecated_users_matcher?(descendant) do |violation|
59
+ add_offense(
60
+ descendant,
61
+ location: offense_range(descendant),
62
+ message: format(
63
+ MSG,
64
+ violation: violation,
65
+ solution: MAP[violation]
66
+ )
67
+ )
68
+ end
69
+ end
70
+ end
71
+
72
+ def autocorrect(node)
73
+ lambda do |corrector|
74
+ # Only these two matchers are autocorrectable
75
+ [
76
+ 'maximum_days_between_password_change',
77
+ 'minimum_days_between_password_change'
78
+ ].map do |violation|
79
+ if node.inspect.include?(violation)
80
+ corrector.replace(node.loc.selector, MAP[violation.to_sym])
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ private
87
+
88
+ def inside_users_spec?(root)
89
+ spec?(root) && users_resource?(root)
90
+ end
91
+
92
+ def offense_range(node)
93
+ node.loc.selector
94
+ end
95
+ end
96
+ end
97
+ end
98
+ 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
+ # # windows_registry_key has been deprecated as a resource. Use registry_key instead
8
+ #
9
+ class WindowsRegistryKey < Cop
10
+ MSG = 'Use `registry_key` instead of `windows_registry_key`. '\
11
+ 'This resource will be removed in InSpec 5.'
12
+
13
+ def_node_matcher :windows_registry_key?, <<~PATTERN
14
+ (send _ :windows_registry_key ...)
15
+ PATTERN
16
+
17
+ def on_send(node)
18
+ return unless windows_registry_key?(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
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module InSpecStyle
6
+ # @example EnforcedStyle: InSpecStyle (default)
7
+ # # wmi_wmis_class has been deprecated as a resource. Use iis_site instead
8
+ #
9
+ class WmiWmisClass < Cop
10
+ MSG = 'Use `iis_site` instead of `wmi_wmis_class`. '\
11
+ 'This resource will be removed in InSpec 5.'
12
+
13
+ def_node_matcher :wmi_wmis_class?, <<~PATTERN
14
+ (send _ :wmi
15
+ (str "wmisclass") ...)
16
+ PATTERN
17
+
18
+ def on_send(node)
19
+ return unless wmi_wmis_class?(node)
20
+ add_offense(node)
21
+ end
22
+
23
+ def autocorrect(node)
24
+ lambda do |corrector|
25
+ corrector.replace(node.source_range, preferred_replacement)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def preferred_replacement
32
+ cop_config.fetch('PreferredReplacement')
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,4 +1,20 @@
1
1
  # frozen_string_literal: true
2
- require_relative 'inspecstyle/first_cop'
3
- require_relative 'inspecstyle/deprecated_attributes'
4
2
  require_relative 'inspecstyle/azure_generic_resource'
3
+ require_relative 'inspecstyle/shadow_properties'
4
+ require_relative 'inspecstyle/oracle_db_session_pass'
5
+ require_relative 'inspecstyle/file_size'
6
+ require_relative 'inspecstyle/apache'
7
+ require_relative 'inspecstyle/script_resource'
8
+ require_relative 'inspecstyle/users_resource_matchers'
9
+ require_relative 'inspecstyle/iis_website'
10
+ require_relative 'inspecstyle/host_proto'
11
+ require_relative 'inspecstyle/linux_kernel_parameter'
12
+ require_relative 'inspecstyle/mssql_session_pass'
13
+ require_relative 'inspecstyle/ppa_resource'
14
+ require_relative 'inspecstyle/processes_list'
15
+ require_relative 'inspecstyle/windows_registry_key'
16
+ require_relative 'inspecstyle/aws_iam_user_property'
17
+ require_relative 'inspecstyle/file_be_mounted'
18
+ require_relative 'inspecstyle/wmi_wmis_class'
19
+ require_relative 'inspecstyle/deprecated_attributes1'
20
+ require_relative 'inspecstyle/deprecated_attributes'
@@ -1,5 +1,5 @@
1
1
  module RuboCop
2
2
  module InSpecStyle
3
- VERSION = "0.1.3"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
@@ -42,4 +42,14 @@ node = source.ast
42
42
  node.type
43
43
  node.children
44
44
  node.source
45
+ NodePattern.new('(send ...)').match(node) # => true
45
46
  ```
47
+
48
+ - Implement CI
49
+
50
+ Correction docs at rubocop's: lib/rubocop/cop/corrector.rb
51
+
52
+ ### Great Repos for cop examples
53
+ - rubocop-ast
54
+ - rubocop-rspec
55
+ - rubocop
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspecstyle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Schwaderer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-11 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -49,9 +49,26 @@ files:
49
49
  - doc/RuboCop.html
50
50
  - doc/RuboCop/Cop.html
51
51
  - doc/RuboCop/Cop/InSpecStyle.html
52
+ - doc/RuboCop/Cop/InSpecStyle/Apache.html
53
+ - doc/RuboCop/Cop/InSpecStyle/AwsIamUserProperty.html
52
54
  - doc/RuboCop/Cop/InSpecStyle/AzureGenericResource.html
53
55
  - doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes.html
56
+ - doc/RuboCop/Cop/InSpecStyle/DeprecatedAttributes1.html
57
+ - doc/RuboCop/Cop/InSpecStyle/FileBeMounted.html
58
+ - doc/RuboCop/Cop/InSpecStyle/FileSize.html
54
59
  - doc/RuboCop/Cop/InSpecStyle/FirstCop.html
60
+ - doc/RuboCop/Cop/InSpecStyle/HostProto.html
61
+ - doc/RuboCop/Cop/InSpecStyle/IisWebsite.html
62
+ - doc/RuboCop/Cop/InSpecStyle/LinuxKernelParameter.html
63
+ - doc/RuboCop/Cop/InSpecStyle/MSSQLSessionPass.html
64
+ - doc/RuboCop/Cop/InSpecStyle/OracleDbSessionPass.html
65
+ - doc/RuboCop/Cop/InSpecStyle/PPAResource.html
66
+ - doc/RuboCop/Cop/InSpecStyle/ProcessesList.html
67
+ - doc/RuboCop/Cop/InSpecStyle/ScriptResource.html
68
+ - doc/RuboCop/Cop/InSpecStyle/ShadowProperties.html
69
+ - doc/RuboCop/Cop/InSpecStyle/UsersResourceMatchers.html
70
+ - doc/RuboCop/Cop/InSpecStyle/WindowsRegistryKey.html
71
+ - doc/RuboCop/Cop/InSpecStyle/WmiWmisClass.html
55
72
  - doc/RuboCop/InSpecStyle.html
56
73
  - doc/RuboCop/InSpecStyle/Error.html
57
74
  - doc/RuboCop/InSpecStyle/Inject.html
@@ -71,9 +88,25 @@ files:
71
88
  - doc/top-level-namespace.html
72
89
  - inspecstyle.gemspec
73
90
  - lib/inspecstyle.rb
91
+ - lib/rubocop/cop/inspecstyle/apache.rb
92
+ - lib/rubocop/cop/inspecstyle/aws_iam_user_property.rb
74
93
  - lib/rubocop/cop/inspecstyle/azure_generic_resource.rb
75
94
  - lib/rubocop/cop/inspecstyle/deprecated_attributes.rb
76
- - lib/rubocop/cop/inspecstyle/first_cop.rb
95
+ - lib/rubocop/cop/inspecstyle/deprecated_attributes1.rb
96
+ - lib/rubocop/cop/inspecstyle/file_be_mounted.rb
97
+ - lib/rubocop/cop/inspecstyle/file_size.rb
98
+ - lib/rubocop/cop/inspecstyle/host_proto.rb
99
+ - lib/rubocop/cop/inspecstyle/iis_website.rb
100
+ - lib/rubocop/cop/inspecstyle/linux_kernel_parameter.rb
101
+ - lib/rubocop/cop/inspecstyle/mssql_session_pass.rb
102
+ - lib/rubocop/cop/inspecstyle/oracle_db_session_pass.rb
103
+ - lib/rubocop/cop/inspecstyle/ppa_resource.rb
104
+ - lib/rubocop/cop/inspecstyle/processes_list.rb
105
+ - lib/rubocop/cop/inspecstyle/script_resource.rb
106
+ - lib/rubocop/cop/inspecstyle/shadow_properties.rb
107
+ - lib/rubocop/cop/inspecstyle/users_resource_matchers.rb
108
+ - lib/rubocop/cop/inspecstyle/windows_registry_key.rb
109
+ - lib/rubocop/cop/inspecstyle/wmi_wmis_class.rb
77
110
  - lib/rubocop/cop/inspecstyle_cops.rb
78
111
  - lib/rubocop/inspecstyle.rb
79
112
  - lib/rubocop/inspecstyle/inject.rb
@@ -1,69 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # TODO: when finished, run `rake generate_cops_documentation` to update the docs
4
- module RuboCop
5
- module Cop
6
- module InSpecStyle
7
- # TODO: Write cop description and example of bad / good code. For every
8
- # `SupportedStyle` and unique configuration, there needs to be examples.
9
- # Examples must have valid Ruby syntax. Do not use upticks.
10
- #
11
- # @example EnforcedStyle: bar (default)
12
- # # Description of the `bar` style.
13
- #
14
- # # bad
15
- # bad_bar_method
16
- #
17
- # # bad
18
- # bad_bar_method(args)
19
- #
20
- # # good
21
- # good_bar_method
22
- #
23
- # # good
24
- # good_bar_method(args)
25
- #
26
- # @example EnforcedStyle: foo
27
- # # Description of the `foo` style.
28
- #
29
- # # bad
30
- # bad_foo_method
31
- #
32
- # # bad
33
- # bad_foo_method(args)
34
- #
35
- # # good
36
- # good_foo_method
37
- #
38
- # # good
39
- # good_foo_method(args)
40
- #
41
- class FirstCop < Cop
42
- # TODO: Implement the cop in here.
43
- #
44
- # In many cases, you can use a node matcher for matching node pattern.
45
- # See https://github.com/rubocop-hq/rubocop/blob/master/lib/rubocop/node_pattern.rb
46
- #
47
- # For example
48
- MSG = 'Use `#good_method` instead of `#bad_method`. %<example_insertion>'
49
-
50
- def_node_matcher :bad_method?, <<~PATTERN
51
- (send nil? :bad_method ...)
52
- PATTERN
53
-
54
- def on_send(node)
55
- return unless bad_method?(node)
56
- message = format(MSG, example_insertion: node.first.source)
57
- add_offense(node, message: message)
58
- end
59
-
60
- def autocorrect(node)
61
- ->(corrector) do
62
- corrector.insert_before(node.source_range, 'good_method')
63
- corrector.remove(node.source_range)
64
- end
65
- end
66
- end
67
- end
68
- end
69
- end