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:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-22 14:31:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-22 14:31:16 +0300
commit905c1110b08f93a19661cf42a276c7ea90d0a0ff (patch)
tree756d138db422392c00471ab06acdff92c5a9b69c /rubocop
parent50d93f8d1686950fc58dda4823c4835fd0d8c14b (diff)
Add latest changes from gitlab-org/gitlab@12-4-stable-ee
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/cop/gitlab/const_get_inherit_false.rb42
-rw-r--r--rubocop/cop/line_break_around_conditional_block.rb2
-rw-r--r--rubocop/migration_helpers.rb12
-rw-r--r--rubocop/rubocop.rb1
4 files changed, 51 insertions, 6 deletions
diff --git a/rubocop/cop/gitlab/const_get_inherit_false.rb b/rubocop/cop/gitlab/const_get_inherit_false.rb
new file mode 100644
index 00000000000..3d3bbc4c8d3
--- /dev/null
+++ b/rubocop/cop/gitlab/const_get_inherit_false.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module RuboCop
+ module Cop
+ module Gitlab
+ # Cop that encourages usage of inherit=false for 2nd argument when using const_get.
+ #
+ # See https://gitlab.com/gitlab-org/gitlab/issues/27678
+ class ConstGetInheritFalse < RuboCop::Cop::Cop
+ MSG = 'Use inherit=false when using const_get.'
+
+ def_node_matcher :const_get?, <<~PATTERN
+ (send _ :const_get ...)
+ PATTERN
+
+ def on_send(node)
+ return unless const_get?(node)
+ return if second_argument(node)&.false_type?
+
+ add_offense(node, location: :selector)
+ end
+
+ def autocorrect(node)
+ lambda do |corrector|
+ if arg = second_argument(node)
+ corrector.replace(arg.source_range, 'false')
+ else
+ first_argument = node.arguments[0]
+ corrector.insert_after(first_argument.source_range, ', false')
+ end
+ end
+ end
+
+ private
+
+ def second_argument(node)
+ node.arguments[1]
+ end
+ end
+ end
+ end
+end
diff --git a/rubocop/cop/line_break_around_conditional_block.rb b/rubocop/cop/line_break_around_conditional_block.rb
index 8118b314b63..2523cc162f3 100644
--- a/rubocop/cop/line_break_around_conditional_block.rb
+++ b/rubocop/cop/line_break_around_conditional_block.rb
@@ -117,7 +117,7 @@ module RuboCop
end
def block_start?(line)
- line.match(/ (do|{)( \|.*?\|)?\s?$/)
+ line.match(/ (do|{)( \|.*?\|)?\s?(#.+)?\z/)
end
def end_line?(line)
diff --git a/rubocop/migration_helpers.rb b/rubocop/migration_helpers.rb
index c066d424437..577f768da67 100644
--- a/rubocop/migration_helpers.rb
+++ b/rubocop/migration_helpers.rb
@@ -3,15 +3,17 @@ module RuboCop
module MigrationHelpers
# Returns true if the given node originated from the db/migrate directory.
def in_migration?(node)
- dirname = File.dirname(node.location.expression.source_buffer.name)
-
- dirname.end_with?('db/migrate', 'db/post_migrate')
+ dirname(node).end_with?('db/migrate', 'db/geo/migrate') || in_post_deployment_migration?(node)
end
def in_post_deployment_migration?(node)
- dirname = File.dirname(node.location.expression.source_buffer.name)
+ dirname(node).end_with?('db/post_migrate', 'db/geo/post_migrate')
+ end
+
+ private
- dirname.end_with?('db/post_migrate')
+ def dirname(node)
+ File.dirname(node.location.expression.source_buffer.name)
end
end
end
diff --git a/rubocop/rubocop.rb b/rubocop/rubocop.rb
index 8e7df62ea75..70679aa1e78 100644
--- a/rubocop/rubocop.rb
+++ b/rubocop/rubocop.rb
@@ -1,3 +1,4 @@
+require_relative 'cop/gitlab/const_get_inherit_false'
require_relative 'cop/gitlab/module_with_instance_variables'
require_relative 'cop/gitlab/predicate_memoization'
require_relative 'cop/gitlab/httparty'