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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/style/regexp_literal_mixed_preserve.rb')
-rw-r--r--rubocop/cop/style/regexp_literal_mixed_preserve.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/rubocop/cop/style/regexp_literal_mixed_preserve.rb b/rubocop/cop/style/regexp_literal_mixed_preserve.rb
new file mode 100644
index 00000000000..4dc38d82f45
--- /dev/null
+++ b/rubocop/cop/style/regexp_literal_mixed_preserve.rb
@@ -0,0 +1,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