Welcome to mirror list, hosted at ThFree Co, Russian Federation.

regexp_literal_mixed_preserve.rb « style « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4dc38d82f456cb24d1cc7b0d7c718ede8d026009 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop is based on `Style/RegexpLiteral` but adds a new
      # `EnforcedStyle` option `mixed_preserve`.
      #
      # This cop will be removed once the upstream PR is merged and RuboCop upgraded.
      #
      # See https://github.com/rubocop/rubocop/pull/9688
      class RegexpLiteralMixedPreserve < RuboCop::Cop::Style::RegexpLiteral
        module Patch
          private

          def allowed_slash_literal?(node)
            super || allowed_mixed_preserve?(node)
          end

          def allowed_percent_r_literal?(node)
            super || allowed_mixed_preserve?(node)
          end

          def allowed_mixed_preserve?(node)
            style == :mixed_preserve && !contains_disallowed_slash?(node)
          end
        end

        prepend Patch
      end
    end
  end
end