cookstyle 6.18.8 → 6.21.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +5 -1
  3. data/config/cookstyle.yml +39 -0
  4. data/config/disable_all.yml +6 -0
  5. data/config/upstream.yml +44 -3
  6. data/cookstyle.gemspec +1 -1
  7. data/lib/cookstyle.rb +0 -3
  8. data/lib/cookstyle/version.rb +2 -2
  9. data/lib/rubocop/cop/chef/correctness/block_guard_clause_string_only.rb +1 -1
  10. data/lib/rubocop/cop/chef/correctness/chef_application_fatal.rb +2 -1
  11. data/lib/rubocop/cop/chef/correctness/conditional_ruby_shellout.rb +1 -1
  12. data/lib/rubocop/cop/chef/correctness/incorrect_library_injection.rb +19 -37
  13. data/lib/rubocop/cop/chef/correctness/invalid_platform_family_values_in_case.rb +1 -1
  14. data/lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb +2 -2
  15. data/lib/rubocop/cop/chef/correctness/invalid_platform_values_in_case.rb +2 -1
  16. data/lib/rubocop/cop/chef/correctness/invalid_version_metadata.rb +1 -0
  17. data/lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb +1 -1
  18. data/lib/rubocop/cop/chef/correctness/lazy_in_resource_guard.rb +1 -1
  19. data/lib/rubocop/cop/chef/correctness/macos_userdefaults_invalid_type.rb +2 -2
  20. data/lib/rubocop/cop/chef/correctness/node_normal.rb +1 -0
  21. data/lib/rubocop/cop/chef/correctness/node_normal_unless.rb +1 -0
  22. data/lib/rubocop/cop/chef/correctness/node_save.rb +1 -0
  23. data/lib/rubocop/cop/chef/correctness/notifies_action_not_symbol.rb +1 -1
  24. data/lib/rubocop/cop/chef/correctness/octal_mode_as_string.rb +48 -0
  25. data/lib/rubocop/cop/chef/correctness/resource_with_none_action.rb +1 -1
  26. data/lib/rubocop/cop/chef/correctness/scoped_file_exist.rb +1 -1
  27. data/lib/rubocop/cop/chef/correctness/supports_must_be_float.rb +2 -2
  28. data/lib/rubocop/cop/chef/deprecation/chef_handler_supports.rb +1 -1
  29. data/lib/rubocop/cop/chef/deprecation/chef_rewind.rb +2 -2
  30. data/lib/rubocop/cop/chef/deprecation/chef_shellout.rb +2 -2
  31. data/lib/rubocop/cop/chef/deprecation/chef_windows_platform_helper.rb +2 -1
  32. data/lib/rubocop/cop/chef/deprecation/chefdk_generators.rb +1 -1
  33. data/lib/rubocop/cop/chef/deprecation/chefspec_coverage_report.rb +1 -1
  34. data/lib/rubocop/cop/chef/deprecation/chefspec_legacy_runner.rb +1 -1
  35. data/lib/rubocop/cop/chef/deprecation/deprecated_chefspec_platform.rb +1 -3
  36. data/lib/rubocop/cop/chef/deprecation/deprecated_platform_methods.rb +1 -0
  37. data/lib/rubocop/cop/chef/deprecation/deprecated_yum_repository_properties.rb +1 -1
  38. data/lib/rubocop/cop/chef/deprecation/epic_fail.rb +1 -1
  39. data/lib/rubocop/cop/chef/deprecation/execute_path_property.rb +1 -1
  40. data/lib/rubocop/cop/chef/deprecation/execute_relative_creates_without_cwd.rb +1 -1
  41. data/lib/rubocop/cop/chef/deprecation/inherits_compat_resource.rb +1 -1
  42. data/lib/rubocop/cop/chef/deprecation/legacy_notify_syntax.rb +2 -2
  43. data/lib/rubocop/cop/chef/deprecation/node_deep_fetch.rb +2 -0
  44. data/lib/rubocop/cop/chef/deprecation/node_methods_not_attributes.rb +22 -27
  45. data/lib/rubocop/cop/chef/deprecation/node_set.rb +1 -0
  46. data/lib/rubocop/cop/chef/deprecation/node_set_unless.rb +1 -0
  47. data/lib/rubocop/cop/chef/deprecation/node_set_without_level.rb +1 -0
  48. data/lib/rubocop/cop/chef/deprecation/partial_search_class_usage.rb +1 -0
  49. data/lib/rubocop/cop/chef/deprecation/powershell_cookbook_helpers.rb +2 -1
  50. data/lib/rubocop/cop/chef/deprecation/resource_overrides_provides_method.rb +2 -2
  51. data/lib/rubocop/cop/chef/deprecation/ruby_27_keyword_argument_warnings.rb +2 -2
  52. data/lib/rubocop/cop/chef/deprecation/ruby_block_create_action.rb +2 -2
  53. data/lib/rubocop/cop/chef/deprecation/search_uses_positional_parameters.rb +1 -1
  54. data/lib/rubocop/cop/chef/deprecation/use_yaml_dump.rb +47 -0
  55. data/lib/rubocop/cop/chef/deprecation/user_supports_property.rb +1 -1
  56. data/lib/rubocop/cop/chef/deprecation/windows_package_installer_type_string.rb +1 -1
  57. data/lib/rubocop/cop/chef/deprecation/windows_task_change_action.rb +2 -2
  58. data/lib/rubocop/cop/chef/deprecation/windows_version_helpers.rb +5 -4
  59. data/lib/rubocop/cop/chef/deprecation/xml_ruby_recipe.rb +1 -1
  60. data/lib/rubocop/cop/chef/effortless/chef_vault_used.rb +89 -0
  61. data/lib/rubocop/cop/chef/effortless/depends_chef_vault.rb +49 -0
  62. data/lib/rubocop/cop/chef/modernize/action_method_in_resource.rb +2 -2
  63. data/lib/rubocop/cop/chef/modernize/berksfile_source.rb +2 -2
  64. data/lib/rubocop/cop/chef/modernize/build_essential.rb +1 -1
  65. data/lib/rubocop/cop/chef/modernize/compile_time_resources.rb +1 -0
  66. data/lib/rubocop/cop/chef/modernize/conditional_using_test.rb +2 -2
  67. data/lib/rubocop/cop/chef/modernize/cron_manage_resource.rb +1 -1
  68. data/lib/rubocop/cop/chef/modernize/databag_helpers.rb +2 -1
  69. data/lib/rubocop/cop/chef/modernize/foodcritic_comments.rb +1 -1
  70. data/lib/rubocop/cop/chef/modernize/if_provides_default_action.rb +1 -1
  71. data/lib/rubocop/cop/chef/modernize/libarchive_file.rb +2 -2
  72. data/lib/rubocop/cop/chef/modernize/macos_user_defaults.rb +1 -1
  73. data/lib/rubocop/cop/chef/modernize/node_init_package.rb +5 -4
  74. data/lib/rubocop/cop/chef/modernize/node_roles_include.rb +2 -1
  75. data/lib/rubocop/cop/chef/modernize/openssl_rsa_key_resource.rb +1 -1
  76. data/lib/rubocop/cop/chef/modernize/openssl_x509_resource.rb +1 -1
  77. data/lib/rubocop/cop/chef/modernize/osx_config_profile_resource.rb +1 -1
  78. data/lib/rubocop/cop/chef/modernize/property_with_name_attribute.rb +1 -1
  79. data/lib/rubocop/cop/chef/modernize/respond_to_compile_time.rb +1 -1
  80. data/lib/rubocop/cop/chef/modernize/respond_to_metadata.rb +6 -6
  81. data/lib/rubocop/cop/chef/modernize/respond_to_provides.rb +10 -10
  82. data/lib/rubocop/cop/chef/modernize/respond_to_resource_name.rb +2 -2
  83. data/lib/rubocop/cop/chef/modernize/shell_out_helper.rb +2 -1
  84. data/lib/rubocop/cop/chef/modernize/simplify_apt_ppa_setup.rb +1 -1
  85. data/lib/rubocop/cop/chef/modernize/sysctl_param_resource.rb +1 -1
  86. data/lib/rubocop/cop/chef/modernize/use_multipackage_installs.rb +1 -1
  87. data/lib/rubocop/cop/chef/modernize/use_require_relative.rb +1 -1
  88. data/lib/rubocop/cop/chef/modernize/zypper_repo.rb +1 -1
  89. data/lib/rubocop/cop/chef/redundant/double_compile_time.rb +2 -1
  90. data/lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb +1 -1
  91. data/lib/rubocop/cop/chef/redundant/name_property_and_required.rb +1 -0
  92. data/lib/rubocop/cop/chef/redundant/ohai_attribute_to_string.rb +2 -1
  93. data/lib/rubocop/cop/chef/redundant/property_splat_regex.rb +1 -0
  94. data/lib/rubocop/cop/chef/redundant/use_create_if_missing.rb +1 -1
  95. data/lib/rubocop/cop/chef/sharing/include_property_descriptions.rb +1 -1
  96. data/lib/rubocop/cop/chef/sharing/insecure_cookbook_url.rb +1 -1
  97. data/lib/rubocop/cop/chef/sharing/invalid_license_string.rb +1 -1
  98. data/lib/rubocop/cop/chef/style/attribute_keys.rb +2 -1
  99. data/lib/rubocop/cop/chef/style/chef_whaaat.rb +1 -1
  100. data/lib/rubocop/cop/chef/style/comment_sentence_spacing.rb +2 -2
  101. data/lib/rubocop/cop/chef/style/comments_copyright_format.rb +2 -2
  102. data/lib/rubocop/cop/chef/style/comments_default_copyright.rb +1 -1
  103. data/lib/rubocop/cop/chef/style/comments_format.rb +6 -13
  104. data/lib/rubocop/cop/chef/style/file_mode.rb +2 -2
  105. data/lib/rubocop/cop/chef/style/immediate_notification_timing.rb +2 -2
  106. data/lib/rubocop/cop/chef/style/include_recipe_with_parentheses.rb +2 -2
  107. data/lib/rubocop/cop/chef/style/negating_only_if.rb +2 -2
  108. data/lib/rubocop/cop/chef/style/overly_complex_supports_depends_metadata.rb +2 -2
  109. data/lib/rubocop/cop/chef/style/simplify_platform_major_version_check.rb +2 -1
  110. data/lib/rubocop/cop/chef/style/true_false_resource_properties.rb +2 -2
  111. data/lib/rubocop/cop/chef/style/unnecessary_os_check.rb +5 -4
  112. data/lib/rubocop/cop/chef/style/unnecessary_platform_case_statement.rb +2 -2
  113. data/lib/rubocop/cop/chef/style/use_platform_helpers.rb +7 -6
  114. metadata +9 -6
  115. data/lib/rubocop/monkey_patches/rescue_ensure_alignment.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5155a9b35b7783b4f93c60355db6c98114c8f337536cd468738d06481b5e8e7e
4
- data.tar.gz: 0f7d7fae656539861f7bcdd6b4bda8463896eacd3a82c9ba4964b6ad4d35f193
3
+ metadata.gz: e79caedf06c2358db6d9d303270d2245f46e66eb65119f4c8a1181081fb57994
4
+ data.tar.gz: b79613983ad7cdfb9715674680c0ac429490ee79cd843892489e3ced7f5f243d
5
5
  SHA512:
6
- metadata.gz: de5247580b6f6432ac8d0fff694115b8c8765ec012c3f5686fd56453ea7ebb3b943c60025102d0a8531ecb0c605484786d3fa7c500819fd6d188bc8589e11a56
7
- data.tar.gz: 54baddbe1f9419c2387ed4c94d678fdc7d599e903876ed84ccaa9aa99aa7add6443167b003f05a38f7f1b79d574e14507006650152a0bce0ed65d4ba368adf47
6
+ metadata.gz: 2e32c80c8e7b16e49d8cfdc89b0c8adafa122e55ab9aad418c23f0b7becf569c3e725cf58c0853a561916e9522ef42584aa37e78f0e5e906e6e0955e0f0d14ef
7
+ data.tar.gz: b015d7a4c96c353d37589210a88c9e1e13472d0695a38a630b6bbdfa18049d63287529359e199770d20eb67040f1eb9047e2561e32bdab4c3c18ee4cbc5b6b6b
data/Gemfile CHANGED
@@ -17,8 +17,12 @@ group :docs do
17
17
  end
18
18
 
19
19
  group :profiling do
20
- gem 'stackprof'
21
20
  gem 'memory_profiler'
21
+ gem 'stackprof'
22
+ end
23
+
24
+ group :rubocop_gems do
25
+ gem 'rubocop-performance'
22
26
  end
23
27
 
24
28
  group :development do
@@ -469,6 +469,16 @@ ChefCorrectness/PropertyWithoutType:
469
469
  - '**/libraries/*.rb'
470
470
  - '**/resources/*.rb'
471
471
 
472
+ ChefCorrectness/OctalModeAsString:
473
+ Description: Don't represent file modes as strings containing octal values. Use standard base 10 file modes instead.
474
+ StyleGuide: '#chefcorrectnessoctalmodeasstring'
475
+ Enabled: true
476
+ VersionAdded: '6.21.0'
477
+ Exclude:
478
+ - '**/attributes/*.rb'
479
+ - '**/metadata.rb'
480
+ - '**/Berksfile'
481
+
472
482
  ###############################
473
483
  # ChefSharing: Issues that prevent sharing code with other teams or with the Chef community in general
474
484
  ###############################
@@ -1121,6 +1131,12 @@ ChefDeprecations/WindowsPackageInstallerTypeString:
1121
1131
  - '**/attributes/*.rb'
1122
1132
  - '**/Berksfile'
1123
1133
 
1134
+ ChefDeprecations/UseYamlDump:
1135
+ Description: Chef Infra Client 16.5 introduced performance enhancements to Ruby library loading. Due to the underlying implementation of Ruby's `.to_yaml` method, it does not automatically load the `yaml` library and `YAML.dump()` should be used instead to properly load the `yaml` library.
1136
+ StyleGuide: '#chefdeprecationsuseyamldump'
1137
+ Enabled: true
1138
+ VersionAdded: '6.21.0'
1139
+
1124
1140
  ###############################
1125
1141
  # ChefModernize: Cleaning up legacy code and using new built-in resources
1126
1142
  ###############################
@@ -1930,6 +1946,25 @@ ChefEffortless/CookbookUsesDatabags:
1930
1946
  - '**/metadata.rb'
1931
1947
  - '**/Berksfile'
1932
1948
 
1949
+ # https://github.com/chef/cookstyle/issues/346
1950
+ ChefEffortless/ChefVaultUsed:
1951
+ Description: Cookbook uses Chef Vault, which cannot be used in the Effortless Infra pattern
1952
+ StyleGuide: '#chefeffortlesscookbookuseschefvault'
1953
+ Enabled: false
1954
+ VersionAdded: '6.19'
1955
+ Exclude:
1956
+ - '**/metadata.rb'
1957
+ - '**/Berksfile'
1958
+
1959
+ # https://github.com/chef/cookstyle/issues/346
1960
+ ChefEffortless/DependsChefVault:
1961
+ Description: Cookbook depends on Chef Vault, which cannot be used in the Effortless Infra pattern
1962
+ StyleGuide: '#chefeffortlesscookbookdependschefvault'
1963
+ Enabled: false
1964
+ VersionAdded: '6.19'
1965
+ Include:
1966
+ - '**/metadata.rb'
1967
+
1933
1968
  ChefEffortless/CookbookUsesEnvironments:
1934
1969
  Description: Cookbook uses environments, which cannot be used in the Effortless Infra pattern
1935
1970
  StyleGuide: '#chefeffortlesscookbookusesenvironments'
@@ -2708,4 +2743,8 @@ Style/Dir:
2708
2743
 
2709
2744
  # Use __FILE__ or __dir__ to simplify expand_paths
2710
2745
  Style/ExpandPathArguments:
2746
+ Enabled: true
2747
+
2748
+ # Avoid a safe navigation operator if we don't need it
2749
+ Lint/RedundantSafeNavigation:
2711
2750
  Enabled: true
@@ -269,6 +269,8 @@ Lint/FloatOutOfRange:
269
269
  Enabled: false
270
270
  Lint/FormatParameterMismatch:
271
271
  Enabled: false
272
+ Lint/HashCompareByIdentity:
273
+ Enabled: false
272
274
  Lint/HeredocMethodCallPosition:
273
275
  Enabled: false
274
276
  Lint/IdentityComparison:
@@ -327,6 +329,8 @@ Lint/RedundantCopEnableDirective:
327
329
  Enabled: false
328
330
  Lint/RedundantRequireStatement:
329
331
  Enabled: false
332
+ Lint/RedundantSafeNavigation:
333
+ Enabled: false
330
334
  Lint/RedundantSplatExpansion:
331
335
  Enabled: false
332
336
  Lint/RedundantStringCoercion:
@@ -493,6 +497,8 @@ Style/ClassAndModuleChildren:
493
497
  Enabled: false
494
498
  Style/ClassCheck:
495
499
  Enabled: false
500
+ Style/ClassEqualityComparison:
501
+ Enabled: false
496
502
  Style/ClassMethods:
497
503
  Enabled: false
498
504
  Style/ClassMethodsDefinitions:
@@ -1546,6 +1546,13 @@ Lint/FormatParameterMismatch:
1546
1546
  Enabled: true
1547
1547
  VersionAdded: '0.33'
1548
1548
 
1549
+ Lint/HashCompareByIdentity:
1550
+ Description: 'Prefer using `Hash#compare_by_identity` than using `object_id` for keys.'
1551
+ StyleGuide: '#identity-comparison'
1552
+ Enabled: pending
1553
+ Safe: false
1554
+ VersionAdded: '0.93'
1555
+
1549
1556
  Lint/HeredocMethodCallPosition:
1550
1557
  Description: >-
1551
1558
  Checks for the ordering of a method call where
@@ -1746,6 +1753,19 @@ Lint/RedundantRequireStatement:
1746
1753
  Enabled: true
1747
1754
  VersionAdded: '0.76'
1748
1755
 
1756
+ Lint/RedundantSafeNavigation:
1757
+ Description: 'Checks for redundant safe navigation calls.'
1758
+ Enabled: pending
1759
+ VersionAdded: '0.93'
1760
+ AllowedMethods:
1761
+ - instance_of?
1762
+ - kind_of?
1763
+ - is_a?
1764
+ - eql?
1765
+ - respond_to?
1766
+ - equal?
1767
+ Safe: false
1768
+
1749
1769
  Lint/RedundantSplatExpansion:
1750
1770
  Description: 'Checks for splat unnecessarily being called on literals.'
1751
1771
  Enabled: true
@@ -2463,7 +2483,7 @@ Style/ArrayCoercion:
2463
2483
  with a variable you want to treat as an Array, but you're not certain it's an array.
2464
2484
  StyleGuide: '#array-coercion'
2465
2485
  Safe: false
2466
- Enabled: 'pending'
2486
+ Enabled: false
2467
2487
  VersionAdded: '0.88'
2468
2488
 
2469
2489
  Style/ArrayJoin:
@@ -2702,6 +2722,16 @@ Style/ClassCheck:
2702
2722
  - is_a?
2703
2723
  - kind_of?
2704
2724
 
2725
+ Style/ClassEqualityComparison:
2726
+ Description: 'Enforces the use of `Object#instance_of?` instead of class comparison for equality.'
2727
+ StyleGuide: '#instance-of-vs-class-comparison'
2728
+ Enabled: pending
2729
+ VersionAdded: '0.93'
2730
+ IgnoredMethods:
2731
+ - ==
2732
+ - equal?
2733
+ - eql?
2734
+
2705
2735
  Style/ClassMethods:
2706
2736
  Description: 'Use self when defining module/class methods.'
2707
2737
  StyleGuide: '#def-self-class-methods'
@@ -2863,7 +2893,8 @@ Style/DateTime:
2863
2893
  StyleGuide: '#date--time'
2864
2894
  Enabled: false
2865
2895
  VersionAdded: '0.51'
2866
- VersionChanged: '0.59'
2896
+ VersionChanged: '0.92'
2897
+ SafeAutoCorrect: false
2867
2898
  AllowCoercion: false
2868
2899
 
2869
2900
  Style/DefWithParentheses:
@@ -3283,11 +3314,16 @@ Style/IpAddresses:
3283
3314
  Description: "Don't include literal IP addresses in code."
3284
3315
  Enabled: false
3285
3316
  VersionAdded: '0.58'
3286
- VersionChanged: '0.77'
3317
+ VersionChanged: '0.91'
3287
3318
  # Allow addresses to be permitted
3288
3319
  AllowedAddresses:
3289
3320
  - "::"
3290
3321
  # :: is a valid IPv6 address, but could potentially be legitimately in code
3322
+ Exclude:
3323
+ - '**/*.gemfile'
3324
+ - '**/Gemfile'
3325
+ - '**/gems.rb'
3326
+ - '**/*.gemspec'
3291
3327
 
3292
3328
  Style/KeywordParametersOrder:
3293
3329
  Description: 'Enforces that optional keyword parameters are placed at the end of the parameters list.'
@@ -3720,6 +3756,8 @@ Style/OptionalBooleanParameter:
3720
3756
  Enabled: pending
3721
3757
  Safe: false
3722
3758
  VersionAdded: '0.89'
3759
+ AllowedMethods:
3760
+ - respond_to_missing?
3723
3761
 
3724
3762
  Style/OrAssignment:
3725
3763
  Description: 'Recommend usage of double pipe equals (||=) where applicable.'
@@ -3988,6 +4026,8 @@ Style/SafeNavigation:
3988
4026
  This cop transforms usages of a method call safeguarded by
3989
4027
  a check for the existence of the object to
3990
4028
  safe navigation (`&.`).
4029
+ Auto-correction is unsafe as it assumes the object will
4030
+ be `nil` or truthy, but never `false`.
3991
4031
  Enabled: true
3992
4032
  VersionAdded: '0.43'
3993
4033
  VersionChanged: '0.77'
@@ -4000,6 +4040,7 @@ Style/SafeNavigation:
4000
4040
  - presence
4001
4041
  - try
4002
4042
  - try!
4043
+ SafeAutoCorrect: false
4003
4044
 
4004
4045
  Style/Sample:
4005
4046
  Description: >-
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  'homepage_uri' => 'https://github.com/chef/cookstyle',
25
25
  'changelog_uri' => 'https://github.com/chef/cookstyle/blob/master/CHANGELOG.md',
26
26
  'source_code_uri' => 'https://github.com/chef/cookstyle',
27
- 'documentation_uri' => 'https://docs.chef.io/cookstyle.html',
27
+ 'documentation_uri' => 'https://docs.chef.io/workstation/cookstyle/',
28
28
  'bug_tracker_uri' => 'https://github.com/chef/cookstyle/issues',
29
29
  }
30
30
  end
@@ -15,9 +15,6 @@ require_relative 'rubocop/monkey_patches/base'
15
15
  require_relative 'rubocop/monkey_patches/team'
16
16
  require_relative 'rubocop/monkey_patches/registry_cop'
17
17
 
18
- # @TODO remove this monkeypatch after we upgrade from 0.91.0
19
- require_relative 'rubocop/monkey_patches/rescue_ensure_alignment'
20
-
21
18
  module RuboCop
22
19
  class ConfigLoader
23
20
  RUBOCOP_HOME.gsub!(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module Cookstyle
3
- VERSION = "6.18.8" # rubocop: disable Style/StringLiterals
4
- RUBOCOP_VERSION = '0.91.0'
3
+ VERSION = "6.21.1" # rubocop: disable Style/StringLiterals
4
+ RUBOCOP_VERSION = '0.93.1'
5
5
  end
@@ -50,7 +50,7 @@ module RuboCop
50
50
  block_guard_with_only_string?(node) do
51
51
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
52
52
  new_val = "#{node.method_name} #{node.body.source}"
53
- corrector.replace(node.loc.expression, new_val)
53
+ corrector.replace(node, new_val)
54
54
  end
55
55
  end
56
56
  end
@@ -33,6 +33,7 @@ module RuboCop
33
33
  extend AutoCorrector
34
34
 
35
35
  MSG = 'Use raise to force Chef Infra Client to fail instead of using Chef::Application.fatal'
36
+ RESTRICT_ON_SEND = [:fatal!].freeze
36
37
 
37
38
  def_node_matcher :application_fatal?, <<-PATTERN
38
39
  (send
@@ -44,7 +45,7 @@ module RuboCop
44
45
  def on_send(node)
45
46
  application_fatal?(node) do |val|
46
47
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
47
- corrector.replace(node.loc.expression, "raise(#{val.source})")
48
+ corrector.replace(node, "raise(#{val.source})")
48
49
  end
49
50
  end
50
51
  end
@@ -58,7 +58,7 @@ module RuboCop
58
58
  def on_block(node)
59
59
  conditional_shellout?(node) do |type, val|
60
60
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
61
- corrector.replace(node.loc.expression, "#{type} #{val.source}")
61
+ corrector.replace(node, "#{type} #{val.source}")
62
62
  end
63
63
  end
64
64
  end
@@ -37,52 +37,34 @@ module RuboCop
37
37
  extend AutoCorrector
38
38
 
39
39
  MSG = 'Libraries should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes directly.'
40
+ RESTRICT_ON_SEND = [:send, :include].freeze
40
41
 
41
- def_node_search :correct_send?, <<-PATTERN
42
- (send
43
- (const
44
- (const
45
- (const {cbase nil?} :Chef) :DSL) :Recipe) :send
46
- (sym :include)
47
- ... )
42
+ def_node_search :correct_injection?, <<-PATTERN
43
+ {(send
44
+ (const
45
+ (const
46
+ (const {cbase nil?} :Chef) :DSL) :Recipe) :send
47
+ (sym :include)
48
+ ... )
49
+ (send
50
+ (const
51
+ (const
52
+ (const {cbase nil?} :Chef) :DSL) :Recipe) :include
53
+ ... )}
48
54
  PATTERN
49
55
 
50
- def_node_search :correct_include?, <<-PATTERN
51
- (send
52
- (const
53
- (const
54
- (const {cbase nil?} :Chef) :DSL) :Recipe) :include
55
- ... )
56
+ def_node_matcher :legacy_injection?, <<-PATTERN
57
+ {(send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
58
+ (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )}
56
59
  PATTERN
57
60
 
58
- def_node_matcher :legacy_class_sends?, <<-PATTERN
59
- (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :send (sym :include) ... )
60
- PATTERN
61
-
62
- def_node_matcher :legacy_class_include?, <<-PATTERN
63
- (send (const (const {cbase nil?} :Chef) {:Recipe :Provider}) :include ... )
64
- PATTERN
65
-
66
- # @todo: This is highly repetitive and could be simplified into a single node_matcher
67
- # call with some matcher magic that should be figured out
68
61
  def on_send(node)
69
- legacy_class_sends?(node) do
70
- add_offense(node, message: MSG, severity: :refactor) do |corrector|
71
- if node.parent && correct_send?(node.parent)
72
- corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
73
- else
74
- corrector.replace(node.loc.expression,
75
- node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
76
- end
77
- end
78
- end
79
-
80
- legacy_class_include?(node) do
62
+ legacy_injection?(node) do
81
63
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
82
- if node.parent && correct_include?(node.parent)
64
+ if node.parent && correct_injection?(node.parent)
83
65
  corrector.remove(range_with_surrounding_space(range: node.loc.expression, side: :left))
84
66
  else
85
- corrector.replace(node.loc.expression,
67
+ corrector.replace(node,
86
68
  node.source.gsub(/Chef::(Provider|Recipe)/, 'Chef::DSL::Recipe'))
87
69
  end
88
70
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
  range = range_with_surrounding_comma(range_with_surrounding_space(range: con.loc.expression, side: :left), :both)
57
57
  corrector.remove(range)
58
58
  else
59
- corrector.replace(con.loc.expression, "'#{new_value}'")
59
+ corrector.replace(con, "'#{new_value}'")
60
60
  end
61
61
  end
62
62
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
  add_offense(plat, message: MSG, severity: :refactor) do |corrector|
57
57
  correct_string = corrected_platform_source(plat)
58
58
  next unless correct_string
59
- corrector.replace(plat.loc.expression, correct_string)
59
+ corrector.replace(plat, correct_string)
60
60
  end
61
61
  end
62
62
  end
@@ -68,7 +68,7 @@ module RuboCop
68
68
  add_offense(plat, message: MSG, severity: :refactor) do |corrector|
69
69
  correct_string = corrected_platform_source(plat)
70
70
  next unless correct_string
71
- corrector.replace(plat.loc.expression, correct_string)
71
+ corrector.replace(plat, correct_string)
72
72
  end
73
73
  end
74
74
  end
@@ -35,6 +35,7 @@ module RuboCop
35
35
  include ::RuboCop::Chef::PlatformHelpers
36
36
 
37
37
  MSG = 'Use valid platform values in case statements.'
38
+ RESTRICT_ON_SEND = [:[]].freeze
38
39
 
39
40
  def_node_matcher :node_platform?, <<-PATTERN
40
41
  (send (send nil? :node) :[] (str "platform") )
@@ -55,7 +56,7 @@ module RuboCop
55
56
  range = range_with_surrounding_comma(range_with_surrounding_space(range: con.loc.expression, side: :left), :both)
56
57
  corrector.remove(range)
57
58
  else
58
- corrector.replace(con.loc.expression, "'#{new_value}'")
59
+ corrector.replace(con, "'#{new_value}'")
59
60
  end
60
61
  end
61
62
  end
@@ -32,6 +32,7 @@ module RuboCop
32
32
  #
33
33
  class InvalidVersionMetadata < Base
34
34
  MSG = 'Cookbook metadata.rb version field should follow X.Y.Z version format.'
35
+ RESTRICT_ON_SEND = [:version].freeze
35
36
 
36
37
  def_node_matcher :version?, '(send nil? :version $str ...)'
37
38
 
@@ -43,7 +43,7 @@ module RuboCop
43
43
  def on_send(node)
44
44
  non_lazy_node_attribute_default?(node) do |default|
45
45
  add_offense(default, message: MSG, severity: :refactor) do |corrector|
46
- corrector.replace(default.loc.expression, "lazy { #{default.loc.expression.source} }")
46
+ corrector.replace(default, "lazy { #{default.source} }")
47
47
  end
48
48
  end
49
49
  end
@@ -56,7 +56,7 @@ module RuboCop
56
56
  def on_block(node)
57
57
  lazy_in_guard?(node) do |type, code|
58
58
  add_offense(node, message: MSG, severity: :refactor) do |corrector|
59
- corrector.replace(node.loc.expression, "#{type} { #{code.source} }")
59
+ corrector.replace(node, "#{type} { #{code.source} }")
60
60
  end
61
61
  end
62
62
  end
@@ -54,9 +54,9 @@ module RuboCop
54
54
  match_property_in_resource?(:macos_userdefaults, 'type', node) do |type|
55
55
  type_val = method_arg_ast_to_string(type)
56
56
  return if VALID_VALUES.include?(type_val)
57
- add_offense(type.loc.expression, message: MSG, severity: :refactor) do |corrector|
57
+ add_offense(type, message: MSG, severity: :refactor) do |corrector|
58
58
  next unless INVALID_VALUE_MAP[type_val]
59
- corrector.replace(type.loc.expression, "type '#{INVALID_VALUE_MAP[type_val]}'")
59
+ corrector.replace(type, "type '#{INVALID_VALUE_MAP[type_val]}'")
60
60
  end
61
61
  end
62
62
  end