Module: Rubocop::Cop::Style::ConfigurableNaming
- Includes:
- ConfigurableEnforcedStyle
- Included in:
- MethodName, VariableName
- Defined in:
- lib/rubocop/cop/style/configurable_naming.rb
Overview
This module provides functionality for checking if names match the configured EnforcedStyle.
Constant Summary collapse
- SNAKE_CASE =
/^@?[\da-z_]+[!?=]?$/- CAMEL_CASE =
/^@?[a-z][\da-zA-Z]+[!?=]?$/
Instance Method Summary collapse
-
#after_dot(node, method_name_length, regexp) ⇒ Object
Returns a range containing the method name after the given regexp and a dot.
- #check(node, range) ⇒ Object
- #matches_config?(name) ⇒ Boolean
Methods included from ConfigurableEnforcedStyle
#alternative_style, #both_styles_detected, #correct_style_detected, #opposite_style_detected, #style, #unrecognized_style_detected
Instance Method Details
#after_dot(node, method_name_length, regexp) ⇒ Object
Returns a range containing the method name after the given regexp and a dot.
29 30 31 32 33 34 35 36 37 |
# File 'lib/rubocop/cop/style/configurable_naming.rb', line 29 def after_dot(node, method_name_length, regexp) expr = node.loc.expression match = /\A#{regexp}\s*\.\s*/.match(expr.source) return unless match offset = match[0].length begin_pos = expr.begin_pos + offset Parser::Source::Range.new(expr.source_buffer, begin_pos, begin_pos + method_name_length) end |
#check(node, range) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/rubocop/cop/style/configurable_naming.rb', line 14 def check(node, range) return unless range name = range.source.to_sym unless matches_config?(name) || Cop::OPERATOR_METHODS.include?(name) add_offence(node, range, (style)) end end |
#matches_config?(name) ⇒ Boolean
23 24 25 |
# File 'lib/rubocop/cop/style/configurable_naming.rb', line 23 def matches_config?(name) name =~ (style == :snake_case ? SNAKE_CASE : CAMEL_CASE) end |