diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-02 12:10:35 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-02 12:10:35 +0000 |
commit | 4fa04f789e6fed5f0dfeafe718eeb7f56a5086e9 (patch) | |
tree | 5ef2d1d8232d3bd359ec79bf95c9a35ce650ae0b /rubocop | |
parent | 4b9ace6c1fead1b44f173eaee0cfaa58f46a258a (diff) | |
download | gitlab-ce-4fa04f789e6fed5f0dfeafe718eeb7f56a5086e9.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/gitlab/except.rb | 23 | ||||
-rw-r--r-- | rubocop/cop/gitlab/intersect.rb | 23 | ||||
-rw-r--r-- | rubocop/routes_under_scope.rb | 9 |
3 files changed, 55 insertions, 0 deletions
diff --git a/rubocop/cop/gitlab/except.rb b/rubocop/cop/gitlab/except.rb new file mode 100644 index 00000000000..24da6962457 --- /dev/null +++ b/rubocop/cop/gitlab/except.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Gitlab + # Cop that disallows the use of `Gitlab::SQL::Except`, in favour of using + # the `FromExcept` module. + class Except < RuboCop::Cop::Cop + MSG = 'Use the `FromExcept` concern, instead of using `Gitlab::SQL::Except` directly' + + def_node_matcher :raw_except?, <<~PATTERN + (send (const (const (const nil? :Gitlab) :SQL) :Except) :new ...) + PATTERN + + def on_send(node) + return unless raw_except?(node) + + add_offense(node, location: :expression) + end + end + end + end +end diff --git a/rubocop/cop/gitlab/intersect.rb b/rubocop/cop/gitlab/intersect.rb new file mode 100644 index 00000000000..4b61073b804 --- /dev/null +++ b/rubocop/cop/gitlab/intersect.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Gitlab + # Cop that disallows the use of `Gitlab::SQL::Intersect`, in favour of using + # the `FromIntersect` module. + class Intersect < RuboCop::Cop::Cop + MSG = 'Use the `FromIntersect` concern, instead of using `Gitlab::SQL::Intersect` directly' + + def_node_matcher :raw_intersect?, <<~PATTERN + (send (const (const (const nil? :Gitlab) :SQL) :Intersect) :new ...) + PATTERN + + def on_send(node) + return unless raw_intersect?(node) + + add_offense(node, location: :expression) + end + end + end + end +end diff --git a/rubocop/routes_under_scope.rb b/rubocop/routes_under_scope.rb index 3f049bb09fa..7ffb0fd36f2 100644 --- a/rubocop/routes_under_scope.rb +++ b/rubocop/routes_under_scope.rb @@ -12,6 +12,7 @@ module RuboCop def on_send(node) return unless route_method?(node) return unless outside_scope?(node) + return if root_route?(node) add_offense(node) end @@ -25,5 +26,13 @@ module RuboCop def route_method?(node) ROUTE_METHODS.include?(node.method_name) end + + def root_route?(node) + first_argument = node.arguments.first + + if first_argument.respond_to?(:value) + first_argument.value == '/' + end + end end end |