Skip to content

Commit 68e9ff7

Browse files
committed
Enable linting workflow
This also updates the `.rubocop_todo.yml` and fixes some easy-to-fix Rubocop offenses.
1 parent 6d6be7a commit 68e9ff7

9 files changed

Lines changed: 69 additions & 71 deletions

File tree

.github/workflows/lint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Lint
2+
3+
on: [pull_request]
4+
5+
concurrency:
6+
group: lint-${{ github.ref_name }}
7+
cancel-in-progress: ${{ github.ref_name != 'main' }}
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
ruby:
14+
name: Check Ruby
15+
runs-on: ubuntu-24.04
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
- name: Install Ruby and gems
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: "3.2"
23+
bundler-cache: true
24+
- name: Lint Ruby files
25+
run: bundle exec rubocop -ESP

.rubocop_todo.yml

Lines changed: 29 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,66 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2020-09-24 12:23:52 UTC using RuboCop version 0.91.1.
3+
# on 2025-02-13 10:58:32 UTC using RuboCop version 1.71.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 1
10-
Lint/MissingSuper:
11-
Exclude:
12-
- 'app/services/solidus_subscriptions/user_mismatch_error.rb'
13-
14-
# Offense count: 1
15-
# Configuration parameters: EnforcedStyleForLeadingUnderscores.
16-
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
17-
Naming/MemoizedInstanceVariableName:
9+
# Offense count: 3
10+
# Configuration parameters: EnforcedStyle.
11+
# SupportedStyles: have_received, receive
12+
RSpec/MessageSpies:
1813
Exclude:
19-
- 'lib/solidus_subscriptions/processor.rb'
14+
- 'spec/controllers/concerns/create_subscription_spec.rb'
2015

21-
# Offense count: 2
16+
# Offense count: 9
2217
RSpec/MultipleExpectations:
23-
Max: 2
18+
Max: 7
2419

25-
# Offense count: 90
26-
# Configuration parameters: IgnoreSharedExamples.
20+
# Offense count: 24
21+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
22+
# SupportedStyles: always, named_only
2723
RSpec/NamedSubject:
28-
Enabled: false
24+
Exclude:
25+
- 'spec/decorators/models/solidus_subscriptions/spree/variant/auto_delete_from_subscriptions_spec.rb'
26+
- 'spec/models/solidus_subscriptions/subscription_spec.rb'
2927

30-
# Offense count: 11
28+
# Offense count: 24
29+
# Configuration parameters: AllowedGroups.
3130
RSpec/NestedGroups:
3231
Max: 4
3332

34-
# Offense count: 4
33+
# Offense count: 3
34+
RSpec/SubjectStub:
35+
Exclude:
36+
- 'spec/controllers/concerns/create_subscription_spec.rb'
37+
38+
# Offense count: 5
3539
# Configuration parameters: Include.
3640
# Include: app/models/**/*.rb
3741
Rails/HasManyOrHasOneDependent:
3842
Exclude:
3943
- 'app/models/solidus_subscriptions/installment.rb'
4044
- 'app/models/solidus_subscriptions/subscription.rb'
4145

42-
# Offense count: 2
43-
# Configuration parameters: Include.
44-
# Include: db/migrate/*.rb
45-
Rails/ReversibleMigration:
46-
Exclude:
47-
- 'db/migrate/20160922164101_add_interval_length_and_units_to_subscription_line_items.rb'
48-
- 'db/migrate/20170106224713_change_line_item_max_installments_to_end_date.rb'
49-
50-
# Offense count: 5
51-
# Configuration parameters: ForbiddenMethods, AllowedMethods.
52-
# ForbiddenMethods: decrement!, decrement_counter, increment!, increment_counter, insert, insert!, insert_all, insert_all!, toggle!, touch, touch_all, update_all, update_attribute, update_column, update_columns, update_counters, upsert, upsert_all
53-
Rails/SkipsModelValidations:
54-
Exclude:
55-
- 'app/services/solidus_subscriptions/failure_dispatcher.rb'
56-
- 'app/services/solidus_subscriptions/order_builder.rb'
57-
- 'app/services/solidus_subscriptions/payment_failed_dispatcher.rb'
58-
5946
# Offense count: 1
60-
# Cop supports --auto-correct.
47+
# This cop supports safe autocorrection (--autocorrect).
6148
# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions.
6249
# SupportedStyles: assign_to_condition, assign_inside_condition
6350
Style/ConditionalAssignment:
6451
Exclude:
6552
- 'app/controllers/spree/admin/subscriptions_controller.rb'
6653

6754
# Offense count: 4
68-
# Configuration parameters: MinBodyLength.
55+
# This cop supports safe autocorrection (--autocorrect).
56+
# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals.
6957
Style/GuardClause:
7058
Exclude:
7159
- 'app/models/solidus_subscriptions/subscription.rb'
7260

73-
# Offense count: 1
74-
# Cop supports --auto-correct.
75-
# Configuration parameters: EnforcedStyle.
76-
# SupportedStyles: compact, exploded
77-
Style/RaiseArgs:
78-
Exclude:
79-
- 'app/services/solidus_subscriptions/checkout.rb'
80-
81-
# Offense count: 11
82-
# Cop supports --auto-correct.
83-
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
61+
# Offense count: 25
62+
# This cop supports safe autocorrection (--autocorrect).
63+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
8464
# URISchemes: http, https
8565
Layout/LineLength:
86-
Max: 290
66+
Max: 145

app/models/solidus_subscriptions/installment.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ class Installment < ApplicationRecord
3030
unfulfilled.where("#{table_name}.actionable_date <= ?", Time.zone.today)
3131
end)
3232

33+
def self.ransackable_attributes(_auth_object = nil)
34+
%w[actionable_date created_at updated_at]
35+
end
36+
3337
# Mark this installment as out of stock.
3438
#
3539
# @return [SolidusSubscriptions::InstallmentDetail] The record of the failed
@@ -131,9 +135,5 @@ def next_actionable_date
131135

132136
(DateTime.current + SolidusSubscriptions.configuration.reprocessing_interval).beginning_of_minute
133137
end
134-
135-
def self.ransackable_attributes(_auth_object = nil)
136-
%w[actionable_date created_at updated_at]
137-
end
138138
end
139139
end

app/models/solidus_subscriptions/subscription.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ def self.ransackable_scopes(_auth_object = nil)
9292
[:in_processing_state, :with_subscribable]
9393
end
9494

95+
def self.ransackable_attributes(_auth_object = nil)
96+
%w[actionable_date created_at end_date state updated_at user_id]
97+
end
98+
99+
def self.ransackable_associations(_auth_object = nil)
100+
%w[events user]
101+
end
102+
95103
def self.processing_states
96104
PROCESSING_STATES
97105
end
@@ -432,13 +440,5 @@ def emit_events_for_update
432440
emit_event(type: 'subscription_payment_method_changed')
433441
end
434442
end
435-
436-
def self.ransackable_attributes(_auth_object = nil)
437-
%w[actionable_date created_at end_date state updated_at user_id]
438-
end
439-
440-
def self.ransackable_associations(_auth_object = nil)
441-
%w[events user]
442-
end
443443
end
444444
end

spec/controllers/concerns/create_subscription_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
attr_accessor :params, :current_order
99

1010
def initialize(params = {})
11-
@params = params
12-
@current_order = nil
11+
super
1312
end
1413
end.new
1514
end

spec/features/admin/subscriptions_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
expect(subscription.billing_address.zipcode).to eq('33167')
2626
end
2727

28-
it 'Creates a subscription' do # rubocop:disable RSpec/MultipleExpectations
28+
it 'Creates a subscription' do
2929
variant = create(:variant, subscribable: true)
3030
create(:user)
3131
create(:store)

spec/jobs/solidus_subscriptions/process_installment_job_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
end
1313

1414
context 'when handling #perform errors' do
15-
it 'by default logs exception data without raising exceptions' do # rubocop:disable RSpec/MultipleExpectations
15+
it 'by default logs exception data without raising exceptions' do
1616
installment = build_stubbed(:installment)
1717
checkout = instance_double(SolidusSubscriptions::Checkout).tap do |c|
1818
allow(c).to receive(:process).and_raise('test error')

spec/lib/solidus_subscriptions/checkout_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
RSpec.describe SolidusSubscriptions::Checkout, :checkout do
44
context 'when the order can be created and paid' do
5-
# rubocop:disable RSpec/MultipleExpectations
65
it 'creates and finalizes a new order for the installment' do
76
stub_spree_preferences(auto_capture: true)
87
installment = create(:installment, :actionable)
@@ -39,7 +38,6 @@
3938
expect(order.subscription).to eq(subscription)
4039
expect(order.subscription_order).to eq(true)
4140
end
42-
# rubocop:enable RSpec/MultipleExpectations
4341

4442
it 'matches the total on the subscription' do
4543
stub_spree_preferences(auto_capture: true)

spec/requests/api/v1/subscriptions_spec.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
end
3838

3939
context 'when valid payment attributes are provided' do
40-
# rubocop:disable RSpec/MultipleExpectations
4140
it 'creates the subscription using the specified payment' do
4241
user = create(:user, &:generate_spree_api_key!)
4342
payment_source = create(:credit_card, user: user)
@@ -53,10 +52,8 @@
5352
end.to change(SolidusSubscriptions::Subscription, :count).from(0).to(1)
5453
expect(SolidusSubscriptions::Subscription.last).to have_attributes(payment_params)
5554
end
56-
# rubocop:enable RSpec/MultipleExpectations
5755
end
5856

59-
# rubocop:disable RSpec/MultipleExpectations
6057
context 'when an invalid payment method is provided' do
6158
it "doesn't create the subscription and responds with 422 Unprocessable Entity" do
6259
user = create(:user, &:generate_spree_api_key!)
@@ -98,7 +95,6 @@
9895
expect(response.status).to eq(422)
9996
end
10097
end
101-
# rubocop:enable RSpec/MultipleExpectations
10298
end
10399

104100
describe 'PATCH /:id' do

0 commit comments

Comments
 (0)