Sha256: 8b13b5d23e1b5c8f0dbf934090cce8fd0ba214b8ed99357e3e0195a2963f5017
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
# encoding: utf-8 module Rubocop module Cop # This module provides functionality for checking if names match the # configured EnforcedStyle. module ConfigurableNaming include ConfigurableEnforcedStyle SNAKE_CASE = /^@?[\da-z_]+[!?=]?$/ CAMEL_CASE = /^@?[a-z][\da-zA-Z]+[!?=]?$/ def check(node, range) return unless range name = range.source.to_sym return if operator?(name) if matches_config?(name) correct_style_detected else add_offence(node, range, message(style)) do opposite_style_detected end end end def matches_config?(name) name =~ (style == :snake_case ? SNAKE_CASE : CAMEL_CASE) end # Returns a range containing the method name after the given regexp and # a dot. 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 end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.18.1 | lib/rubocop/cop/mixin/configurable_naming.rb |
rubocop-0.18.0 | lib/rubocop/cop/mixin/configurable_naming.rb |
rubocop-0.17.0 | lib/rubocop/cop/mixin/configurable_naming.rb |