From 2e0e9d689671d6be64db7493c60f64b390ea4798 Mon Sep 17 00:00:00 2001 From: Andrew Fader Date: Wed, 11 Oct 2023 14:47:21 -0400 Subject: [PATCH] updates to latest rubocop Signed-off-by: Andrew Fader --- .rubocop.yml | 2 ++ Gemfile | 6 +++--- Gemfile.lock | 19 +++++++++++-------- app/controllers/projects_controller.rb | 2 +- app/lib/chief.rb | 2 +- app/mailers/report_mailer.rb | 6 +++--- app/models/project.rb | 2 +- app/models/project_stat.rb | 10 +++++----- config/routes.rb | 2 +- lib/tasks/default.rake | 18 +++++++++--------- test/models/translations_test.rb | 2 +- 11 files changed, 38 insertions(+), 33 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 70201dbdc..464c48182 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -262,3 +262,5 @@ Style/RequireOrder: Enabled: false Style/YodaExpression: Enabled: false +Metrics/BlockLength: + Max: 36 diff --git a/Gemfile b/Gemfile index b6eef138b..f509f130a 100644 --- a/Gemfile +++ b/Gemfile @@ -124,9 +124,9 @@ group :development, :test do gem 'pronto-rails_best_practices', '0.11.0' gem 'pronto-rubocop', '0.11.5' # gem 'railroader', '4.3.8' # Security static analyzer. OSS fork of Brakeman - gem 'rubocop', '1.50.1', require: false # Style checker - gem 'rubocop-performance', '1.17.1', require: false # Performance cops - gem 'rubocop-rails', '2.19.0', require: false # Rails-specific cops + gem 'rubocop', '1.56.4', require: false # Style checker + gem 'rubocop-performance', '1.19.1', require: false # Performance cops + gem 'rubocop-rails', '2.21.2', require: false # Rails-specific cops gem 'ruby-graphviz', '1.2.5' # This is used for bundle viz gem 'spring', '~> 4.1' # Do NOT upgrade to vcr 6.*, as that is not OSS: diff --git a/Gemfile.lock b/Gemfile.lock index 4c5c23e47..393785edc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -184,6 +184,7 @@ GEM rexml kramdown-parser-gfm (1.1.0) kramdown (~> 2.0) + language_server-protocol (3.17.0.3) license_finder (7.1.0) bundler rubyzip (>= 1, < 3) @@ -382,22 +383,24 @@ GEM rack (>= 1.4) require_all (3.0.0) rexml (3.2.6) - rubocop (1.50.1) + rubocop (1.56.4) + base64 (~> 0.1.1) json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.2.0.0) + parser (>= 3.2.2.3) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.0, < 2.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.29.0) parser (>= 3.2.1.0) - rubocop-performance (1.17.1) + rubocop-performance (1.19.1) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rails (2.19.0) + rubocop-rails (2.21.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.33.0, < 2.0) @@ -558,9 +561,9 @@ DEPENDENCIES rails_12factor (~> 0.0.3) railties (~> 7.0.7) redcarpet (~> 3.5) - rubocop (= 1.50.1) - rubocop-performance (= 1.17.1) - rubocop-rails (= 2.19.0) + rubocop (= 1.56.4) + rubocop-performance (= 1.19.1) + rubocop-rails (= 2.21.2) ruby-graphviz (= 1.2.5) sass-rails (~> 5.1) scout_apm diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 17fcd08d6..aa5c9430e 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -752,7 +752,7 @@ def set_valid_query_url # rubocop:disable Metrics/AbcSize def sort_projects # Sort, if there is a requested order (otherwise use default created_at) - return unless params[:sort].present? && ALLOWED_SORT.include?(params[:sort]) + return if params[:sort].blank? || ALLOWED_SORT.exclude?(params[:sort]) sort_direction = params[:sort_direction] == 'desc' ? ' desc' : ' asc' sort_index = ALLOWED_SORT.index(params[:sort]) diff --git a/app/lib/chief.rb b/app/lib/chief.rb index d30bee49e..9478c94df 100644 --- a/app/lib/chief.rb +++ b/app/lib/chief.rb @@ -143,7 +143,7 @@ def propose_changes # rubocop:disable Metrics/PerceivedComplexity def apply_changes(project, changes) changes.each do |key, data| - next unless ALLOWED_FIELDS.include?(key) + next if ALLOWED_FIELDS.exclude?(key) next unless update_value?(project, key, data) # Store change: diff --git a/app/mailers/report_mailer.rb b/app/mailers/report_mailer.rb index e5f8fc00b..e078edd1f 100644 --- a/app/mailers/report_mailer.rb +++ b/app/mailers/report_mailer.rb @@ -64,7 +64,7 @@ def email_owner(project, old_badge_level, new_badge_level, lost_level) user = User.find(project.user_id) return if user.nil? return unless user.email? - return unless user.email.include?('@') + return if user.email.exclude?('@') @project_info_url = project_url(@project, locale: user.preferred_locale.to_sym) @@ -95,7 +95,7 @@ def email_reminder_owner(project) user = User.find(project.user_id) return if user.nil? return unless user.email? - return unless user.email.include?('@') + return if user.email.exclude?('@') @project_info_url = project_url(@project, locale: user.preferred_locale.to_sym) @@ -163,7 +163,7 @@ def email_new_project_owner(project) user = User.find(project.user_id) return if user.nil? return unless user.email? - return unless user.email.include?('@') + return if user.email.exclude?('@') @project_info_url = project_url(@project, locale: user.preferred_locale.to_sym) diff --git a/app/models/project.rb b/app/models/project.rb index 0f0a9f7a1..8755394e4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -606,7 +606,7 @@ def justification_good?(justification) end def need_a_base_url - return unless repo_url.blank? && homepage_url.blank? + return if repo_url.present? || homepage_url.present? errors.add :base, I18n.t('error_messages.need_home_page_or_url') end diff --git a/app/models/project_stat.rb b/app/models/project_stat.rb index ccc3eb763..71d55cb96 100644 --- a/app/models/project_stat.rb +++ b/app/models/project_stat.rb @@ -141,10 +141,10 @@ def stamp # returns nil if no ProjectStat is available in that month. # Note that created_at is an index, so this should be extremely fast. def self.last_in_month(query_date) - ProjectStat.all - .where('created_at >= ?', query_date.beginning_of_month) - .where('created_at <= ?', query_date.end_of_month) - .reorder(:created_at).last + ProjectStat + .where('created_at >= ?', query_date.beginning_of_month) + .where('created_at <= ?', query_date.end_of_month) + .reorder(:created_at).last end # Return the name of the field for a given level 0..2 @@ -167,7 +167,7 @@ def self.percent_field_name(level, percentage) # system reports instead of user interaction. # rubocop:disable Metrics/MethodLength def self.percent_field_description(level, percentage) - return "Bad level #{level}" unless Project::LEVEL_IDS.include?(level.to_s) + return "Bad level #{level}" if Project::LEVEL_IDS.exclude?(level.to_s) level_i = level.to_i percentage_i = percentage.to_i diff --git a/config/routes.rb b/config/routes.rb index 59b8ce121..5bb7cd229 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -11,7 +11,7 @@ # See how all your routes lay out with "rake routes". # This regex defines all legal locale values: -LEGAL_LOCALE = /(?:#{I18n.available_locales.join("|")})/.freeze +LEGAL_LOCALE = /(?:#{I18n.available_locales.join('|')})/.freeze # This regex is used to verify criteria levels in routes: VALID_CRITERIA_LEVEL = /[0-2]/.freeze diff --git a/lib/tasks/default.rake b/lib/tasks/default.rake index 1cb59b97c..e5f9c8fd9 100644 --- a/lib/tasks/default.rake +++ b/lib/tasks/default.rake @@ -419,22 +419,22 @@ end def normalize_string(value, locale) # Remove trailing whitespace value.sub!(/\s+$/, '') - return value unless value.include?('<') + return value if value.exclude?('<') # Google Translate generates html text that has predictable errors. # The last entry mitigates the target=... vulnerability. We don't need # to "counter" attacks from ourselves, but it does no harm and it's # easier to protect against everything. - value.gsub(/< a /, '/, '') - .gsub(//, '') + .gsub('', '') + .gsub('', '') .gsub(/ Href *=/, 'href=') - .gsub(/href = /, 'href=') - .gsub(/class = /, 'class=') - .gsub(/target = /, 'target=') - .gsub(/target="_ blank">/, 'target="_blank">') + .gsub('href = ', 'href=') + .gsub('class = ', 'class=') + .gsub('target = ', 'target=') + .gsub('target="_ blank">', 'target="_blank">') .gsub(/target="_blank" *>/, 'target="_blank" rel="noopener">') .gsub(%r{https: // }, 'https://') .gsub(%r{href="/en/}, "href=\"/#{locale}/") @@ -608,7 +608,7 @@ task :create_project_insertion_command do project_id = data_hash['id'] puts "Inserting project id #{project_id}" # Escape JSON using SQL escape ' -> '', so we can use it in a SQL command - escaped_json = "'" + file_contents.gsub(/'/, "''") + "'" + escaped_json = "'" + file_contents.gsub("'", "''") + "'" sql_command = 'insert into projects select * from ' + "json_populate_record(NULL::projects, #{escaped_json});" File.write('project.sql', sql_command) puts 'File project.sql created. To use this, do the following (examples):' diff --git a/test/models/translations_test.rb b/test/models/translations_test.rb index 047e885bc..f9a679fba 100644 --- a/test/models/translations_test.rb +++ b/test/models/translations_test.rb @@ -48,7 +48,7 @@ def simple_type(x) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity # rubocop:disable Metrics/AbcSize, Metrics/MethodLength def acceptable_html_string(text) - return true unless text.include?('<') # Can't be a problem, no '<' + return true if text.exclude?('<') # Can't be a problem, no '<' # First, detect common mistakes. # Require HTML tags to start in a lowercase Latin letter.