Skip to content

Commit

Permalink
Update the Style/ModuleFunction documentation to suggest `class << …
Browse files Browse the repository at this point in the history
…self` as an alternative
  • Loading branch information
RDeckard committed Oct 25, 2022
1 parent 5f61a3b commit de93416
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog/change_module_function-forbidden_msg.md
@@ -0,0 +1 @@
* [#11045](https://github.com/rubocop/rubocop/pull/11045): Update the `Style/ModuleFunction` documentation to suggest `class << self` as an alternative. ([@rdeckard][])
34 changes: 28 additions & 6 deletions lib/rubocop/cop/style/module_function.rb
Expand Up @@ -3,13 +3,15 @@
module RuboCop
module Cop
module Style
# Checks for use of `extend self` or `module_function` in a
# module.
# Checks for use of `extend self` or `module_function` in a module.
#
# Supported styles are: module_function, extend_self, forbidden. `forbidden`
# style prohibits the usage of both styles.
# Supported styles are: `module_function` (default), `extend_self` and `forbidden`.
#
# NOTE: the cop won't be activated when the module contains any private methods.
# NOTES:
#
# - `forbidden` style prohibits the usage of both styles
# - in default mode (`module_function`), the cop won't be activated when the module
# contains any private methods
#
# @safety
# Autocorrection is unsafe (and is disabled by default) because `extend self`
Expand All @@ -28,7 +30,6 @@ module Style
# # ...
# end
#
# @example EnforcedStyle: module_function (default)
# # good
# module Test
# extend self
Expand All @@ -37,6 +38,13 @@ module Style
# # ...
# end
#
# # good
# module Test
# class << self
# # ...
# end
# end
#
# @example EnforcedStyle: extend_self
# # bad
# module Test
Expand All @@ -50,6 +58,13 @@ module Style
# # ...
# end
#
# # good
# module Test
# class << self
# # ...
# end
# end
#
# @example EnforcedStyle: forbidden
# # bad
# module Test
Expand All @@ -70,6 +85,13 @@ module Style
# private
# # ...
# end
#
# # good
# module Test
# class << self
# # ...
# end
# end
class ModuleFunction < Base
include ConfigurableEnforcedStyle
extend AutoCorrector
Expand Down

0 comments on commit de93416

Please sign in to comment.