Skip to content

Commit

Permalink
updates to latest rubocop
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Fader <[email protected]>
  • Loading branch information
andrewfader committed Oct 11, 2023
1 parent d21a82c commit 2e0e9d6
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 33 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,5 @@ Style/RequireOrder:
Enabled: false
Style/YodaExpression:
Enabled: false
Metrics/BlockLength:
Max: 36
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 11 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion app/lib/chief.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions app/mailers/report_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?('@')

Check warning on line 67 in app/mailers/report_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/report_mailer.rb#L67

Added line #L67 was not covered by tests

@project_info_url =
project_url(@project, locale: user.preferred_locale.to_sym)
Expand Down Expand Up @@ -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?('@')

Check warning on line 98 in app/mailers/report_mailer.rb

View check run for this annotation

Codecov / codecov/patch

app/mailers/report_mailer.rb#L98

Added line #L98 was not covered by tests

@project_info_url =
project_url(@project, locale: user.preferred_locale.to_sym)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/models/project_stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 144 in app/models/project_stat.rb

View check run for this annotation

Codecov / codecov/patch

app/models/project_stat.rb#L144

Added line #L144 was not covered by tests
.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
Expand All @@ -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)

Check warning on line 170 in app/models/project_stat.rb

View check run for this annotation

Codecov / codecov/patch

app/models/project_stat.rb#L170

Added line #L170 was not covered by tests

level_i = level.to_i
percentage_i = percentage.to_i
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions lib/tasks/default.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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 /, '<a ')
value.gsub('< a ', '<a ')
.gsub(/< \057/, '</')
.gsub(/<\057 /, '</')
.gsub(/<Strong>/, '<strong>')
.gsub(/<Em>/, '<em>')
.gsub('<Strong>', '<strong>')
.gsub('<Em>', '<em>')
.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}/")
Expand Down Expand Up @@ -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):'
Expand Down
2 changes: 1 addition & 1 deletion test/models/translations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2e0e9d6

Please sign in to comment.