Sha256: ccbca246c668da02c31040e717458b7f0050decae52e6064e35a4de2617f62ca

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

module RuboCop
  module Cop
    module Security
      module Regexp
        # This cop checks for the use of `Object#singleton_class`.
        #
        # @example
        #
        #   # bad
        #   Object.singleton_class
        #
        #   # good
        #   Object.cs__singleton_class
        class Spelling < Cop
          include RangeHelp
          MSG = 'The use of the string "regex" without a following "p" is inconsistent'

          def eligible_line? line
            line =~ /(regex)[^p]/im
          end

          def on_send node
            add_offense(node, location: :selector) if eligible_line?(node.source)

            processed_source.ast_with_comments.each do |_node, comment_lines|
              comment_lines.each do |comment_node|
                next unless eligible_line?(comment_node.text)

                add_offense(comment_node, location: comment_node.location.expression)
              end
            end
          end

          def autocorrect node
            ->(corrector) { corrector.replace(node.location.expression, node.source.gsub(/regex([^p])/, 'regexp\1')) }
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
contrast-agent-3.10.2 resources/rubocops/regexp/spelling_cop.rb
contrast-agent-3.10.1 resources/rubocops/regexp/spelling_cop.rb
contrast-agent-3.10.0 resources/rubocops/regexp/spelling_cop.rb
contrast-agent-3.9.1 resources/rubocops/regexp/spelling_cop.rb
contrast-agent-3.9.0 resources/rubocops/regexp/spelling_cop.rb
contrast-agent-3.8.5 resources/rubocops/regexp/spelling_cop.rb
contrast-agent-3.8.4 resources/rubocops/regexp/spelling_cop.rb