Module: Rubocop::Cop::Style::ConfigurableNaming
- 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
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.
35 36 37 38 39 40 41 42 43 |
# File 'lib/rubocop/cop/style/configurable_naming.rb', line 35 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
12 13 14 15 16 17 18 19 |
# File 'lib/rubocop/cop/style/configurable_naming.rb', line 12 def check(node, range) return unless range name = range.source.to_sym unless matches_config?(name) || Cop::OPERATOR_METHODS.include?(name) convention(node, range, (cop_config['EnforcedStyle'])) end end |
#matches_config?(name) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rubocop/cop/style/configurable_naming.rb', line 21 def matches_config?(name) case cop_config['EnforcedStyle'] when 'snake_case' name =~ SNAKE_CASE when 'camelCase' name =~ CAMEL_CASE else fail 'Illegal value for EnforcedStyle. Must be snake_case or ' + 'camelCase.' end end |