class RuboCop::Cop::Naming::MethodName
Makes sure that all methods use the configured style, snake_case or camelCase, for their names.
This cop has `AllowedPatterns` configuration option.
Naming/MethodName: AllowedPatterns: - '\A\s*onSelectionBulkChange\s*' - '\A\s*onSelectionCleared\s*'
Method names matching patterns are always allowed.
@example EnforcedStyle: snake_case (default)
# bad def fooBar; end # good def foo_bar; end
@example EnforcedStyle: camelCase
# bad def foo_bar; end # good def fooBar; end
Constants
- MSG
Public Instance Methods
on_def(node)
click to toggle source
# File lib/rubocop/cop/naming/method_name.rb, line 55 def on_def(node) return if node.operator_method? || matches_allowed_pattern?(node.method_name) check_name(node, node.method_name, node.loc.name) end
Also aliased as: on_defs
on_send(node)
click to toggle source
# File lib/rubocop/cop/naming/method_name.rb, line 44 def on_send(node) return unless (attrs = node.attribute_accessor?) attrs.last.each do |name_item| name = attr_name(name_item) next if !name || matches_allowed_pattern?(name) check_name(node, name, range_position(node)) end end
Private Instance Methods
attr_name(name_item)
click to toggle source
# File lib/rubocop/cop/naming/method_name.rb, line 64 def attr_name(name_item) sym_name(name_item) || str_name(name_item) end
message(style)
click to toggle source
# File lib/rubocop/cop/naming/method_name.rb, line 75 def message(style) format(MSG, style: style) end
range_position(node)
click to toggle source
# File lib/rubocop/cop/naming/method_name.rb, line 68 def range_position(node) selector_end_pos = node.loc.selector.end_pos + 1 expr_end_pos = node.loc.expression.end_pos range_between(selector_end_pos, expr_end_pos) end