Skip to content

Commit

Permalink
Update Rubocop config (#4878)
Browse files Browse the repository at this point in the history
  • Loading branch information
coalest authored Dec 23, 2024
1 parent fc1e7b4 commit 6e767db
Show file tree
Hide file tree
Showing 49 changed files with 81 additions and 142 deletions.
34 changes: 10 additions & 24 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ inherit_mode:

inherit_gem:
standard: config/base.yml
standard-rails: config/base.yml
standard-performance: config/base.yml

inherit_from:
.rubocop_todo.yml
Expand All @@ -12,15 +14,17 @@ require:
- rubocop-rails
- rubocop-performance
- standard
- standard-rails
- standard-performance

AllCops:
TargetRubyVersion: 3.1.2
Exclude:
- "vendor/**/*"
- "db/schema.rb"
- "db/partners_schema.rb"
- "db/seeds.rb"
- "db/migrate/*"
- "db/partners_migrate/*"
- "bin/*"
- "lib/files/cucumber.rake"
- "lib/tasks/*"
Expand All @@ -29,26 +33,13 @@ AllCops:
- "Rakefile"
- "tmp/*"
- "node_modules/**/*"
UseCache: false

Rails:
Enabled: true
Rails/Output:
Enabled: true
Rails/Date:
Enabled: true
Rails/FilePath:
Enabled: false
Rails/FindBy:
Enabled: true
Rails/FindEach:
Enabled: true
Rails/PluralizationGrammar:
Enabled: true
Rails/ScopeArgs:
Enabled: true
Rails/TimeZone:
Enabled: true
Rails/UnknownEnv:
Environments:
- production
Expand All @@ -62,32 +53,27 @@ Rails/AfterCommitOverride:
Enabled: false
Rails/FindById:
Enabled: false
Rails/Inquiry:
Enabled: false
Rails/MailerName:
Enabled: false
Rails/MatchRoute:
Enabled: false
Rails/NegateInclude:
Enabled: false
Rails/Pluck:
Enabled: false
Rails/PluckInWhere:
Enabled: false
Rails/RenderInline:
Enabled: false
Rails/RenderPlainText:
Enabled: false
Rails/ShortI18n:
Enabled: false
Rails/SquishedSQLHeredocs:
Enabled: false
Rails/WhereExists:
Enabled: false
Rails/WhereNot:
Enabled: false
Rails/HasAndBelongsToMany:
Enabled: false
Rails/ThreeStateBooleanColumn:
Enabled: true
# FIXME: Fix our ENV variable access and remove the following config.
Rails/EnvironmentVariableAccess:
AllowReads: true

Rails/BulkChangeTable:
Exclude:
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,11 @@ group :development, :test do
gem "rubocop"
# Rails add-on for static analysis.
gem 'rubocop-performance'
gem "rubocop-rails", "~> 2.27.0"
gem "rubocop-rails", "~> 2.25.1"
# Default rules for Rubocop.
gem "standard", "~> 1.40"
gem "standard-rails"
gem "standard-performance"
# Erb linter.
gem "erb_lint"
end
Expand Down
30 changes: 16 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ GEM
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pdf-core (0.10.0)
pdf-core (0.9.0)
pdf-reader (2.12.0)
Ascii85 (~> 1.0)
afm (~> 0.2.1)
Expand All @@ -454,13 +454,11 @@ GEM
ttfunk
pg (1.5.7)
popper_js (2.11.8)
prawn (2.5.0)
matrix (~> 0.4)
pdf-core (~> 0.10.0)
ttfunk (~> 1.8)
prawn-rails (1.5.0)
prawn (2.4.0)
pdf-core (~> 0.9.0)
ttfunk (~> 1.7)
prawn-rails (1.4.2)
actionview (>= 3.1.0)
activesupport (>= 3.1.0)
prawn
prawn-table
prawn-table (0.2.2)
Expand Down Expand Up @@ -595,10 +593,10 @@ GEM
rubocop-performance (1.23.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.27.0)
rubocop-rails (2.25.1)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.52.0, < 2.0)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-graphviz (1.2.5)
rexml
Expand Down Expand Up @@ -664,6 +662,9 @@ GEM
standard-performance (1.6.0)
lint_roller (~> 1.1)
rubocop-performance (~> 1.23.0)
standard-rails (1.1.0)
lint_roller (~> 1.0)
rubocop-rails (~> 2.25.0)
stimulus-rails (1.3.4)
railties (>= 6.0.0)
stringio (3.1.2)
Expand All @@ -673,10 +674,9 @@ GEM
execjs (>= 0.3.0, < 3)
thor (1.3.2)
tilt (2.2.0)
timeout (0.4.2)
ttfunk (1.8.0)
bigdecimal (~> 3.1)
turbo-rails (2.0.11)
timeout (0.4.1)
ttfunk (1.7.0)
turbo-rails (2.0.10)
actionpack (>= 6.0.0)
railties (>= 6.0.0)
tzinfo (2.0.6)
Expand Down Expand Up @@ -792,13 +792,15 @@ DEPENDENCIES
rspec-rails (~> 7.0.1)
rubocop
rubocop-performance
rubocop-rails (~> 2.27.0)
rubocop-rails (~> 2.25.1)
sass-rails
shoulda-matchers (~> 6.2)
simple_form
simplecov
sprockets (~> 4.2.1)
standard (~> 1.40)
standard-performance
standard-rails
stimulus-rails
strong_migrations (= 1.8.0)
terser
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/partners/dashboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def show
@partner = current_partner
@partner_requests = @partner.requests.order(created_at: :desc).limit(10)
@upcoming_distributions = @partner.distributions.order(issued_at: :desc)
.where('issued_at >= ?', Time.zone.today)
.where(issued_at: Time.zone.today..)
@distributions = @partner.distributions.order(issued_at: :desc)
.where('issued_at < ?', Time.zone.today)
.where(issued_at: ...Time.zone.today)
.limit(5)

@parent_org = Organization.find(@partner.organization_id)
Expand Down
2 changes: 1 addition & 1 deletion app/events/inventory_aggregate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def inventory_for(organization_id, event_time: nil, validate: false)
end

if event_time && (!last_snapshot || event_time > last_snapshot.event_time)
events = events.where("event_time <= ?", event_time)
events = events.where(event_time: ..event_time)
end

events = events.to_a
Expand Down
1 change: 0 additions & 1 deletion app/models/adjustment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class Adjustment < ApplicationRecord
}
scope :during, ->(range) { where(adjustments: { created_at: range }) }

validates :storage_location, :organization, presence: true
validate :storage_locations_belong_to_organization

def self.storage_locations_adjusted_for(organization)
Expand Down
1 change: 0 additions & 1 deletion app/models/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class Audit < ApplicationRecord

enum status: { in_progress: 0, confirmed: 1, finalized: 2 }

validates :storage_location, :organization, presence: true
validate :line_items_quantity_is_not_negative
validate :line_items_unique_by_item_id
validate :user_is_organization_admin_of_the_organization
Expand Down
2 changes: 1 addition & 1 deletion app/models/barcode_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BarcodeItem < ApplicationRecord
validates :organization, presence: true, unless: proc { |b| b.barcodeable_type == "BaseItem" }
validates :value, presence: true
validate :unique_barcode_value
validates :quantity, :barcodeable, presence: true
validates :quantity, presence: true
validates :quantity, numericality: { only_integer: true, greater_than: 0 }

include Filterable
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/issued_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module IssuedAt
extend ActiveSupport::Concern

included do
scope :by_issued_at, ->(issued_at) { where(issued_at: issued_at.beginning_of_month..issued_at.end_of_month) }
scope :by_issued_at, ->(issued_at) { where(issued_at: issued_at.all_month) }
scope :for_year, ->(year) { where("extract(year from issued_at) = ?", year) }
validates :issued_at, presence: true
validate :issued_at_cannot_be_before_2000
Expand Down
4 changes: 2 additions & 2 deletions app/models/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Distribution < ApplicationRecord
has_one :request, dependent: :nullify
accepts_nested_attributes_for :request

validates :storage_location, :partner, :organization, :delivery_method, presence: true
validates :delivery_method, presence: true
validate :line_items_quantity_is_positive
validates :shipping_cost, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true, if: :shipped?

Expand All @@ -59,7 +59,7 @@ class Distribution < ApplicationRecord
# state scope to allow filtering by state
scope :by_state, ->(state) { where(state: state) }
scope :recent, ->(count = 3) { order(issued_at: :desc).limit(count) }
scope :future, -> { where("issued_at >= :tomorrow", tomorrow: Time.zone.tomorrow) }
scope :future, -> { where(issued_at: Time.zone.tomorrow..) }
scope :during, ->(range) { where(distributions: { issued_at: range }) }
scope :for_csv_export, ->(organization, filters = {}, date_range = nil) {
where(organization: organization)
Expand Down
2 changes: 1 addition & 1 deletion app/models/donation_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DonationSite < ApplicationRecord

belongs_to :organization

validates :name, :address, :organization, presence: true
validates :name, :address, presence: true
validates :contact_name, length: {minimum: 3}, allow_blank: true
validates :email, format: {with: URI::MailTo::EMAIL_REGEXP, message: "is not a valid email format"}, allow_blank: true

Expand Down
2 changes: 0 additions & 2 deletions app/models/inventory_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ class InventoryItem < ApplicationRecord
belongs_to :item

validates :quantity, presence: true
validates :storage_location_id, presence: true
validates :item_id, presence: true

scope :by_partner_key, ->(partner_key) { joins(:item).merge(Item.by_partner_key(partner_key)) }
scope :active, -> { joins(:item).where(items: {active: true}) }
Expand Down
3 changes: 1 addition & 2 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Item < ApplicationRecord

validates :name, uniqueness: { scope: :organization, case_sensitive: false, message: "- An item with that name already exists (could be an inactive item)" }
validates :name, presence: true
validates :organization, presence: true
validates :distribution_quantity, numericality: { greater_than: 0 }, allow_blank: true
validates :on_hand_recommended_quantity, numericality: { greater_than_or_equal_to: 0 }, allow_blank: true
validates :on_hand_minimum_quantity, numericality: { greater_than_or_equal_to: 0 }
Expand Down Expand Up @@ -115,7 +114,7 @@ def self.barcoded_items
end

def self.barcodes_for(item)
BarcodeItem.where("barcodeable_id = ?", item.id)
BarcodeItem.where(barcodeable_id: item.id)
end

def self.reactivate(item_ids)
Expand Down
1 change: 0 additions & 1 deletion app/models/item_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
class ItemCategory < ApplicationRecord
has_paper_trail
validates :name, presence: true, uniqueness: { scope: :organization_id }
validates :organization, presence: true
validates :description, length: { maximum: 250 }

belongs_to :organization
Expand Down
1 change: 0 additions & 1 deletion app/models/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class LineItem < ApplicationRecord
belongs_to :itemizable, polymorphic: true, inverse_of: :line_items, optional: false
belongs_to :item

validates :item_id, presence: true
validates :quantity, numericality: { only_integer: true, message: "is not a number. Note: commas are not allowed" }
validate :quantity_must_be_a_number_within_range

Expand Down
6 changes: 3 additions & 3 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Organization < ApplicationRecord
has_paper_trail
resourcify

DIAPER_APP_LOGO = Rails.root.join("public", "img", "humanessentials_logo.png")
DIAPER_APP_LOGO = Rails.public_path.join("img", "humanessentials_logo.png")

include Deadlinable

Expand Down Expand Up @@ -106,7 +106,7 @@ def all
end
has_many :distributions, dependent: :destroy do
def upcoming
this_week.scheduled.where('issued_at >= ?', Time.zone.today)
this_week.scheduled.where(issued_at: Time.zone.today..)
end
end

Expand Down Expand Up @@ -293,6 +293,6 @@ def get_admin_email
end

def logo_size_check
errors.add(:logo, 'File size is greater than 1 MB') if logo.byte_size > 1.megabyte
errors.add(:logo, 'File size is greater than 1 MB') if logo.byte_size > 1.megabytes
end
end
3 changes: 1 addition & 2 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class Partner < ApplicationRecord

has_many_attached :documents

validates :organization, presence: true
validates :name, presence: true, uniqueness: { scope: :organization }

validates :email, presence: true, uniqueness: { case_sensitive: false }, format: { with: URI::MailTo::EMAIL_REGEXP }
Expand Down Expand Up @@ -259,7 +258,7 @@ def partials_to_show
def quantity_year_to_date
distributions
.includes(:line_items)
.where('distributions.issued_at >= ?', Time.zone.today.beginning_of_year)
.where(distributions: { issued_at: Time.zone.today.beginning_of_year.. })
.references(:line_items).map(&:line_items).flatten.sum(&:quantity)
end

Expand Down
1 change: 0 additions & 1 deletion app/models/partner_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class PartnerGroup < ApplicationRecord
has_many :partners, dependent: :nullify
has_and_belongs_to_many :item_categories

validates :organization, presence: true
validates :name, presence: true, uniqueness: { scope: :organization }
validates :deadline_day, :reminder_day, presence: true, if: :send_reminders?
end
2 changes: 1 addition & 1 deletion app/models/partners/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class Profile < Base
validate :has_at_least_one_request_setting
validate :pick_up_email_addresses

self.ignored_columns = %w[
self.ignored_columns += %w[
evidence_based_description
program_client_improvement
incorporate_plan
Expand Down
2 changes: 1 addition & 1 deletion app/models/storage_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class StorageLocation < ApplicationRecord
dependent: :destroy
has_many :kit_allocations, dependent: :destroy

validates :name, :address, :organization, presence: true
validates :name, :address, presence: true
validates :warehouse_type, inclusion: { in: WAREHOUSE_TYPES },
allow_blank: true
before_destroy :validate_empty_inventory, prepend: true
Expand Down
1 change: 0 additions & 1 deletion app/models/transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Transfer < ApplicationRecord
}
scope :during, ->(range) { where(created_at: range) }

validates :from, :to, :organization, presence: true
validate :storage_locations_belong_to_organization
validate :storage_locations_must_be_different
validate :from_storage_quantities
Expand Down
Loading

0 comments on commit 6e767db

Please sign in to comment.