diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 13:42:19 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-16 13:42:19 +0300 |
commit | 84d1bd786125c1c14a3ba5f63e38a4cc736a9027 (patch) | |
tree | f550fa965f507077e20dbb6d61a8269a99ef7107 /rubocop/cop | |
parent | 3a105e36e689f7b75482236712f1a47fd5a76814 (diff) |
Add latest changes from gitlab-org/gitlab@16-8-stable-eev16.8.0-rc42
Diffstat (limited to 'rubocop/cop')
-rw-r--r-- | rubocop/cop/gitlab/license_available_usage.rb | 26 | ||||
-rw-r--r-- | rubocop/cop/rails/avoid_time_comparison.rb | 50 | ||||
-rw-r--r-- | rubocop/cop/scalability/file_uploads.rb | 2 |
3 files changed, 77 insertions, 1 deletions
diff --git a/rubocop/cop/gitlab/license_available_usage.rb b/rubocop/cop/gitlab/license_available_usage.rb new file mode 100644 index 00000000000..29eddcba392 --- /dev/null +++ b/rubocop/cop/gitlab/license_available_usage.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Gitlab + # Cop to ban use of License.feature_available? in ApplicationSetting model to avoid cyclical dependency issues. + # Issue example: https://gitlab.com/gitlab-org/gitlab/-/issues/423237 + class LicenseAvailableUsage < RuboCop::Cop::Base + MSG = 'Avoid License.feature_available? usage in ApplicationSetting due to possible cyclical dependency ' \ + 'issue. For more information see: https://gitlab.com/gitlab-org/gitlab/-/issues/423237' + + RESTRICT_ON_SEND = [:feature_available?].freeze + + def_node_matcher :license_feature_available?, <<~PATTERN + (send + (const nil? :License) :feature_available? + (sym $_)) + PATTERN + + def on_send(node) + add_offense(node, message: MSG) if license_feature_available?(node) + end + end + end + end +end diff --git a/rubocop/cop/rails/avoid_time_comparison.rb b/rubocop/cop/rails/avoid_time_comparison.rb new file mode 100644 index 00000000000..89aa0c2ebd0 --- /dev/null +++ b/rubocop/cop/rails/avoid_time_comparison.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Rails + # Checks for time comparison. + # For more information see: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/133520 + # + # @example + # # bad + # datetime > Time.now + # Time.current < datetime + # datetime > Time.zone.now + # + # # good + # datetime.future? + # datetime.future? + # datetime.past? + class AvoidTimeComparison < RuboCop::Cop::Base + MSG = 'Avoid time comparison, use `.past?` or `.future?` instead.' + RESTRICT_ON_SEND = %i[< >].to_set.freeze + + def_node_matcher :comparison?, <<~PATTERN + (send _ %RESTRICT_ON_SEND _) + PATTERN + + def_node_matcher :time_now?, <<~PATTERN + { + (send + (const {nil? cbase} :Time) :now) + (send + (send + (const {nil? cbase} :Time) :zone) :now) + (send + (const {nil? cbase} :Time) :current) + } + PATTERN + + def on_send(node) + return unless comparison?(node) + + arg_check = node.arguments.find { |arg| time_now?(arg) } + receiver_check = time_now?(node.receiver) + + add_offense(node) if arg_check || receiver_check + end + end + end + end +end diff --git a/rubocop/cop/scalability/file_uploads.rb b/rubocop/cop/scalability/file_uploads.rb index fc52444c551..8f8c9605d09 100644 --- a/rubocop/cop/scalability/file_uploads.rb +++ b/rubocop/cop/scalability/file_uploads.rb @@ -27,7 +27,7 @@ module RuboCop # class FileUploads < RuboCop::Cop::Base MSG = 'Do not upload files without workhorse acceleration. ' \ - 'Please refer to https://docs.gitlab.com/ee/development/uploads.html' + 'Please refer to https://docs.gitlab.com/ee/development/uploads/' def_node_matcher :file_in_type, <<~PATTERN (send nil? {:requires :optional} |