Skip to content

Commit 5ab601c

Browse files
committedMar 6, 2025
Include thread-safety rubocop
1 parent 39d8dd7 commit 5ab601c

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed
 

‎Gemfile.lock

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PATH
33
specs:
44
rubocop-shopify (2.15.1)
55
rubocop (~> 1.62)
6+
rubocop-thread_safety
67

78
GEM
89
remote: https://rubygems.org/
@@ -44,6 +45,9 @@ GEM
4445
unicode-display_width (>= 2.4.0, < 4.0)
4546
rubocop-ast (1.38.1)
4647
parser (>= 3.3.1.0)
48+
rubocop-thread_safety (0.7.0)
49+
lint_roller (~> 1.1)
50+
rubocop (~> 1.72, >= 1.72.1)
4751
ruby-progressbar (1.13.0)
4852
unicode-display_width (3.1.4)
4953
unicode-emoji (~> 4.0, >= 4.0.4)

‎bin/sort-cops

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def sort_cops(file_path)
5858
end
5959

6060
if ARGV.empty?
61-
puts "Usage: ruby sort_cops.rb path/to/rubocop.yml"
61+
puts "Usage: ruby sort-cops path/to/rubocop.yml"
6262
exit 1
6363
end
6464

‎rubocop-shopify.gemspec

+1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ Gem::Specification.new do |s|
2424
s.required_ruby_version = ">= 3.1.0"
2525

2626
s.add_dependency("rubocop", "~> 1.62")
27+
s.add_dependency("rubocop-thread_safety")
2728
end

‎rubocop.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ inherit_mode:
99
- Exclude
1010
- Include
1111

12+
plugins: rubocop-thread_safety
13+
1214
AllCops:
1315
StyleGuideBaseURL: https://shopify.github.io/ruby-style-guide/
1416
NewCops: disable # New cops will be triaged by style guide maintainers instead.
@@ -1165,7 +1167,7 @@ Style/MultipleComparison:
11651167
Enabled: false
11661168

11671169
Style/MutableConstant:
1168-
Enabled: false
1170+
Enabled: true
11691171

11701172
Style/NegatedIf:
11711173
Enabled: false
@@ -1549,3 +1551,8 @@ Style/YodaCondition:
15491551

15501552
Style/ZeroLengthPredicate:
15511553
Enabled: false
1554+
1555+
<% if rubocop_version >= "1.71" %>
1556+
ThreadSafety:
1557+
Enabled: true
1558+
<% end %>

‎test/fixtures/full_config.yml

+35-1
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ Style/MultipleComparison:
35263526
ComparisonsThreshold: 2
35273527
Style/MutableConstant:
35283528
Description: Do not assign mutable objects to constants.
3529-
Enabled: false
3529+
Enabled: true
35303530
VersionAdded: '0.34'
35313531
VersionChanged: '1.8'
35323532
SafeAutoCorrect: false
@@ -4523,7 +4523,41 @@ Style/ZeroLengthPredicate:
45234523
Safe: false
45244524
VersionAdded: '0.37'
45254525
VersionChanged: '0.39'
4526+
ThreadSafety/ClassAndModuleAttributes:
4527+
Description: Avoid mutating class and module attributes.
4528+
Enabled: true
4529+
ActiveSupportClassAttributeAllowed: false
4530+
ThreadSafety/InstanceVariableInClassMethod:
4531+
Description: Avoid using instance variables in class methods.
4532+
Enabled: true
4533+
ThreadSafety/MutableClassInstanceVariable:
4534+
Description: Do not assign mutable objects to class instance variables.
4535+
Enabled: true
4536+
EnforcedStyle: literals
4537+
SafeAutoCorrect: false
4538+
SupportedStyles:
4539+
- literals
4540+
- strict
4541+
ThreadSafety/NewThread:
4542+
Description: Avoid starting new threads. Let a framework like Sidekiq handle the
4543+
threads.
4544+
Enabled: true
4545+
ThreadSafety/DirChdir:
4546+
Description: Avoid using `Dir.chdir` due to its process-wide effect.
4547+
Enabled: true
4548+
AllowCallWithBlock: false
4549+
ThreadSafety/RackMiddlewareInstanceVariable:
4550+
Description: Avoid instance variables in Rack middleware.
4551+
Enabled: true
4552+
Include:
4553+
- app/middleware/**/*.rb
4554+
- lib/middleware/**/*.rb
4555+
- app/middlewares/**/*.rb
4556+
- lib/middlewares/**/*.rb
4557+
AllowedIdentifiers: []
45264558
inherit_mode:
45274559
merge:
45284560
- Exclude
45294561
- Include
4562+
ThreadSafety:
4563+
Enabled: true

0 commit comments

Comments
 (0)
Failed to load comments.