Skip to content

Commit

Permalink
Update rubocop, replace custom cop with official safe navigator cop (#…
Browse files Browse the repository at this point in the history
…5292)

* Fix rubocop problems in event previews
  • Loading branch information
martinemde authored Dec 1, 2024
1 parent 77bbd90 commit c7bbd32
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 81 deletions.
7 changes: 3 additions & 4 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
inherit_from: .rubocop_todo.yml
require:
- ./lib/cops/safe_navigation_cop.rb
- rubocop-performance
- rubocop-rails
- rubocop-minitest
Expand Down Expand Up @@ -130,9 +129,9 @@ Naming/AccessorMethodName:
Exclude:
- app/controllers/application_controller.rb

Style/CustomSafeNavigationCop:
Exclude:
- app/models/links.rb
Rails/SafeNavigation:
Enabled: true
ConvertTry: true

Style/Documentation:
Enabled: false
Expand Down
27 changes: 15 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ GEM
ostruct (0.6.0)
pagy (8.6.3)
parallel (1.26.3)
parser (3.3.5.0)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pg (1.5.9)
Expand Down Expand Up @@ -676,7 +676,7 @@ GEM
rdoc (6.8.1)
psych (>= 4.0.0)
redcarpet (3.6.0)
regexp_parser (2.9.2)
regexp_parser (2.9.3)
reline (0.5.12)
io-console (~> 0.5)
rexml (3.3.9)
Expand Down Expand Up @@ -705,17 +705,17 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.66.1)
rubocop (1.69.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
rubocop-ast (>= 1.36.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.32.3)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.36.2)
parser (>= 3.3.1.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
Expand Down Expand Up @@ -819,7 +819,9 @@ GEM
turbo-rails (>= 1.3.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
unicode-display_width (3.1.2)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
unpwn (1.0.0)
bloomer (~> 1.0)
pwned (~> 2.0)
Expand Down Expand Up @@ -1191,7 +1193,7 @@ CHECKSUMS
ostruct (0.6.0) sha256=3b1736c99f4d985de36bde1155be5e22aaf6e564b30ff9bd481e2ef7c2d9ba85
pagy (8.6.3) sha256=537b2ee3119f237dd6c4a0d0a35c67a77b9d91ebb9d4f85e31407c2686774fb2
parallel (1.26.3) sha256=d86babb7a2b814be9f4b81587bf0b6ce2da7d45969fab24d8ae4bf2bb4d4c7ef
parser (3.3.5.0) sha256=f30ebb71b7830c2e7cdc4b2b0e0ec2234900e3fca3fe2fba47f78be759181ab3
parser (3.3.6.0) sha256=25d4e67cc4f0f7cab9a2ae1f38e2005b6904d2ea13c34734511d0faad038bc3b
pg (1.5.9) sha256=761efbdf73b66516f0c26fcbe6515dc7500c3f0aa1a1b853feae245433c64fdc
pg_query (5.1.0) sha256=b7f7f47c864f08ccbed46a8244906fb6ee77ee344fd27250717963928c93145d
pghero (3.6.1) sha256=e6d4f6ec3979d4828dafcd1eaa4214e70279fe2502b9fe5bd632d8333aa79cd4
Expand Down Expand Up @@ -1239,7 +1241,7 @@ CHECKSUMS
rbtrace (0.5.1) sha256=e8cba64d462bfb8ba102d7be2ecaacc789247d52ac587d8003549d909cb9c5dc
rdoc (6.8.1) sha256=0128002d1bfc4892bdd780940841e4ca41275f63781fd832d11bc8ba4461462c
redcarpet (3.6.0) sha256=8ad1889c0355ff4c47174af14edd06d62f45a326da1da6e8a121d59bdcd2e9e9
regexp_parser (2.9.2) sha256=5a27e767ad634f8a4b544520d5cd28a0db7aa1198a5d7c9d7e11d7b3d9066446
regexp_parser (2.9.3) sha256=4b620657ed8349d82e1331a076415c79b9dd714a5546162ddd790ea9988f6379
reline (0.5.12) sha256=41ab36d3fd2aaa169e99f8b82a93b9585f51130529360e24388fcccc20a055a2
rexml (3.3.9) sha256=d71875b85299f341edf47d44df0212e7658cbdf35aeb69cefdb63f57af3137c9
roadie (5.2.1) sha256=e4a4f61ce792bd91b228b6844b4bad6b160cdc1b8df86c81a8b983082a5001d6
Expand All @@ -1253,8 +1255,8 @@ CHECKSUMS
rspec-expectations (3.13.1) sha256=814cf8dadc797b00be55a84d7bc390c082735e5c914e62cbe8d0e19774b74200
rspec-mocks (3.13.1) sha256=087189899c337937bcf1d66a50dc3fc999ac88335bbeba4d385c2a38c87d7b38
rspec-support (3.13.1) sha256=48877d4f15b772b7538f3693c22225f2eda490ba65a0515c4e7cf6f2f17de70f
rubocop (1.66.1) sha256=0679c263b1164fd003b8590ae83b3e9e9bf72282d411755f227f1d6268ee5ee7
rubocop-ast (1.32.3) sha256=40201e861c73a3c2d59428c7627828ef81fb2f8a306bc4a1c1801452afe3fe0f
rubocop (1.69.0) sha256=f9440f1b84dfd744e7542c28d5b073b7733e6a254bd7c31e0036af522141ac00
rubocop-ast (1.36.2) sha256=566405b7f983eb9aa3b91d28aca6bc6566e356a97f59e89851dd910aef1dd1ca
rubocop-capybara (2.21.0) sha256=5d264efdd8b6c7081a3d4889decf1451a1cfaaec204d81534e236bc825b280ab
rubocop-factory_bot (2.26.1) sha256=8de13cd4edcee5ca800f255188167ecef8dbfc3d1fae9f15734e9d2e755392aa
rubocop-minitest (0.36.0) sha256=1d15850849c685ff4b6d64dd801ec2d13eb2fe56b6f7ce9aab93d1b0508e7b9f
Expand Down Expand Up @@ -1302,7 +1304,8 @@ CHECKSUMS
turbo-rails (2.0.11) sha256=fc47674736372780abd2a4dc0d84bef242f5ca156a457cd7fa6308291e397fcf
turbo_power (0.6.2) sha256=c9080d0d1bb79deed67bee2a7654dd38f9c903b57ad52b98d19d000958fde2cc
tzinfo (2.0.6) sha256=8daf828cc77bcf7d63b0e3bdb6caa47e2272dcfaf4fbfe46f8c3a9df087a829b
unicode-display_width (2.6.0) sha256=12279874bba6d5e4d2728cef814b19197dbb10d7a7837a869bab65da943b7f5a
unicode-display_width (3.1.2) sha256=fdd4db6cf898201e341b21106663866dbd2a64d665c1a0a2fe8af09c6ef495d1
unicode-emoji (4.0.4) sha256=2c2c4ef7f353e5809497126285a50b23056cc6e61b64433764a35eff6c36532a
unpwn (1.0.0) sha256=6239d17d46a882b3719b24fb79c78a34caff89d57ab0f5e546be5b5c882bc7d3
uri (1.0.2) sha256=b303504ceb7e5905771fa7fa14b649652fa949df18b5880d69cfb12494791e27
user_agent_parser (2.18.0) sha256=aa943b91da8906cace7d3fe16b450c9d77b68f571485c11e577af97aecb25584
Expand Down
2 changes: 1 addition & 1 deletion app/models/deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def ineligible_reason
end

def record_yank_forbidden_event!
return unless user && version && version.indexed? && ineligible?
return unless user && version&.indexed? && ineligible?
version.rubygem.record_event!(
Events::RubygemEvent::VERSION_YANK_FORBIDDEN,
reason: ineligible_reason,
Expand Down
2 changes: 1 addition & 1 deletion app/models/rubygem_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RubygemContents
attr_reader :gem

def initialize(gem:)
raise ArgumentError, "gem must be Rubygem#name" unless gem.try(:match?, Rubygem::NAME_PATTERN)
raise ArgumentError, "gem must be Rubygem#name" unless gem&.match?(Rubygem::NAME_PATTERN)
@gem = gem
end

Expand Down
16 changes: 0 additions & 16 deletions lib/cops/safe_navigation_cop.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
class Events::RubygemEvent::Version::PushedComponentPreview < Lookbook::Preview
def default(rubygem: Rubygem.first!, # rubocop:disable Metrics/ParameterLists
number: "1.0.0", platform: "ruby",
version_gid: rubygem.versions.where(number:, platform:).first&.to_gid,
pushed_by: "Pusher", actor_gid: version_gid&.find&.pusher&.to_gid)
event = FactoryBot.build(:events_rubygem_event, rubygem:, tag: Events::RubygemEvent::VERSION_PUSHED, additional:
{
number:,
platform:,
pushed_by:,
def default(rubygem: Rubygem.first!, **additional)
additional[:number] ||= "1.0.0"
additional[:platform] ||= "ruby"
version = rubygem.versions.find_by(additional.slice(:number, :platform))
additional[:version_gid] ||= version&.to_gid
additional[:actor_gid] ||= version&.pusher&.to_gid
additional[:pushed_by] ||= "Pusher"

version_gid:,
actor_gid:
})
render Events::RubygemEvent::Version::PushedComponent.new(
event:
)
event = FactoryBot.build(:events_rubygem_event, rubygem:, tag: Events::RubygemEvent::VERSION_PUSHED, additional:)
render Events::RubygemEvent::Version::PushedComponent.new(event:)
end
end
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
class Events::RubygemEvent::Version::YankForbiddenComponentPreview < Lookbook::Preview
def default(rubygem: Rubygem.first!, # rubocop:disable Metrics/ParameterLists
reason: "Versions used for testing can't be yanked.",
number: "0.0.1", platform: "ruby",
version_gid: rubygem.versions.where(number:, platform:).first&.to_gid,
yanked_by: "Yanker", actor_gid: version_gid&.find&.yanker&.to_gid)
event = FactoryBot.build(:events_rubygem_event, rubygem:, tag: Events::RubygemEvent::VERSION_YANK_FORBIDDEN, additional:
{
number:,
platform:,
yanked_by:,
def default(rubygem: Rubygem.first!, **additional)
additional[:reason] ||= "Versions used for testing can't be yanked."
additional[:number] ||= "0.0.1"
additional[:platform] ||= "ruby"
version = rubygem.versions.find_by(additional.slice(:number, :platform))
additional[:version_gid] ||= version&.to_gid
additional[:actor_gid] ||= version&.yanker&.to_gid
additional[:yanked_by] ||= "Yanker"

version_gid:,
actor_gid:,
reason:
})
render Events::RubygemEvent::Version::YankForbiddenComponent.new(
event:
)
event = FactoryBot.build(:events_rubygem_event, rubygem:, tag: Events::RubygemEvent::VERSION_YANK_FORBIDDEN, additional:)
render Events::RubygemEvent::Version::YankForbiddenComponent.new(event:)
end
end
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
class Events::RubygemEvent::Version::YankedComponentPreview < Lookbook::Preview
def default(rubygem: Rubygem.first!, # rubocop:disable Metrics/ParameterLists
number: "0.0.1", platform: "ruby",
version_gid: rubygem.versions.where(number:, platform:).first&.to_gid,
yanked_by: "Yanker", actor_gid: version_gid&.find&.yanker&.to_gid)
event = FactoryBot.build(:events_rubygem_event, rubygem:, tag: Events::RubygemEvent::VERSION_YANKED, additional:
{
number:,
platform:,
yanked_by:,
def default(rubygem: Rubygem.first!, **additional)
additional[:number] ||= "0.0.1"
additional[:platform] ||= "ruby"
version = rubygem.versions.find_by(additional.slice(:number, :platform))
additional[:version_gid] ||= version&.to_gid
additional[:actor_gid] ||= version&.yanker&.to_gid
additional[:yanked_by] ||= "Yanker"

version_gid:,
actor_gid:
})
render Events::RubygemEvent::Version::YankedComponent.new(
event:
)
event = FactoryBot.build(:events_rubygem_event, rubygem:, tag: Events::RubygemEvent::VERSION_YANKED, additional:)
render Events::RubygemEvent::Version::YankedComponent.new(event:)
end
end

0 comments on commit c7bbd32

Please sign in to comment.