Class: RuboCop::Cop::Ezcater::RspecDotNotSelfDot
- Inherits:
-
RuboCop::Cop
- Object
- RuboCop::Cop
- RuboCop::Cop::Ezcater::RspecDotNotSelfDot
- Defined in:
- lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb
Overview
Use “.<class method>” instead of “self.<class method>” in RSpec example group descriptions.
Constant Summary collapse
- SELF_DOT_REGEXP =
/["']self\./.freeze
- COLON_COLON_REGEXP =
/["'](\:\:)/.freeze
- SELF_DOT_MSG =
'Use ".<class method>" instead of "self.<class method>" for example group description.'- COLON_COLON_MSG =
'Use ".<class method>" instead of "::<class method>" for example group description.'
Instance Method Summary collapse
Instance Method Details
#autocorrect(node) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb', line 47 def autocorrect(node) lambda do |corrector| experession_end = node.source.match?(COLON_COLON_REGEXP) ? 3 : 6 corrector.replace(Parser::Source::Range.new(node.source_range.source_buffer, node.source_range.begin_pos + 1, node.source_range.begin_pos + experession_end), ".") end end |
#on_send(node) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cop/ezcater/rspec_dot_not_self_dot.rb', line 37 def on_send(node) example_group_match(node) do |doc| if doc.source.match?(SELF_DOT_REGEXP) add_offense(doc, location: :expression, message: SELF_DOT_MSG) elsif doc.source.match?(COLON_COLON_REGEXP) add_offense(doc, location: :expression, message: COLON_COLON_MSG) end end end |