Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new ChefRedundantCode and ChefSharing cop groups #428

Merged
merged 3 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 98 additions & 77 deletions config/cookstyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,6 @@ ChefCorrectness/TmpPath:
Exclude:
- '**/metadata.rb'

ChefCorrectness/InsecureCookbookURL:
Description: Insecure http Github or Gitlab URLs for metadata source_url/issues_url fields
Enabled: true
VersionAdded: '5.1.0'
Include:
- '**/metadata.rb'

ChefCorrectness/NamePropertyIsRequired:
Description: Resource properties marked as name properties should not also be required properties
Enabled: true
VersionAdded: '5.1.0'

ChefCorrectness/InvalidLicenseString:
Description: Cookbook metadata.rb does not use a SPDX compliant license string or "all rights reserved"
Enabled: true
VersionAdded: '5.2.0'
Include:
- '**/metadata.rb'

ChefCorrectness/InvalidPlatformMetadata:
Description: metadata.rb "supports" platform is invalid
Enabled: true
Expand All @@ -148,29 +129,6 @@ ChefCorrectness/CookbookUsesNodeSave:
Exclude:
- '**/metadata.rb'

ChefCorrectness/DefaultMetadataMaintainer:
Description: Metadata contains default maintainer information from the cookbook generator. Add actual cookbook maintainer information to the metadata.rb.
Enabled: true
VersionAdded: '5.4.0'
Include:
- '**/metadata.rb'

ChefCorrectness/PropertyWithNameAttribute:
Description: Resource property sets name_attribute not name_property
Enabled: true
VersionAdded: '5.1.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

ChefCorrectness/PropertyWithRequiredAndDefault:
Description: Resource property should not be both required and have a default value
Enabled: true
VersionAdded: '5.1.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

ChefCorrectness/CookbooksDependsOnSelf:
Description: A cookbook cannot depend on itself
Enabled: true
Expand Down Expand Up @@ -213,28 +171,6 @@ ChefCorrectness/ResourceWithNoneAction:
Exclude:
- '**/metadata.rb'

ChefCorrectness/IncludingOhaiDefaultRecipe:
Description: Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely.
Enabled: true
VersionAdded: '5.4.0'
Exclude:
- '**/metadata.rb'

ChefCorrectness/UnnecessaryNameProperty:
Description: There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources by default.
Enabled: true
VersionAdded: '5.8.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

ChefCorrectness/EmptyMetadataField:
Description: metadata.rb should not include fields with an empty string. Either don't include the field or add a value.
Enabled: true
VersionAdded: '5.8.0'
Include:
- '**/metadata.rb'

ChefCorrectness/InvalidVersionMetadata:
Description: Cookbook metadata.rb version field should follow X.Y.Z version format.
Enabled: true
Expand All @@ -256,14 +192,41 @@ ChefCorrectness/IncorrectLibraryInjection:
Include:
- '**/libraries/*.rb'

ChefCorrectness/ResourceWithNothingAction:
Description: There is no need to define a :nothing action in your resource as Chef Infra Client provides the :nothing action by default for every resource.
###############################
# ChefSharing: Issues that prevent sharing code with other teams or with the Chef community in general
###############################

ChefSharing/InsecureCookbookURL:
Description: Insecure http Github or Gitlab URLs for metadata source_url/issues_url fields
Enabled: true
VersionAdded: '5.12.0'
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/libraries/*.rb'
- '**/resources/*.rb'
- '**/providers/*.rb'
- '**/metadata.rb'

ChefSharing/InvalidLicenseString:
Description: Cookbook metadata.rb does not use a SPDX compliant license string or "all rights reserved"
Enabled: true
VersionAdded: '5.2.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefSharing/DefaultMetadataMaintainer:
Description: Metadata contains default maintainer information from the cookbook generator. Add actual cookbook maintainer information to the metadata.rb.
Enabled: true
VersionAdded: '5.4.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefSharing/EmptyMetadataField:
Description: metadata.rb should not include fields with an empty string. Either don't include the field or add a value.
Enabled: true
VersionAdded: '5.8.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

###############################
# ChefDeprecations: Resolving Deprecations that block upgrading Chef Infra Client
Expand Down Expand Up @@ -895,62 +858,120 @@ ChefModernize/ChefGemNokogiri:
- '**/metadata.rb'
- '**/attributes/*.rb'

ChefModernize/ConflictsMetadata:
ChefModernize/PropertyWithNameAttribute:
Description: Resource property sets name_attribute not name_property
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

ChefModernize/IncludingOhaiDefaultRecipe:
Description: Use the ohai_plugin resource to ship custom Ohai plugins instead of using the ohai::default recipe. If you're not shipping custom Ohai plugins, then you can remove this recipe entirely.
Enabled: true
VersionAdded: '5.4.0'
VersionChanged: '5.15.0'
Exclude:
- '**/metadata.rb'

###############################
# ChefRedundantCode: Cleanup unncessary code in your cookbooks regardless of chef-client release
###############################

ChefRedundantCode/ConflictsMetadata:
Description: Don't use the deprecated 'conflicts' metadata value
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefModernize/SuggestsMetadata:
ChefRedundantCode/SuggestsMetadata:
Description: Don't use the deprecated 'suggests' metadata value
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefModernize/ProvidesMetadata:
ChefRedundantCode/ProvidesMetadata:
Description: Don't use the deprecated 'provides' metadata value
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefModernize/ReplacesMetadata:
ChefRedundantCode/ReplacesMetadata:
Description: Don't use the deprecated 'replaces' metadata value
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefModernize/AttributeMetadata:
ChefRedundantCode/AttributeMetadata:
Description: Don't use the deprecated 'attribute' metadata value
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefModernize/LongDescriptionMetadata:
ChefRedundantCode/LongDescriptionMetadata:
Description: The long_description metadata.rb method is not used and is unnecessary in cookbooks
Enabled: true
VersionAdded: '5.2.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefModernize/RecipeMetadata:
ChefRedundantCode/RecipeMetadata:
Description: The recipe metadata.rb method is not used and is unnecessary in cookbooks. Recipes should be documented in the README.md file instead.
Enabled: true
VersionAdded: '5.6.0'
VersionChanged: '5.15.0'
Include:
- '**/metadata.rb'

ChefRedundantCode/ResourceWithNothingAction:
Description: There is no need to define a :nothing action in your resource as Chef Infra Client provides the :nothing action by default for every resource.
Enabled: true
VersionAdded: '5.12.0'
VersionChanged: '5.15.0'
Include:
- '**/libraries/*.rb'
- '**/resources/*.rb'
- '**/providers/*.rb'

ChefRedundantCode/UnnecessaryNameProperty:
Description: There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources by default.
Enabled: true
VersionAdded: '5.8.0'
VersionChanged: '5.15.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

ChefRedundantCode/PropertyWithRequiredAndDefault:
Description: Resource property should not be both required and have a default value
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

ChefRedundantCode/NamePropertyIsRequired:
Description: Resource properties marked as name properties should not also be required properties
Enabled: true
VersionAdded: '5.1.0'
VersionChanged: '5.15.0'
Include:
- '**/resources/*.rb'
- '**/libraries/*.rb'

###############################
# Migrating to new patterns
###############################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module RuboCop
module Cop
module Chef
module ChefCorrectness
module ChefModernize
# The Ohai default recipe previously allowed a user to ship custom Ohai plugins to a system by including them
# in a directory in the Ohai cookbook. This functionality was replaced with the ohai_plugin resource, which
# should be used instead as it doesn't require forking the ohai cookbook.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
module RuboCop
module Cop
module Chef
module ChefCorrectness
# When using properties in a custom resource you should use name_property not
# the legacy name_attribute from the days of attributes
module ChefModernize
# When using properties in a custom resource you should use name_property not the legacy name_attribute from the days of attributes
#
# @example
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ module RuboCop
module Cop
module Chef
module ChefModernize
# Chef Infra Client includes mixlib/shellout automatically in resources and providers.
# Chef Infra Client 12.4+ includes mixlib/shellout automatically in resources and providers.
#
# @example
#
# # bad
# require 'mixlib/shellout'
#
class UnnecessaryMixlibShelloutRequire < Cop
MSG = 'Chef Infra Client includes mixlib/shellout automatically in resources and providers.'.freeze
MSG = 'Chef Infra Client 12.4+ includes mixlib/shellout automatically in resources and providers.'.freeze

def_node_matcher :require_mixlibshellout?, <<-PATTERN
(send nil? :require ( str "mixlib/shellout"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The attribute metadata.rb method is not used and is unnecessary in cookbooks.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The conflicts metadata.rb method is not used and is unnecessary in cookbooks.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The long_description metadata.rb method is not used and is unnecessary in cookbooks.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module RuboCop
module Cop
module Chef
module ChefCorrectness
module ChefRedundantCode
# When using properties in a custom resource you shouldn't set a property to
# be both required and a name_property. Name properties are a way to optionally
# override the name given to the resource block in cookbook code. In your resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module RuboCop
module Cop
module Chef
module ChefCorrectness
module ChefRedundantCode
# When using properties in a custom resource you shouldn't set a property to
# required and then provide a default value. If a property is required the
# user will always pass in a value and the default will never be used. In Chef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The provides metadata.rb method is not used and is unnecessary in cookbooks.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The recipe metadata.rb method is not used and is unnecessary in cookbooks. Recipes should be documented in the cookbook's README.md file instead.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The replaces metadata.rb method is not used and is unnecessary in cookbooks. Replacements for existing cookbooks should be documented in the cookbook's README.md file instead.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module RuboCop
module Cop
module Chef
module ChefCorrectness
module ChefRedundantCode
# Chef Infra Client provides the :nothing action by default for every resource. There is no need to define a :nothing action in your resource code.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module RuboCop
module Cop
module Chef
module ChefModernize
module ChefRedundantCode
# The suggests metadata.rb method is not used and is unnecessary in cookbooks.
#
# @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module RuboCop
module Cop
module Chef
module ChefCorrectness
module ChefRedundantCode
# There is no need to define a property named :name in a resource as Chef Infra defines that property for all resources by default.
#
# @example
Expand Down
Loading