rubocop-hk 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +56 -3758
- data/config/default.yml +5 -3
- data/lib/rubocop/hk/version.rb +2 -1
- data/lib/rubocop-hk.rb +5 -0
- metadata +2 -1
data/README.md
CHANGED
@@ -1,3807 +1,105 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# 🔧 RuboCop HK
|
4
|
-
|
5
|
-
> **The Ultimate RuboCop Configuration for Modern Ruby & Rails 8.0+ Applications**
|
1
|
+
# RuboCop HK
|
6
2
|
|
7
3
|
[](https://badge.fury.io/rb/rubocop-hk)
|
8
|
-
[](https://www.ruby-lang.org)
|
5
|
+
[](https://rubyonrails.org)
|
10
6
|
[](https://opensource.org/licenses/MIT)
|
11
|
-
[](https://github.com/rubocop/rubocop)
|
12
|
-
[]()
|
13
|
-
[](https://rubygems.org/gems/rubocop-hk)
|
14
|
-
[]()
|
15
|
-
[]()
|
16
|
-
[](https://rubyonrails.org)
|
17
|
-
|
18
|
-
✨ **Rails 8.0+ Compatible** | 🚀 **Production-Ready** | 🎯 **Zero Configuration** | ⚡ **Performance Optimized**
|
19
|
-
|
20
|
-
**[📚 Quick Start](#-quick-start) • [📖 Usage Guide](#-usage-documentation) • [⚙️ Customization](#-advanced-customization) • [🏗️ Migration Guide](#-migration-guide) • [🤝 Contributing](CONTRIBUTING.md)**
|
21
|
-
|
22
|
-
</div>
|
23
|
-
|
24
|
-
---
|
25
|
-
|
26
|
-
## 🎯 Why RuboCop HK?
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
# ❌ Before: Inconsistent code style across your team
|
30
|
-
class UserController
|
31
|
-
def show
|
32
|
-
@user = User.find(params[:id])
|
33
|
-
render json: {
|
34
|
-
name: @user.name,
|
35
|
-
email: @user.email
|
36
|
-
}
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# ✅ After: Beautiful, consistent code with RuboCop HK
|
41
|
-
class UsersController < ApplicationController
|
42
|
-
def show
|
43
|
-
@user = User.find_by(id: params[:id])
|
44
|
-
return render json: { error: "User not found" }, status: :not_found unless @user
|
45
|
-
|
46
|
-
render json: {
|
47
|
-
name: @user.name,
|
48
|
-
email: @user.email,
|
49
|
-
}
|
50
|
-
end
|
51
|
-
end
|
52
|
-
```
|
53
|
-
|
54
|
-
---
|
55
|
-
|
56
|
-
## 📋 Table of Contents
|
57
|
-
|
58
|
-
- [🚀 Quick Start](#-quick-start)
|
59
|
-
- [🎯 Features](#-features)
|
60
|
-
- [📦 Installation & Setup](#-installation--setup)
|
61
|
-
- [⚙️ Configuration](#️-configuration)
|
62
|
-
- [🔄 Rails 8 Compatibility](#-rails-8-compatibility)
|
63
|
-
- [📊 Version Compatibility Matrix](#-version-compatibility-matrix)
|
64
|
-
- [📖 Usage Documentation](#-usage-documentation)
|
65
|
-
- [🛠️ Advanced Customization](#️-advanced-customization)
|
66
|
-
- [🏗️ Migration Guide](#️-migration-guide)
|
67
|
-
- [🎯 Real-World Examples](#-real-world-examples)
|
68
|
-
- [🎨 Modern Rails Conventions](#-modern-rails-conventions)
|
69
|
-
- [🔧 Editor Integration](#-editor-integration)
|
70
|
-
- [🐳 Docker & Containerization](#-docker--containerization)
|
71
|
-
- [📈 CI/CD Integration](#-cicd-integration)
|
72
|
-
- [⚡ Performance Optimization](#-performance-optimization)
|
73
|
-
- [❓ FAQ & Troubleshooting](#-faq--troubleshooting)
|
74
|
-
|
75
|
-
---
|
76
|
-
|
77
|
-
## 🚀 Quick Start
|
78
|
-
|
79
|
-
### ⚡ 30-Second Setup
|
80
|
-
|
81
|
-
```bash
|
82
|
-
# 1. Add to your Gemfile
|
83
|
-
echo 'gem "rubocop-hk", "~> 1.1.1", require: false' >> Gemfile
|
84
|
-
|
85
|
-
# 2. Install the gem
|
86
|
-
bundle install
|
87
|
-
|
88
|
-
# 3. Create configuration
|
89
|
-
echo 'inherit_gem:\n rubocop-hk: config/default.yml' > .rubocop.yml
|
90
|
-
|
91
|
-
# 4. Run RuboCop
|
92
|
-
bundle exec rubocop
|
93
|
-
```
|
94
|
-
|
95
|
-
<details>
|
96
|
-
<summary>🎬 <strong>See it in action</strong></summary>
|
97
|
-
|
98
|
-
```
|
99
|
-
$ bundle exec rubocop
|
100
|
-
|
101
|
-
Inspecting 23 files
|
102
|
-
.......................
|
103
|
-
|
104
|
-
23 files inspected, no offenses detected
|
105
|
-
|
106
|
-
✨ Your code is now beautifully formatted! ✨
|
107
|
-
```
|
108
|
-
|
109
|
-
</details>
|
110
|
-
|
111
|
-
**👉 For detailed setup instructions, see [QUICK_START.md](QUICK_START.md)**
|
112
|
-
|
113
|
-
---
|
114
|
-
|
115
|
-
## 🎯 Features
|
116
|
-
|
117
|
-
<table>
|
118
|
-
<tr>
|
119
|
-
<td width="33%">
|
120
|
-
|
121
|
-
### 🔥 **Modern Ruby & Rails**
|
122
|
-
- ✅ **Rails 6.0-8.0+ Ready**
|
123
|
-
- ✅ **Ruby 3.1-3.3+ Optimized**
|
124
|
-
- ✅ **Rails 8 Omakase Integration**
|
125
|
-
- ✅ **Rails 8 Authentication Patterns**
|
126
|
-
- ✅ **Double Quote Strings**
|
127
|
-
- ✅ **300+ Curated Rules**
|
128
|
-
|
129
|
-
</td>
|
130
|
-
<td width="33%">
|
131
|
-
|
132
|
-
### 🚀 **Developer Experience**
|
133
|
-
- ✅ **Zero Configuration**
|
134
|
-
- ✅ **Auto-correction**
|
135
|
-
- ✅ **Fast Performance**
|
136
|
-
- ✅ **IDE Integration**
|
137
|
-
|
138
|
-
</td>
|
139
|
-
<td width="33%">
|
140
|
-
|
141
|
-
### 🎛️ **Flexible & Extensible**
|
142
|
-
- ✅ **Plugin Architecture**
|
143
|
-
- ✅ **Selective Disabling**
|
144
|
-
- ✅ **Gradual Adoption**
|
145
|
-
- ✅ **Custom Cop Support**
|
146
|
-
|
147
|
-
</td>
|
148
|
-
</tr>
|
149
|
-
</table>
|
150
|
-
|
151
|
-
---
|
152
|
-
|
153
|
-
## 📦 Installation & Setup
|
154
|
-
|
155
|
-
### 📋 **Copy-Paste Installation**
|
156
|
-
|
157
|
-
<details>
|
158
|
-
<summary><strong>🆕 New Rails Application</strong></summary>
|
159
|
-
|
160
|
-
```bash
|
161
|
-
# Step 1: Add to Gemfile
|
162
|
-
cat << 'EOF' >> Gemfile
|
163
|
-
|
164
|
-
# Code quality and style enforcement
|
165
|
-
group :development, :test do
|
166
|
-
gem "rubocop-hk", "~> 1.1.1", require: false
|
167
|
-
end
|
168
|
-
EOF
|
169
|
-
|
170
|
-
# Step 2: Install dependencies
|
171
|
-
bundle install
|
172
|
-
|
173
|
-
# Step 3: Create RuboCop configuration
|
174
|
-
cat << 'EOF' > .rubocop.yml
|
175
|
-
# RuboCop HK Configuration
|
176
|
-
inherit_gem:
|
177
|
-
rubocop-hk: config/default.yml
|
178
|
-
|
179
|
-
AllCops:
|
180
|
-
TargetRubyVersion: 3.3
|
181
|
-
TargetRailsVersion: 7.0
|
182
|
-
NewCops: enable
|
183
|
-
EOF
|
184
|
-
|
185
|
-
# Step 4: Run initial check
|
186
|
-
bundle exec rubocop --autocorrect-all
|
187
|
-
```
|
188
|
-
|
189
|
-
</details>
|
190
|
-
|
191
|
-
<details>
|
192
|
-
<summary><strong>🔄 Existing Rails Application</strong></summary>
|
193
|
-
|
194
|
-
```bash
|
195
|
-
# Step 1: Add to existing Gemfile
|
196
|
-
bundle add rubocop-hk --group development,test --require false
|
197
|
-
|
198
|
-
# Step 2: Backup existing config (if any)
|
199
|
-
[ -f .rubocop.yml ] && cp .rubocop.yml .rubocop.yml.backup
|
200
|
-
|
201
|
-
# Step 3: Create new configuration
|
202
|
-
cat << 'EOF' > .rubocop.yml
|
203
|
-
inherit_gem:
|
204
|
-
rubocop-hk: config/default.yml
|
205
|
-
|
206
|
-
# Gradually enable rules for legacy codebases
|
207
|
-
inherit_from: .rubocop_todo.yml
|
208
|
-
|
209
|
-
AllCops:
|
210
|
-
TargetRubyVersion: 3.0 # Adjust to your Ruby version (3.0+)
|
211
|
-
TargetRailsVersion: 6.0 # Adjust to your Rails version (6.0+)
|
212
|
-
EOF
|
213
|
-
|
214
|
-
# Step 4: Generate TODO list for gradual adoption
|
215
|
-
bundle exec rubocop --auto-gen-config
|
216
|
-
|
217
|
-
# Step 5: Auto-fix what you can
|
218
|
-
bundle exec rubocop --autocorrect-all --safe
|
219
|
-
```
|
220
|
-
|
221
|
-
</details>
|
222
7
|
|
223
|
-
|
224
|
-
<summary><strong>💎 Standalone Ruby Application</strong></summary>
|
8
|
+
A comprehensive RuboCop configuration for modern Ruby 3.3+ and Rails 7.1+ applications, featuring 45+ warning-only modern rules with team-focused gradual adoption.
|
225
9
|
|
226
|
-
|
227
|
-
# Step 1: Install gem
|
228
|
-
gem install rubocop-hk -v "~> 1.0.0"
|
229
|
-
|
230
|
-
# Step 2: Create configuration
|
231
|
-
cat << 'EOF' > .rubocop.yml
|
232
|
-
inherit_gem:
|
233
|
-
rubocop-hk: config/default.yml
|
10
|
+
## Features
|
234
11
|
|
235
|
-
|
236
|
-
|
237
|
-
|
12
|
+
- **Modern Ruby & Rails Support**: Target Ruby 3.3+ and Rails 8.0+ with latest patterns
|
13
|
+
- **Warning-Only Modern Rules**: 45+ new rules as warnings to enable gradual adoption
|
14
|
+
- **Team-Focused**: Educational approach with clear explanations for each rule
|
15
|
+
- **Zero Breaking Changes**: All new features are opt-in warnings only
|
16
|
+
- **Comprehensive Coverage**: Style, Rails, RSpec, Performance, and Lint rules
|
17
|
+
- **Production Ready**: 100% test coverage with extensive CI/CD validation
|
238
18
|
|
239
|
-
|
240
|
-
rubocop --autocorrect-all
|
241
|
-
```
|
242
|
-
|
243
|
-
</details>
|
244
|
-
|
245
|
-
### 📋 **Manual Installation**
|
19
|
+
## Installation
|
246
20
|
|
247
21
|
Add this line to your application's Gemfile:
|
248
22
|
|
249
23
|
```ruby
|
250
|
-
|
251
|
-
gem "rubocop-hk", "~> 1.1.1", require: false
|
252
|
-
end
|
253
|
-
```
|
254
|
-
|
255
|
-
Then execute:
|
256
|
-
|
257
|
-
```bash
|
258
|
-
$ bundle install
|
259
|
-
```
|
260
|
-
|
261
|
-
Or install it directly:
|
262
|
-
|
263
|
-
```bash
|
264
|
-
$ gem install rubocop-hk -v "~> 1.0.0"
|
265
|
-
```
|
266
|
-
|
267
|
-
---
|
268
|
-
|
269
|
-
## ⚙️ Configuration
|
270
|
-
|
271
|
-
### 🎯 **Basic Configuration**
|
272
|
-
|
273
|
-
Create `.rubocop.yml` in your project root:
|
274
|
-
|
275
|
-
```yaml
|
276
|
-
# 🔧 Basic RuboCop HK Setup
|
277
|
-
inherit_gem:
|
278
|
-
rubocop-hk: config/default.yml
|
279
|
-
|
280
|
-
AllCops:
|
281
|
-
TargetRubyVersion: 3.3 # Your Ruby version
|
282
|
-
TargetRailsVersion: 7.0 # Your Rails version (if using Rails)
|
283
|
-
NewCops: enable # Enable new cops as they're added
|
284
|
-
```
|
285
|
-
|
286
|
-
### 🎛️ **Advanced Configuration**
|
287
|
-
|
288
|
-
```yaml
|
289
|
-
# 🚀 Advanced RuboCop HK Configuration
|
290
|
-
inherit_gem:
|
291
|
-
rubocop-hk: config/default.yml
|
292
|
-
|
293
|
-
AllCops:
|
294
|
-
TargetRubyVersion: 3.3
|
295
|
-
TargetRailsVersion: 7.0
|
296
|
-
NewCops: enable
|
297
|
-
|
298
|
-
# Exclude common directories
|
299
|
-
Exclude:
|
300
|
-
- "tmp/**/*"
|
301
|
-
- "log/**/*"
|
302
|
-
- "node_modules/**/*"
|
303
|
-
- "public/**/*"
|
304
|
-
- "vendor/**/*"
|
305
|
-
- "db/schema.rb"
|
306
|
-
- "db/migrate/*.rb"
|
307
|
-
|
308
|
-
# 🎨 Customize specific cops
|
309
|
-
Style/Documentation:
|
310
|
-
Enabled: false # Disable documentation requirement
|
311
|
-
|
312
|
-
Metrics/ClassLength:
|
313
|
-
Max: 150 # Allow longer classes
|
314
|
-
|
315
|
-
Layout/LineLength:
|
316
|
-
Max: 120 # Extend line length
|
317
|
-
|
318
|
-
# 🧪 Testing configurations
|
319
|
-
RSpec/ExampleLength:
|
320
|
-
Max: 20 # Allow longer test examples
|
321
|
-
|
322
|
-
# 📊 Performance settings
|
323
|
-
Performance/Casecmp:
|
324
|
-
Enabled: true # Enable performance optimizations
|
325
|
-
```
|
326
|
-
|
327
|
-
**👉 For more configuration options, see [CUSTOMIZATION.md](CUSTOMIZATION.md)**
|
328
|
-
|
329
|
-
---
|
330
|
-
|
331
|
-
## 🔄 Rails 8 Compatibility
|
332
|
-
|
333
|
-
### 🎉 **Rails 8.0+ Enhanced Support**
|
334
|
-
|
335
|
-
RuboCop HK fully embraces **Rails 8.0+ Omakase RuboCop configuration** while extending it with production-tested rules for real-world applications.
|
336
|
-
|
337
|
-
<details>
|
338
|
-
<summary><strong>🆕 What's New in Rails 8 Integration</strong></summary>
|
339
|
-
|
340
|
-
- ✅ **Omakase Configuration Compatibility** - Works seamlessly with Rails 8's built-in RuboCop settings
|
341
|
-
- ✅ **Enhanced Authentication Patterns** - Support for new Rails 8 authentication generators
|
342
|
-
- ✅ **Modern Asset Pipeline** - Updated rules for Propshaft and new asset handling
|
343
|
-
- ✅ **Improved Performance** - Optimized for Rails 8's enhanced performance features
|
344
|
-
- ✅ **Solid Foundation** - Full support for Solid Cache, Queue, and Cable
|
345
|
-
- ✅ **Kamal Deployment** - Integrated rules for modern deployment workflows
|
346
|
-
|
347
|
-
</details>
|
348
|
-
|
349
|
-
### 🚀 **Rails 8 Migration Benefits**
|
350
|
-
|
351
|
-
```ruby
|
352
|
-
# Rails 8 Authentication (New Pattern)
|
353
|
-
class SessionsController < ApplicationController
|
354
|
-
# ✅ Rails 8 style - using new authentication patterns
|
355
|
-
def create
|
356
|
-
user = User.authenticate_by(email: params[:email], password: params[:password])
|
357
|
-
return redirect_to login_path, alert: "Invalid credentials" unless user
|
358
|
-
|
359
|
-
login(user)
|
360
|
-
redirect_to root_path, notice: "Welcome back!"
|
361
|
-
end
|
362
|
-
|
363
|
-
private
|
364
|
-
|
365
|
-
def login(user)
|
366
|
-
session[:user_id] = user.id
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
# Rails 8 Solid Foundation Integration
|
371
|
-
class CacheService
|
372
|
-
# ✅ Modern Rails 8 caching patterns
|
373
|
-
def fetch_user_data(user_id)
|
374
|
-
Rails.cache.fetch("user:#{user_id}", expires_in: 1.hour) do
|
375
|
-
expensive_user_calculation(user_id)
|
376
|
-
end
|
377
|
-
end
|
378
|
-
end
|
379
|
-
|
380
|
-
# Rails 8 Deployment with Kamal
|
381
|
-
# config/deploy.yml - Now properly supported by our rules
|
382
|
-
```
|
383
|
-
|
384
|
-
---
|
385
|
-
|
386
|
-
## 📊 Version Compatibility & Support Matrix
|
387
|
-
|
388
|
-
### 🎯 **Complete Ruby & Rails Compatibility**
|
389
|
-
|
390
|
-
<div align="center">
|
391
|
-
|
392
|
-

|
393
|
-

|
394
|
-

|
395
|
-

|
396
|
-
|
397
|
-
</div>
|
398
|
-
|
399
|
-
| Ruby Version | Rails Version | RuboCop HK | Status | Production Ready | Performance | Notes |
|
400
|
-
|:-------------|:--------------|:-----------|:-------|:-----------------|:------------|:------|
|
401
|
-
| **🟢 Ruby 3.3+** | **Rails 8.0+** | **v0.1.0+** | ✅ **Fully Supported** | ✅ **Excellent** | ⚡ **Fastest** | Latest Rails 8 Omakase + Enhanced rules |
|
402
|
-
| **🟢 Ruby 3.3** | Rails 7.2 | v0.1.0+ | ✅ **Fully Supported** | ✅ **Excellent** | ⚡ **Fast** | Recommended for new projects |
|
403
|
-
| **🟢 Ruby 3.3** | Rails 7.1 | v0.1.0+ | ✅ **Fully Supported** | ✅ **Excellent** | ⚡ **Fast** | Stable and feature-rich |
|
404
|
-
| **🟢 Ruby 3.3** | Rails 7.0 | v0.1.0+ | ✅ **Fully Supported** | ✅ **Excellent** | ⚡ **Fast** | Most stable combination |
|
405
|
-
| **🟡 Ruby 3.2** | Rails 8.0+ | v0.1.0+ | ✅ **Supported** | ✅ **Very Good** | 🚀 **Good** | Excellent production choice |
|
406
|
-
| **🟡 Ruby 3.2** | Rails 7.0-7.2 | v0.1.0+ | ✅ **Supported** | ✅ **Very Good** | 🚀 **Good** | Widely adopted in enterprise |
|
407
|
-
| **🟠 Ruby 3.1** | Rails 7.0-8.0 | v0.1.0+ | ✅ **Minimum Support** | ✅ **Good** | 📈 **Adequate** | Consider upgrading Ruby soon |
|
408
|
-
| **🟠 Ruby 3.1** | Rails 6.1 | v0.1.0+ | ✅ **Legacy Support** | ✅ **Good** | 📈 **Adequate** | Legacy applications only |
|
409
|
-
| **🟠 Ruby 3.1** | Rails 6.0 | v0.1.0+ | ⚠️ **Limited** | ⚠️ **Caution** | 📉 **Slow** | Upgrade strongly recommended |
|
410
|
-
| **🔴 Ruby 3.0** | Rails 5.2-6.1 | v0.1.0+ | ⚠️ **End of Life** | ❌ **Not Recommended** | 📉 **Poor** | Security risk - upgrade immediately |
|
411
|
-
| **🔴 Ruby 2.7** | Rails 4.2-6.0 | ❌ **Not Supported** | ❌ **Incompatible** | ❌ **Deprecated** | ❌ **N/A** | End of life - unsupported |
|
412
|
-
|
413
|
-
### 🔧 **RuboCop Dependencies Matrix**
|
414
|
-
|
415
|
-
| Component | Version | Required For | Compatibility | Security | Notes |
|
416
|
-
|:----------|:--------|:-------------|:-------------|:---------|:------|
|
417
|
-
| **RuboCop Core** | **1.79.2+** | All projects | ✅ Latest stable | 🔒 Secure | Core functionality |
|
418
|
-
| **rubocop-rails** | **2.32.0+** | Rails projects | ✅ Rails 6.0-8.0+ | 🔒 Secure | Rails-specific cops |
|
419
|
-
| **rubocop-rspec** | **3.6.0+** | RSpec testing | ✅ RSpec 3.0+ | 🔒 Secure | Testing best practices |
|
420
|
-
| **rubocop-performance** | **1.25.0+** | All projects | ✅ Ruby 3.1+ | 🔒 Secure | Performance optimizations |
|
421
|
-
| **thor** | **1.0+** | CLI functionality | ✅ Ruby 3.1+ | 🔒 Secure | Command-line interface |
|
422
|
-
| **Ruby** | **3.1.0+** | All projects | ✅ Required minimum | 🔒 Secure | Minimum supported version |
|
423
|
-
|
424
|
-
### 🎯 **Framework & Library Compatibility**
|
425
|
-
|
426
|
-
<table>
|
427
|
-
<tr>
|
428
|
-
<td width="50%">
|
429
|
-
|
430
|
-
#### ✅ **Fully Supported (Tier 1)**
|
431
|
-
- 🚀 **Ruby on Rails** 6.0 - 8.0+
|
432
|
-
- 🧪 **RSpec** 3.0+
|
433
|
-
- 📊 **Minitest** 5.0+
|
434
|
-
- 🔍 **Capybara** 3.0+
|
435
|
-
- 🏭 **Factory Bot** 6.0+
|
436
|
-
- 🎯 **Pundit** 2.0+
|
437
|
-
- 📡 **GraphQL Ruby** 1.8+
|
438
|
-
- 🎨 **ViewComponent** 2.0+
|
439
|
-
- 🔐 **Devise** 4.0+
|
440
|
-
- 📄 **Kaminari** 1.0+
|
441
|
-
|
442
|
-
</td>
|
443
|
-
<td width="50%">
|
444
|
-
|
445
|
-
#### 🟡 **Partially Supported (Tier 2)**
|
446
|
-
- 🛠️ **Sinatra** (Basic support)
|
447
|
-
- 🔧 **Hanami** 2.0+ (Community rules)
|
448
|
-
- 🎪 **Grape** 1.0+ (API-focused rules)
|
449
|
-
- 🏗️ **Dry-rb** (Functional patterns)
|
450
|
-
- 🌊 **Trailblazer** (Operation patterns)
|
451
|
-
- 🎭 **ROM** (Data mapping)
|
452
|
-
- 🏃 **Sidekiq** 6.0+ (Job processing)
|
453
|
-
- 🔄 **ActiveJob** (Built into Rails)
|
454
|
-
|
455
|
-
</td>
|
456
|
-
</tr>
|
457
|
-
</table>
|
458
|
-
|
459
|
-
### 📈 **Testing Matrix (CI/CD Verified)**
|
460
|
-
|
461
|
-
<div align="center">
|
462
|
-
|
463
|
-
| Environment | Ruby 3.1 | Ruby 3.2 | Ruby 3.3 | Ruby 3.4-dev |
|
464
|
-
|:------------|:--------:|:--------:|:--------:|:-------------:|
|
465
|
-
| **Rails 8.0** | 🟡 | ✅ | ✅ | 🔧 |
|
466
|
-
| **Rails 7.2** | ✅ | ✅ | ✅ | 🔧 |
|
467
|
-
| **Rails 7.1** | ✅ | ✅ | ✅ | 🔧 |
|
468
|
-
| **Rails 7.0** | ✅ | ✅ | ✅ | ⚠️ |
|
469
|
-
| **Rails 6.1** | ✅ | ✅ | 🟡 | ❌ |
|
470
|
-
| **Rails 6.0** | 🟡 | 🟡 | ⚠️ | ❌ |
|
471
|
-
|
472
|
-
**Legend**: ✅ Fully Tested | 🟡 Basic Testing | 🔧 Development | ⚠️ Legacy | ❌ Not Supported
|
473
|
-
|
474
|
-
</div>
|
475
|
-
|
476
|
-
---
|
477
|
-
|
478
|
-
## 📊 Available Configurations
|
479
|
-
|
480
|
-
### 🎯 **Core Configuration Files**
|
481
|
-
|
482
|
-
| File | Purpose | When to Use |
|
483
|
-
|:-----|:--------|:------------|
|
484
|
-
| **`config/default.yml`** | 🎯 Main configuration | Standard Rails applications |
|
485
|
-
| **`config/rubocop-rails.yml`** | 🚂 Rails-specific rules | Rails applications only |
|
486
|
-
| **`config/rubocop-rspec.yml`** | 🧪 RSpec testing rules | Projects using RSpec |
|
487
|
-
| **`config/rubocop-style.yml`** | 🎨 Style preferences | Code formatting standards |
|
488
|
-
| **`config/rubocop-layout.yml`** | 📐 Layout and spacing | Code structure rules |
|
489
|
-
| **`config/rubocop-metrics.yml`** | 📊 Complexity metrics | Code quality enforcement |
|
490
|
-
| **`config/rubocop-lint.yml`** | 🐛 Error prevention | Bug detection and prevention |
|
491
|
-
| **`config/rubocop-performance.yml`** | ⚡ Performance rules | Optimization recommendations |
|
492
|
-
|
493
|
-
### 🔗 **Configuration Inheritance Tree**
|
494
|
-
|
495
|
-
```
|
496
|
-
📁 default.yml (Main Config)
|
497
|
-
├── 🎨 rubocop-style.yml ── Double quotes, modern syntax
|
498
|
-
├── 🚂 rubocop-rails.yml ── Rails 7+ conventions
|
499
|
-
├── 🧪 rubocop-rspec.yml ── Testing best practices
|
500
|
-
├── 📐 rubocop-layout.yml ── Code structure & spacing
|
501
|
-
├── 📊 rubocop-metrics.yml ── Complexity & maintainability
|
502
|
-
├── 🐛 rubocop-lint.yml ── Error detection & prevention
|
503
|
-
└── ⚡ rubocop-performance.yml ── Performance optimizations
|
504
|
-
```
|
505
|
-
|
506
|
-
---
|
507
|
-
|
508
|
-
## 📖 Usage Documentation
|
509
|
-
|
510
|
-
### 🎯 **Installation for Different Project Types**
|
511
|
-
|
512
|
-
<details>
|
513
|
-
<summary><strong>🆕 New Rails 8 Application</strong></summary>
|
514
|
-
|
515
|
-
```bash
|
516
|
-
# Generate new Rails 8 app with RuboCop HK pre-configured
|
517
|
-
rails new my_app --css=tailwind --database=postgresql
|
518
|
-
cd my_app
|
519
|
-
|
520
|
-
# Add RuboCop HK to Gemfile
|
521
|
-
cat >> Gemfile << 'EOF'
|
522
|
-
|
523
|
-
# Code quality and linting
|
524
|
-
group :development, :test do
|
525
|
-
gem "rubocop-hk", "~> 1.1.1", require: false
|
526
|
-
end
|
527
|
-
EOF
|
528
|
-
|
529
|
-
bundle install
|
530
|
-
|
531
|
-
# Create optimized Rails 8 configuration
|
532
|
-
cat > .rubocop.yml << 'EOF'
|
533
|
-
# Rails 8 Omakase + RuboCop HK Enhanced Configuration
|
534
|
-
inherit_gem:
|
535
|
-
rubocop-hk: config/default.yml
|
536
|
-
|
537
|
-
AllCops:
|
538
|
-
TargetRubyVersion: 3.3
|
539
|
-
TargetRailsVersion: 8.0
|
540
|
-
NewCops: enable
|
541
|
-
|
542
|
-
# Rails 8 optimizations
|
543
|
-
Rails/ApplicationController:
|
544
|
-
Enabled: true
|
545
|
-
Rails/ApplicationRecord:
|
546
|
-
Enabled: true
|
547
|
-
Rails/SkipsModelValidations:
|
548
|
-
AllowedMethods:
|
549
|
-
- touch
|
550
|
-
- increment!
|
551
|
-
- decrement!
|
552
|
-
- update_attribute
|
553
|
-
|
554
|
-
# Rails 8 Authentication patterns
|
555
|
-
Rails/Output:
|
556
|
-
Exclude:
|
557
|
-
- "app/controllers/sessions_controller.rb"
|
558
|
-
EOF
|
559
|
-
|
560
|
-
# Run initial auto-correction
|
561
|
-
bundle exec rubocop --autocorrect-all
|
562
|
-
|
563
|
-
# Optional: Set up pre-commit hook
|
564
|
-
echo 'bundle exec rubocop --autocorrect' > .git/hooks/pre-commit
|
565
|
-
chmod +x .git/hooks/pre-commit
|
566
|
-
```
|
567
|
-
|
568
|
-
</details>
|
569
|
-
|
570
|
-
<details>
|
571
|
-
<summary><strong>🏗️ Existing Legacy Rails Application</strong></summary>
|
572
|
-
|
573
|
-
```bash
|
574
|
-
# Backup existing configuration
|
575
|
-
[ -f .rubocop.yml ] && cp .rubocop.yml .rubocop.yml.backup.$(date +%Y%m%d)
|
576
|
-
|
577
|
-
# Add to existing Gemfile
|
578
|
-
bundle add rubocop-hk --group development,test --require false
|
579
|
-
|
580
|
-
# Create gradual adoption configuration
|
581
|
-
cat > .rubocop.yml << 'EOF'
|
582
|
-
# Gradual adoption for legacy Rails applications
|
583
|
-
inherit_gem:
|
584
|
-
rubocop-hk: config/default.yml
|
585
|
-
|
586
|
-
# Import generated TODO file for gradual adoption
|
587
|
-
inherit_from: .rubocop_todo.yml
|
588
|
-
|
589
|
-
AllCops:
|
590
|
-
TargetRubyVersion: 3.1 # Adjust to your Ruby version
|
591
|
-
TargetRailsVersion: 6.0 # Adjust to your Rails version
|
592
|
-
NewCops: disable # Start conservative for legacy apps
|
593
|
-
|
594
|
-
# Legacy app exclusions (customize as needed)
|
595
|
-
AllCops:
|
596
|
-
Exclude:
|
597
|
-
- "db/**/*"
|
598
|
-
- "config/**/*"
|
599
|
-
- "vendor/**/*"
|
600
|
-
- "node_modules/**/*"
|
601
|
-
- "bin/**/*"
|
602
|
-
- "log/**/*"
|
603
|
-
- "tmp/**/*"
|
604
|
-
- "public/**/*"
|
605
|
-
- "storage/**/*"
|
606
|
-
|
607
|
-
# Disable problematic cops for legacy apps initially
|
608
|
-
Metrics/ClassLength:
|
609
|
-
Enabled: false
|
610
|
-
Metrics/MethodLength:
|
611
|
-
Enabled: false
|
612
|
-
Style/Documentation:
|
613
|
-
Enabled: false
|
614
|
-
EOF
|
615
|
-
|
616
|
-
# Generate TODO file for gradual adoption
|
617
|
-
bundle exec rubocop --auto-gen-config
|
618
|
-
|
619
|
-
# Auto-fix safe issues only
|
620
|
-
bundle exec rubocop --autocorrect --safe
|
621
|
-
|
622
|
-
echo "✅ Setup complete! Review .rubocop_todo.yml and gradually enable rules."
|
623
|
-
```
|
624
|
-
|
625
|
-
</details>
|
626
|
-
|
627
|
-
<details>
|
628
|
-
<summary><strong>📡 Rails API-Only Application</strong></summary>
|
629
|
-
|
630
|
-
```bash
|
631
|
-
# API-only Rails app setup
|
632
|
-
rails new my_api --api --database=postgresql
|
633
|
-
cd my_api
|
634
|
-
|
635
|
-
# Add RuboCop HK with API optimizations
|
636
|
-
cat >> Gemfile << 'EOF'
|
637
|
-
|
638
|
-
group :development, :test do
|
639
|
-
gem "rubocop-hk", "~> 1.1.1", require: false
|
640
|
-
end
|
641
|
-
EOF
|
642
|
-
|
643
|
-
bundle install
|
644
|
-
|
645
|
-
# Create API-optimized configuration
|
646
|
-
cat > .rubocop.yml << 'EOF'
|
647
|
-
# API-only Rails application configuration
|
648
|
-
inherit_gem:
|
649
|
-
rubocop-hk: config/default.yml
|
650
|
-
|
651
|
-
AllCops:
|
652
|
-
TargetRubyVersion: 3.3
|
653
|
-
TargetRailsVersion: 8.0
|
654
|
-
|
655
|
-
# API-specific customizations
|
656
|
-
Rails/ApplicationController:
|
657
|
-
Enabled: true
|
658
|
-
|
659
|
-
# Disable view-related cops for API-only apps
|
660
|
-
Rails/OutputSafety:
|
661
|
-
Enabled: false
|
662
|
-
Rails/LinkToBlank:
|
663
|
-
Enabled: false
|
664
|
-
|
665
|
-
# API response patterns
|
666
|
-
Style/HashSyntax:
|
667
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
668
|
-
|
669
|
-
Layout/HashAlignment:
|
670
|
-
EnforcedHashRocketStyle: key
|
671
|
-
EnforcedColonStyle: key
|
672
|
-
EOF
|
673
|
-
|
674
|
-
bundle exec rubocop --autocorrect-all
|
24
|
+
gem 'rubocop-hk', '~> 1.2.1', require: false
|
675
25
|
```
|
676
26
|
|
677
|
-
|
678
|
-
|
679
|
-
<details>
|
680
|
-
<summary><strong>💎 Ruby Gem Development</strong></summary>
|
27
|
+
And then execute:
|
681
28
|
|
682
29
|
```bash
|
683
|
-
# Create new gem with RuboCop HK
|
684
|
-
bundle gem my_gem
|
685
|
-
cd my_gem
|
686
|
-
|
687
|
-
# Add to gemspec
|
688
|
-
cat >> my_gem.gemspec << 'EOF'
|
689
|
-
spec.add_development_dependency "rubocop-hk", "~> 1.0.0"
|
690
|
-
EOF
|
691
|
-
|
692
30
|
bundle install
|
693
|
-
|
694
|
-
# Create gem-focused configuration
|
695
|
-
cat > .rubocop.yml << 'EOF'
|
696
|
-
# Ruby gem development configuration
|
697
|
-
inherit_gem:
|
698
|
-
rubocop-hk: config/default.yml
|
699
|
-
|
700
|
-
AllCops:
|
701
|
-
TargetRubyVersion: 3.1 # Support broader Ruby versions for gems
|
702
|
-
|
703
|
-
# Gem-specific settings
|
704
|
-
Style/Documentation:
|
705
|
-
Enabled: true # Important for gems
|
706
|
-
|
707
|
-
Metrics/BlockLength:
|
708
|
-
Exclude:
|
709
|
-
- "spec/**/*"
|
710
|
-
- "*.gemspec"
|
711
|
-
|
712
|
-
Naming/FileName:
|
713
|
-
Exclude:
|
714
|
-
- "lib/**/*" # Allow gem naming conventions
|
715
|
-
EOF
|
716
|
-
|
717
|
-
bundle exec rubocop --autocorrect-all
|
718
31
|
```
|
719
32
|
|
720
|
-
|
33
|
+
## Quick Start
|
721
34
|
|
722
|
-
|
723
|
-
|
724
|
-
<details>
|
725
|
-
<summary><strong>🚀 Rails 8.0+ Configuration (Recommended)</strong></summary>
|
726
|
-
|
727
|
-
**Best for**: New projects, modern Rails applications
|
35
|
+
1. Create a `.rubocop.yml` file in your project root:
|
728
36
|
|
729
37
|
```yaml
|
730
|
-
# .rubocop.yml - Rails 8 Optimized
|
731
38
|
inherit_gem:
|
732
39
|
rubocop-hk: config/default.yml
|
733
|
-
|
734
|
-
AllCops:
|
735
|
-
TargetRubyVersion: 3.3 # Latest stable Ruby
|
736
|
-
TargetRailsVersion: 8.0 # Rails 8 features
|
737
|
-
NewCops: enable # Enable new cops as released
|
738
|
-
|
739
|
-
# Rails 8 Omakase Integration
|
740
|
-
Rails/ApplicationController:
|
741
|
-
Enabled: true
|
742
|
-
SuperClass: ApplicationController
|
743
|
-
|
744
|
-
Rails/ApplicationRecord:
|
745
|
-
Enabled: true
|
746
|
-
SuperClass: ApplicationRecord
|
747
|
-
|
748
|
-
# Rails 8 Authentication patterns
|
749
|
-
Rails/Output:
|
750
|
-
Exclude:
|
751
|
-
- "app/controllers/sessions_controller.rb" # Rails 8 auth patterns
|
752
|
-
- "app/controllers/passwords_controller.rb"
|
753
|
-
|
754
|
-
# Modern Rails 8 patterns
|
755
|
-
Style/StringLiterals:
|
756
|
-
EnforcedStyle: double_quotes # Rails 8 Omakase preference
|
757
|
-
|
758
|
-
# Performance optimizations for Rails 8
|
759
|
-
Performance/StringReplacement:
|
760
|
-
Enabled: true
|
761
|
-
|
762
|
-
Performance/MapCompact:
|
763
|
-
Enabled: true
|
764
|
-
|
765
|
-
# Rails 8 Solid foundation
|
766
|
-
Rails/CompactBlank:
|
767
|
-
Enabled: true
|
768
|
-
|
769
|
-
Rails/ResponseParsedBody:
|
770
|
-
Enabled: true
|
771
40
|
```
|
772
41
|
|
773
|
-
|
42
|
+
2. Run RuboCop:
|
43
|
+
|
774
44
|
```bash
|
775
|
-
|
776
|
-
cd my_app
|
777
|
-
bundle add rubocop-hk --group development,test
|
778
|
-
# Copy configuration above to .rubocop.yml
|
779
|
-
bundle exec rubocop --autocorrect-all
|
45
|
+
bundle exec rubocop
|
780
46
|
```
|
781
47
|
|
782
|
-
|
783
|
-
|
784
|
-
<details>
|
785
|
-
<summary><strong>🎯 Rails 7.x Configuration (Stable)</strong></summary>
|
786
|
-
|
787
|
-
**Best for**: Production applications, enterprise environments
|
788
|
-
|
789
|
-
```yaml
|
790
|
-
# .rubocop.yml - Rails 7 Stable
|
791
|
-
inherit_gem:
|
792
|
-
rubocop-hk: config/default.yml
|
793
|
-
|
794
|
-
AllCops:
|
795
|
-
TargetRubyVersion: 3.2 # Stable Ruby for enterprise
|
796
|
-
TargetRailsVersion: 7.1 # Rails 7.1 for stability
|
797
|
-
NewCops: disable # Conservative for production
|
798
|
-
|
799
|
-
# Rails 7 specific features
|
800
|
-
Rails/CompactBlank:
|
801
|
-
Enabled: true
|
802
|
-
|
803
|
-
Rails/DuplicateAssociation:
|
804
|
-
Enabled: true
|
805
|
-
|
806
|
-
Rails/I18nLazyLookup:
|
807
|
-
Enabled: true
|
808
|
-
|
809
|
-
Rails/ResponseParsedBody:
|
810
|
-
Enabled: true
|
811
|
-
|
812
|
-
# Enterprise security settings
|
813
|
-
Security/Open:
|
814
|
-
Enabled: true
|
815
|
-
|
816
|
-
Security/Eval:
|
817
|
-
Enabled: true
|
818
|
-
|
819
|
-
# Production-ready settings
|
820
|
-
Rails/Output:
|
821
|
-
Enabled: true
|
822
|
-
Exclude:
|
823
|
-
- "db/seeds.rb"
|
824
|
-
- "lib/tasks/**/*"
|
825
|
-
|
826
|
-
# Asset pipeline for Rails 7
|
827
|
-
Rails/FilePath:
|
828
|
-
EnforcedStyle: arguments
|
48
|
+
3. Review warnings and gradually promote them to errors when your team is ready:
|
829
49
|
|
830
|
-
# Performance for Rails 7 apps
|
831
|
-
Performance:
|
832
|
-
Enabled: true
|
833
|
-
```
|
834
|
-
|
835
|
-
**Migration from Rails 6**:
|
836
50
|
```bash
|
837
|
-
#
|
838
|
-
bundle
|
51
|
+
# View current warnings
|
52
|
+
bundle exec rubocop --format json | jq '.files[].offenses[] | select(.severity=="warning")'
|
839
53
|
|
840
|
-
#
|
841
|
-
|
842
|
-
|
843
|
-
# Run safe auto-corrections
|
844
|
-
bundle exec rubocop --autocorrect --safe
|
54
|
+
# Use the promotion script (see documentation)
|
55
|
+
ruby scripts/promote-warnings.rb
|
845
56
|
```
|
846
57
|
|
847
|
-
|
848
|
-
|
849
|
-
<details>
|
850
|
-
<summary><strong>🏗️ Rails 6.x Configuration (Legacy)</strong></summary>
|
851
|
-
|
852
|
-
**Best for**: Legacy applications, gradual upgrades
|
853
|
-
|
854
|
-
```yaml
|
855
|
-
# .rubocop.yml - Rails 6 Legacy Support
|
856
|
-
inherit_gem:
|
857
|
-
rubocop-hk: config/default.yml
|
858
|
-
|
859
|
-
# Import legacy TODO file for gradual adoption
|
860
|
-
inherit_from: .rubocop_todo.yml
|
861
|
-
|
862
|
-
AllCops:
|
863
|
-
TargetRubyVersion: 3.1 # Minimum supported
|
864
|
-
TargetRailsVersion: 6.1 # Rails 6.1 for better support
|
865
|
-
NewCops: disable # Avoid breaking changes
|
866
|
-
|
867
|
-
# Disable newer Rails cops not available in Rails 6
|
868
|
-
Rails/CompactBlank:
|
869
|
-
Enabled: false # Not available in Rails 6
|
58
|
+
## Configuration Options
|
870
59
|
|
871
|
-
|
872
|
-
Enabled: false # Rails 7+ feature
|
60
|
+
RuboCop HK provides several preconfigured options:
|
873
61
|
|
874
|
-
|
875
|
-
|
62
|
+
- `config/default.yml` - Balanced configuration with modern warning-only rules
|
63
|
+
- `config/strict.yml` - More stringent rules for mature codebases
|
64
|
+
- `config/rails.yml` - Rails-specific optimizations
|
876
65
|
|
877
|
-
|
878
|
-
Metrics/ClassLength:
|
879
|
-
Max: 200 # More lenient for legacy code
|
880
|
-
|
881
|
-
Metrics/MethodLength:
|
882
|
-
Max: 20 # Allow longer methods initially
|
883
|
-
|
884
|
-
Style/Documentation:
|
885
|
-
Enabled: false # Disable for legacy migration
|
886
|
-
|
887
|
-
# Rails 6 specific exclusions
|
888
|
-
AllCops:
|
889
|
-
Exclude:
|
890
|
-
- "db/**/*"
|
891
|
-
- "config/environments/**/*"
|
892
|
-
- "config/initializers/**/*"
|
893
|
-
- "app/assets/**/*"
|
894
|
-
- "vendor/**/*"
|
895
|
-
- "node_modules/**/*"
|
896
|
-
```
|
897
|
-
|
898
|
-
**Gradual migration strategy**:
|
899
|
-
```bash
|
900
|
-
# Generate TODO file
|
901
|
-
bundle exec rubocop --auto-gen-config
|
902
|
-
|
903
|
-
# Enable one department at a time
|
904
|
-
# Week 1: Layout cops
|
905
|
-
# Week 2: Style cops
|
906
|
-
# Week 3: Rails cops
|
907
|
-
# Week 4: Performance cops
|
908
|
-
```
|
909
|
-
|
910
|
-
</details>
|
911
|
-
|
912
|
-
<details>
|
913
|
-
<summary><strong>💎 Ruby-Only Configuration (Non-Rails)</strong></summary>
|
914
|
-
|
915
|
-
**Best for**: Gems, libraries, non-Rails applications
|
916
|
-
|
917
|
-
```yaml
|
918
|
-
# .rubocop.yml - Ruby-only projects
|
919
|
-
inherit_gem:
|
920
|
-
rubocop-hk: config/default.yml
|
921
|
-
|
922
|
-
AllCops:
|
923
|
-
TargetRubyVersion: 3.1 # Broad compatibility for gems
|
924
|
-
|
925
|
-
# Disable Rails-specific cops
|
926
|
-
Rails:
|
927
|
-
Enabled: false
|
928
|
-
|
929
|
-
# Disable RSpec cops if not using RSpec
|
930
|
-
RSpec:
|
931
|
-
Enabled: false
|
932
|
-
|
933
|
-
# Gem-specific settings
|
934
|
-
Style/Documentation:
|
935
|
-
Enabled: true # Important for public gems
|
936
|
-
|
937
|
-
Style/FrozenStringLiteralComment:
|
938
|
-
Enabled: true # Performance for gems
|
939
|
-
|
940
|
-
# Gem naming conventions
|
941
|
-
Naming/FileName:
|
942
|
-
Exclude:
|
943
|
-
- "lib/**/*" # Allow gem naming patterns
|
944
|
-
|
945
|
-
# Testing configuration
|
946
|
-
Metrics/BlockLength:
|
947
|
-
Exclude:
|
948
|
-
- "spec/**/*"
|
949
|
-
- "test/**/*"
|
950
|
-
- "*.gemspec"
|
951
|
-
|
952
|
-
# Security for public gems
|
953
|
-
Security:
|
954
|
-
Enabled: true
|
955
|
-
```
|
956
|
-
|
957
|
-
</details>
|
958
|
-
|
959
|
-
<details>
|
960
|
-
<summary><strong>🌐 API-Only Rails Configuration</strong></summary>
|
961
|
-
|
962
|
-
**Best for**: Microservices, JSON APIs, headless applications
|
963
|
-
|
964
|
-
```yaml
|
965
|
-
# .rubocop.yml - API-only Rails
|
966
|
-
inherit_gem:
|
967
|
-
rubocop-hk: config/default.yml
|
968
|
-
|
969
|
-
AllCops:
|
970
|
-
TargetRubyVersion: 3.3
|
971
|
-
TargetRailsVersion: 8.0
|
972
|
-
|
973
|
-
# API-specific Rails cops
|
974
|
-
Rails/ApplicationController:
|
975
|
-
Enabled: true
|
976
|
-
SuperClass: ActionController::API
|
977
|
-
|
978
|
-
# Disable view-related cops
|
979
|
-
Rails/OutputSafety:
|
980
|
-
Enabled: false # No views in API-only
|
981
|
-
|
982
|
-
Rails/LinkToBlank:
|
983
|
-
Enabled: false # No HTML links
|
984
|
-
|
985
|
-
Rails/ContentTag:
|
986
|
-
Enabled: false # No HTML generation
|
987
|
-
|
988
|
-
# JSON response patterns
|
989
|
-
Style/HashSyntax:
|
990
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
991
|
-
|
992
|
-
Style/StringHashKeys:
|
993
|
-
Enabled: false # Allow string keys in responses
|
994
|
-
|
995
|
-
# API testing patterns
|
996
|
-
RSpec/ExampleLength:
|
997
|
-
Max: 30 # API tests can be longer
|
998
|
-
|
999
|
-
RSpec/MultipleExpectations:
|
1000
|
-
Max: 8 # Complex API responses
|
1001
|
-
|
1002
|
-
# Performance for API responses
|
1003
|
-
Performance/StringReplacement:
|
1004
|
-
Enabled: true
|
1005
|
-
|
1006
|
-
Performance/MapCompact:
|
1007
|
-
Enabled: true
|
1008
|
-
|
1009
|
-
# Exclude non-API directories
|
1010
|
-
AllCops:
|
1011
|
-
Exclude:
|
1012
|
-
- "app/views/**/*" # No views
|
1013
|
-
- "app/helpers/**/*" # No view helpers
|
1014
|
-
- "app/assets/**/*" # No assets
|
1015
|
-
```
|
1016
|
-
|
1017
|
-
</details>
|
1018
|
-
|
1019
|
-
### 🔧 **Configuration Examples for Different Team Sizes**
|
1020
|
-
|
1021
|
-
<details>
|
1022
|
-
<summary><strong>👥 Startup Team (2-5 developers)</strong></summary>
|
1023
|
-
|
1024
|
-
**Focus: Speed, flexibility, learning-friendly**
|
1025
|
-
|
1026
|
-
```yaml
|
1027
|
-
# .rubocop.yml - Startup Configuration
|
1028
|
-
inherit_gem:
|
1029
|
-
rubocop-hk: config/default.yml
|
1030
|
-
|
1031
|
-
AllCops:
|
1032
|
-
TargetRubyVersion: 3.3
|
1033
|
-
TargetRailsVersion: 8.0
|
1034
|
-
NewCops: enable
|
1035
|
-
|
1036
|
-
# More lenient for small teams learning best practices
|
1037
|
-
Metrics/ClassLength:
|
1038
|
-
Max: 150 # Allow slightly longer classes while learning
|
1039
|
-
|
1040
|
-
Metrics/MethodLength:
|
1041
|
-
Max: 15 # Slightly more flexible
|
1042
|
-
|
1043
|
-
Style/Documentation:
|
1044
|
-
Enabled: false # Focus on code quality first
|
1045
|
-
|
1046
|
-
# Encourage good practices but don't block development
|
1047
|
-
Layout/LineLength:
|
1048
|
-
Max: 120
|
1049
|
-
|
1050
|
-
# Allow more experimental patterns
|
1051
|
-
Style/ClassAndModuleChildren:
|
1052
|
-
Enabled: false
|
1053
|
-
|
1054
|
-
# Startup-friendly RSpec settings
|
1055
|
-
RSpec/ExampleLength:
|
1056
|
-
Max: 25 # Allow longer examples for complex integration tests
|
1057
|
-
|
1058
|
-
RSpec/MultipleExpectations:
|
1059
|
-
Max: 5 # Allow more expectations while learning TDD
|
1060
|
-
```
|
1061
|
-
|
1062
|
-
</details>
|
1063
|
-
|
1064
|
-
<details>
|
1065
|
-
<summary><strong>🏢 Enterprise Team (10+ developers)</strong></summary>
|
1066
|
-
|
1067
|
-
**Focus: Consistency, maintainability, strict standards**
|
1068
|
-
|
1069
|
-
```yaml
|
1070
|
-
# .rubocop.yml - Enterprise Configuration
|
1071
|
-
inherit_gem:
|
1072
|
-
rubocop-hk: config/default.yml
|
1073
|
-
|
1074
|
-
AllCops:
|
1075
|
-
TargetRubyVersion: 3.2 # Conservative for enterprise
|
1076
|
-
TargetRailsVersion: 7.0
|
1077
|
-
NewCops: disable # Evaluate new cops before enabling
|
1078
|
-
|
1079
|
-
# Strict metrics for large teams
|
1080
|
-
Metrics/ClassLength:
|
1081
|
-
Max: 100
|
1082
|
-
|
1083
|
-
Metrics/MethodLength:
|
1084
|
-
Max: 10
|
1085
|
-
|
1086
|
-
Metrics/CyclomaticComplexity:
|
1087
|
-
Max: 6
|
1088
|
-
|
1089
|
-
# Mandatory documentation for enterprise
|
1090
|
-
Style/Documentation:
|
1091
|
-
Enabled: true
|
1092
|
-
Exclude:
|
1093
|
-
- "spec/**/*"
|
1094
|
-
- "test/**/*"
|
1095
|
-
|
1096
|
-
# Strict line length for readability
|
1097
|
-
Layout/LineLength:
|
1098
|
-
Max: 100
|
1099
|
-
|
1100
|
-
# Enterprise security settings
|
1101
|
-
Security/Open:
|
1102
|
-
Enabled: true
|
1103
|
-
|
1104
|
-
# Mandatory error handling
|
1105
|
-
Style/RescueStandardError:
|
1106
|
-
EnforcedStyle: explicit
|
1107
|
-
|
1108
|
-
# Enterprise RSpec standards
|
1109
|
-
RSpec/ExampleLength:
|
1110
|
-
Max: 15
|
1111
|
-
|
1112
|
-
RSpec/MultipleExpectations:
|
1113
|
-
Max: 3
|
1114
|
-
|
1115
|
-
RSpec/NestedGroups:
|
1116
|
-
Max: 3
|
1117
|
-
```
|
1118
|
-
|
1119
|
-
</details>
|
1120
|
-
|
1121
|
-
<details>
|
1122
|
-
<summary><strong>🌍 Open Source Project</strong></summary>
|
1123
|
-
|
1124
|
-
**Focus: Community standards, broad compatibility**
|
1125
|
-
|
1126
|
-
```yaml
|
1127
|
-
# .rubocop.yml - Open Source Configuration
|
1128
|
-
inherit_gem:
|
1129
|
-
rubocop-hk: config/default.yml
|
1130
|
-
|
1131
|
-
AllCops:
|
1132
|
-
TargetRubyVersion: 3.1 # Broad compatibility
|
1133
|
-
|
1134
|
-
# Documentation is crucial for open source
|
1135
|
-
Style/Documentation:
|
1136
|
-
Enabled: true
|
1137
|
-
|
1138
|
-
# Ensure broad Ruby version compatibility
|
1139
|
-
Style/FrozenStringLiteralComment:
|
1140
|
-
Enabled: true
|
1141
|
-
|
1142
|
-
# Community-friendly settings
|
1143
|
-
Layout/LineLength:
|
1144
|
-
Max: 120
|
1145
|
-
|
1146
|
-
# Encourage descriptive naming
|
1147
|
-
Naming/VariableNumber:
|
1148
|
-
EnforcedStyle: snake_case
|
1149
|
-
|
1150
|
-
# Open source security
|
1151
|
-
Security:
|
1152
|
-
Enabled: true
|
1153
|
-
|
1154
|
-
# Community RSpec patterns
|
1155
|
-
RSpec/ExampleLength:
|
1156
|
-
Max: 20 # Allow detailed examples for documentation
|
1157
|
-
```
|
1158
|
-
|
1159
|
-
</details>
|
1160
|
-
|
1161
|
-
### ⚡ **Advanced Customization Options**
|
1162
|
-
|
1163
|
-
<details>
|
1164
|
-
<summary><strong>🎯 Selective Cop Enabling/Disabling</strong></summary>
|
1165
|
-
|
1166
|
-
```yaml
|
1167
|
-
# Advanced selective configuration
|
1168
|
-
inherit_gem:
|
1169
|
-
rubocop-hk: config/default.yml
|
1170
|
-
|
1171
|
-
# Enable specific cops with custom settings
|
1172
|
-
Style/TrailingCommaInArguments:
|
1173
|
-
EnforcedStyleForMultiline: comma
|
1174
|
-
|
1175
|
-
Style/TrailingCommaInArrayLiteral:
|
1176
|
-
EnforcedStyleForMultiline: comma
|
1177
|
-
|
1178
|
-
# Disable cops that conflict with team preferences
|
1179
|
-
Style/StringLiterals:
|
1180
|
-
Enabled: false # If you prefer single quotes
|
1181
|
-
|
1182
|
-
# Customize specific file patterns
|
1183
|
-
Rails/Output:
|
1184
|
-
Exclude:
|
1185
|
-
- "app/controllers/admin/**/*"
|
1186
|
-
- "lib/debugging_helpers.rb"
|
1187
|
-
|
1188
|
-
# Department-level configurations
|
1189
|
-
Lint:
|
1190
|
-
Enabled: true
|
1191
|
-
|
1192
|
-
Style:
|
1193
|
-
Enabled: true
|
1194
|
-
Exclude:
|
1195
|
-
- "db/data_migrations/**/*"
|
1196
|
-
```
|
1197
|
-
|
1198
|
-
</details>
|
1199
|
-
|
1200
|
-
---
|
1201
|
-
|
1202
|
-
## 🛠️ Advanced Customization
|
1203
|
-
|
1204
|
-
### 🎯 **Common Commands**
|
1205
|
-
|
1206
|
-
```bash
|
1207
|
-
# 🔍 Check all files
|
1208
|
-
bundle exec rubocop
|
1209
|
-
|
1210
|
-
# ⚡ Auto-fix safe issues
|
1211
|
-
bundle exec rubocop --autocorrect
|
1212
|
-
|
1213
|
-
# 🚀 Auto-fix all issues (use with caution)
|
1214
|
-
bundle exec rubocop --autocorrect-all
|
1215
|
-
|
1216
|
-
# 📊 Show progress and statistics
|
1217
|
-
bundle exec rubocop --format progress
|
1218
|
-
|
1219
|
-
# 📁 Check specific files/directories
|
1220
|
-
bundle exec rubocop app/ lib/
|
1221
|
-
|
1222
|
-
# 🎯 Check only specific cops
|
1223
|
-
bundle exec rubocop --only Style/StringLiterals
|
1224
|
-
|
1225
|
-
# 📋 Generate configuration for legacy code
|
1226
|
-
bundle exec rubocop --auto-gen-config
|
1227
|
-
```
|
1228
|
-
|
1229
|
-
### 🎛️ **Overriding RuboCop Rules**
|
1230
|
-
|
1231
|
-
You can easily override or customize any RuboCop rule by adding it to your `.rubocop.yml` file:
|
1232
|
-
|
1233
|
-
```yaml
|
1234
|
-
# .rubocop.yml
|
1235
|
-
inherit_gem:
|
1236
|
-
rubocop-hk: config/default.yml
|
1237
|
-
|
1238
|
-
AllCops:
|
1239
|
-
TargetRubyVersion: 3.3
|
1240
|
-
TargetRailsVersion: 8.0
|
1241
|
-
|
1242
|
-
# 🚫 Disable specific cops
|
1243
|
-
Style/Documentation:
|
1244
|
-
Enabled: false # Turn off documentation requirement
|
1245
|
-
|
1246
|
-
# 🔢 Adjust cop parameters
|
1247
|
-
Metrics/ClassLength:
|
1248
|
-
Max: 200 # Allow longer classes (default: 100)
|
1249
|
-
|
1250
|
-
Layout/LineLength:
|
1251
|
-
Max: 120 # Extend line length (default: 80)
|
1252
|
-
Exclude:
|
1253
|
-
- "db/migrate/*.rb" # Exclude migrations from line length
|
1254
|
-
|
1255
|
-
# 🎯 Enable/disable cops for specific files
|
1256
|
-
Style/FrozenStringLiteralComment:
|
1257
|
-
Enabled: true
|
1258
|
-
Exclude:
|
1259
|
-
- "bin/*"
|
1260
|
-
- "db/seeds.rb"
|
1261
|
-
|
1262
|
-
# 📊 Customize severity levels
|
1263
|
-
Style/StringLiterals:
|
1264
|
-
EnforcedStyle: double_quotes # Enforce double quotes
|
1265
|
-
Severity: error # Make violations errors instead of warnings
|
1266
|
-
|
1267
|
-
# 🧪 RSpec-specific overrides
|
1268
|
-
RSpec/ExampleLength:
|
1269
|
-
Max: 25 # Allow longer test examples (default: 15)
|
1270
|
-
|
1271
|
-
RSpec/MultipleExpectations:
|
1272
|
-
Max: 5 # Allow more expectations per test
|
1273
|
-
|
1274
|
-
# ⚡ Performance cop customization
|
1275
|
-
Performance/Casecmp:
|
1276
|
-
Enabled: true
|
1277
|
-
Severity: warning
|
1278
|
-
|
1279
|
-
# 🚂 Rails-specific overrides
|
1280
|
-
Rails/HasManyOrHasOneDependent:
|
1281
|
-
Enabled: true
|
1282
|
-
Severity: error # Make missing dependent option an error
|
1283
|
-
```
|
1284
|
-
|
1285
|
-
**💡 Pro Tips for Overriding Rules:**
|
1286
|
-
|
1287
|
-
- **Start small**: Override one rule at a time and test the impact
|
1288
|
-
- **Use Exclude**: Prefer excluding specific files rather than disabling cops entirely
|
1289
|
-
- **Check severity**: Use `warning` instead of disabling if you want to keep visibility
|
1290
|
-
- **Document why**: Add comments explaining why you're overriding specific rules
|
1291
|
-
- **Team agreement**: Make sure your team agrees on rule changes
|
1292
|
-
|
1293
|
-
**🔍 Finding Rule Names:**
|
1294
|
-
```bash
|
1295
|
-
# See all available cops
|
1296
|
-
bundle exec rubocop --show-cops
|
1297
|
-
|
1298
|
-
# Find which cop is flagging a specific issue
|
1299
|
-
bundle exec rubocop --format offenses
|
1300
|
-
```
|
1301
|
-
|
1302
|
-
### 🔧 **Pre-commit Hook Setup**
|
1303
|
-
|
1304
|
-
```bash
|
1305
|
-
# Install pre-commit gem
|
1306
|
-
gem install pre-commit
|
1307
|
-
|
1308
|
-
# Initialize in your project
|
1309
|
-
pre-commit install
|
1310
|
-
|
1311
|
-
# Create .pre-commit-config.yaml
|
1312
|
-
cat << 'EOF' > .pre-commit-config.yaml
|
1313
|
-
repos:
|
1314
|
-
- repo: local
|
1315
|
-
hooks:
|
1316
|
-
- id: rubocop
|
1317
|
-
name: RuboCop
|
1318
|
-
entry: bundle exec rubocop --autocorrect
|
1319
|
-
language: system
|
1320
|
-
types: [ruby]
|
1321
|
-
pass_filenames: false
|
1322
|
-
EOF
|
1323
|
-
```
|
1324
|
-
|
1325
|
-
---
|
1326
|
-
|
1327
|
-
## 🏗️ Migration & Upgrade Guide
|
1328
|
-
|
1329
|
-
### 🚀 **Rails Version Upgrades**
|
1330
|
-
|
1331
|
-
<details>
|
1332
|
-
<summary><strong>📈 Rails 7 → Rails 8 Migration</strong></summary>
|
1333
|
-
|
1334
|
-
**Prerequisites**:
|
1335
|
-
- Ruby 3.1+ (Ruby 3.2+ recommended)
|
1336
|
-
- RuboCop HK 0.1.0+
|
1337
|
-
- Clean RuboCop run on current Rails 7 setup
|
1338
|
-
|
1339
|
-
**Step-by-Step Migration**:
|
1340
|
-
|
1341
|
-
1. **Preparation Phase**
|
1342
|
-
```bash
|
1343
|
-
# Ensure clean state
|
1344
|
-
bundle exec rubocop
|
1345
|
-
bundle exec rspec # or your test suite
|
1346
|
-
|
1347
|
-
# Backup current configuration
|
1348
|
-
cp .rubocop.yml .rubocop.yml.rails7.backup
|
1349
|
-
```
|
1350
|
-
|
1351
|
-
2. **Rails Upgrade**
|
1352
|
-
```bash
|
1353
|
-
# Update Rails
|
1354
|
-
bundle update rails
|
1355
|
-
|
1356
|
-
# Run Rails 8 upgrade tasks
|
1357
|
-
rails app:update
|
1358
|
-
```
|
1359
|
-
|
1360
|
-
3. **RuboCop Configuration Update**
|
1361
|
-
```yaml
|
1362
|
-
# .rubocop.yml - Updated for Rails 8
|
1363
|
-
inherit_gem:
|
1364
|
-
rubocop-hk: config/default.yml
|
1365
|
-
|
1366
|
-
AllCops:
|
1367
|
-
TargetRubyVersion: 3.3 # Updated from 3.2
|
1368
|
-
TargetRailsVersion: 8.0 # Updated from 7.x
|
1369
|
-
NewCops: enable # Enable Rails 8 cops
|
1370
|
-
|
1371
|
-
# New Rails 8 specific cops
|
1372
|
-
Rails/CompactBlank:
|
1373
|
-
Enabled: true
|
1374
|
-
|
1375
|
-
Rails/ResponseParsedBody:
|
1376
|
-
Enabled: true
|
1377
|
-
```
|
1378
|
-
|
1379
|
-
4. **Auto-correction and Testing**
|
1380
|
-
```bash
|
1381
|
-
# Run auto-corrections
|
1382
|
-
bundle exec rubocop --autocorrect-all --safe
|
1383
|
-
|
1384
|
-
# Test the application
|
1385
|
-
bundle exec rspec
|
1386
|
-
rails server # Manual testing
|
1387
|
-
```
|
1388
|
-
|
1389
|
-
5. **Rails 8 Feature Integration**
|
1390
|
-
```ruby
|
1391
|
-
# Update authentication patterns
|
1392
|
-
# Before (Rails 7)
|
1393
|
-
user = User.find_by(email: params[:email])&.authenticate(params[:password])
|
1394
|
-
|
1395
|
-
# After (Rails 8)
|
1396
|
-
user = User.authenticate_by(email: params[:email], password: params[:password])
|
1397
|
-
```
|
1398
|
-
|
1399
|
-
**Common Issues & Solutions**:
|
1400
|
-
- ⚠️ **Authentication changes**: Update to Rails 8 `authenticate_by` pattern
|
1401
|
-
- ⚠️ **Asset pipeline changes**: Update asset references for Propshaft
|
1402
|
-
- ⚠️ **New cop violations**: Review and fix new Rails 8 specific rules
|
1403
|
-
|
1404
|
-
</details>
|
1405
|
-
|
1406
|
-
<details>
|
1407
|
-
<summary><strong>📊 Rails 6 → Rails 7 Migration</strong></summary>
|
1408
|
-
|
1409
|
-
**Prerequisites**:
|
1410
|
-
- Ruby 3.0+ (Ruby 3.1+ recommended for best performance)
|
1411
|
-
- RuboCop HK 0.1.0+
|
1412
|
-
- Update all gems to Rails 6.1 compatible versions first
|
1413
|
-
|
1414
|
-
**Migration Strategy**:
|
1415
|
-
|
1416
|
-
1. **Pre-upgrade Preparation**
|
1417
|
-
```bash
|
1418
|
-
# Update to Rails 6.1 first (if not already)
|
1419
|
-
bundle update rails
|
1420
|
-
|
1421
|
-
# Fix any Rails 6 deprecations
|
1422
|
-
bundle exec rake rails:update
|
1423
|
-
|
1424
|
-
# Clean RuboCop state
|
1425
|
-
bundle exec rubocop --autocorrect-all --safe
|
1426
|
-
```
|
1427
|
-
|
1428
|
-
2. **Dependency Updates**
|
1429
|
-
```ruby
|
1430
|
-
# Gemfile updates for Rails 7 compatibility
|
1431
|
-
gem "rails", "~> 7.0.0"
|
1432
|
-
gem "rubocop-hk", "~> 1.1.1"
|
1433
|
-
|
1434
|
-
# Update other gems
|
1435
|
-
gem "rspec-rails", "~> 6.0" # Rails 7 compatible
|
1436
|
-
gem "factory_bot_rails", "~> 6.2"
|
1437
|
-
```
|
1438
|
-
|
1439
|
-
3. **Configuration Updates**
|
1440
|
-
```yaml
|
1441
|
-
# .rubocop.yml - Rails 7 configuration
|
1442
|
-
inherit_gem:
|
1443
|
-
rubocop-hk: config/default.yml
|
1444
|
-
|
1445
|
-
AllCops:
|
1446
|
-
TargetRubyVersion: 3.1
|
1447
|
-
TargetRailsVersion: 7.0 # Updated from 6.x
|
1448
|
-
NewCops: enable
|
1449
|
-
|
1450
|
-
# New Rails 7 cops
|
1451
|
-
Rails/CompactBlank:
|
1452
|
-
Enabled: true
|
1453
|
-
|
1454
|
-
Rails/DuplicateAssociation:
|
1455
|
-
Enabled: true
|
1456
|
-
|
1457
|
-
Rails/I18nLazyLookup:
|
1458
|
-
Enabled: true
|
1459
|
-
```
|
1460
|
-
|
1461
|
-
4. **Code Pattern Updates**
|
1462
|
-
```ruby
|
1463
|
-
# Rails 7 introduces new methods
|
1464
|
-
# Old Rails 6 pattern:
|
1465
|
-
users.reject(&:blank?)
|
1466
|
-
|
1467
|
-
# New Rails 7 pattern (RuboCop HK will suggest):
|
1468
|
-
users.compact_blank
|
1469
|
-
```
|
1470
|
-
|
1471
|
-
**Migration Timeline**:
|
1472
|
-
- **Week 1**: Dependencies and basic Rails upgrade
|
1473
|
-
- **Week 2**: RuboCop configuration update and auto-fixes
|
1474
|
-
- **Week 3**: Manual code review and Rails 7 feature adoption
|
1475
|
-
- **Week 4**: Testing and deployment
|
1476
|
-
|
1477
|
-
</details>
|
1478
|
-
|
1479
|
-
<details>
|
1480
|
-
<summary><strong>🔄 Ruby Version Upgrades</strong></summary>
|
1481
|
-
|
1482
|
-
#### **Ruby 3.1 → Ruby 3.2**
|
1483
|
-
|
1484
|
-
```bash
|
1485
|
-
# Update Ruby version
|
1486
|
-
rvm install 3.2.0 # or rbenv install 3.2.0
|
1487
|
-
rvm use 3.2.0 # or rbenv local 3.2.0
|
1488
|
-
|
1489
|
-
# Update Gemfile
|
1490
|
-
sed -i 's/ruby "3.1"/ruby "3.2"/' Gemfile
|
1491
|
-
|
1492
|
-
# Update RuboCop target
|
1493
|
-
sed -i 's/TargetRubyVersion: 3.1/TargetRubyVersion: 3.2/' .rubocop.yml
|
1494
|
-
|
1495
|
-
# Bundle update
|
1496
|
-
bundle install
|
1497
|
-
bundle exec rubocop
|
1498
|
-
```
|
1499
|
-
|
1500
|
-
#### **Ruby 3.2 → Ruby 3.3**
|
1501
|
-
|
1502
|
-
```bash
|
1503
|
-
# Similar process with additional performance benefits
|
1504
|
-
rvm install 3.3.0
|
1505
|
-
rvm use 3.3.0
|
1506
|
-
|
1507
|
-
# Update configuration for Ruby 3.3 features
|
1508
|
-
cat >> .rubocop.yml << 'EOF'
|
1509
|
-
# Ruby 3.3 performance optimizations
|
1510
|
-
Performance/StringReplacement:
|
1511
|
-
Enabled: true
|
1512
|
-
|
1513
|
-
Performance/MapCompact:
|
1514
|
-
Enabled: true
|
1515
|
-
EOF
|
1516
|
-
```
|
1517
|
-
|
1518
|
-
**Performance Comparison**:
|
1519
|
-
- Ruby 3.1 → 3.2: ~10-15% performance improvement
|
1520
|
-
- Ruby 3.2 → 3.3: ~15-20% performance improvement
|
1521
|
-
- RuboCop run time: ~25% faster on Ruby 3.3 vs 3.1
|
1522
|
-
|
1523
|
-
</details>
|
1524
|
-
|
1525
|
-
<details>
|
1526
|
-
<summary><strong>🔧 RuboCop Version Migrations</strong></summary>
|
1527
|
-
|
1528
|
-
#### **Updating RuboCop Dependencies**
|
1529
|
-
|
1530
|
-
```bash
|
1531
|
-
# Check current versions
|
1532
|
-
bundle exec rubocop --version
|
1533
|
-
gem list | grep rubocop
|
1534
|
-
|
1535
|
-
# Update RuboCop HK (includes all dependencies)
|
1536
|
-
bundle update rubocop-hk
|
1537
|
-
|
1538
|
-
# Or update individual components
|
1539
|
-
bundle update rubocop rubocop-rails rubocop-rspec rubocop-performance
|
1540
|
-
```
|
1541
|
-
|
1542
|
-
#### **Handling New Cops**
|
1543
|
-
|
1544
|
-
```yaml
|
1545
|
-
# Gradual adoption of new cops
|
1546
|
-
AllCops:
|
1547
|
-
NewCops: disable # Start conservative
|
1548
|
-
|
1549
|
-
# Enable specific new cops after evaluation
|
1550
|
-
Style/NewCopName:
|
1551
|
-
Enabled: true
|
1552
|
-
```
|
1553
|
-
|
1554
|
-
#### **Managing Breaking Changes**
|
1555
|
-
|
1556
|
-
```bash
|
1557
|
-
# Generate new TODO file when major updates introduce issues
|
1558
|
-
bundle exec rubocop --auto-gen-config --force
|
1559
|
-
|
1560
|
-
# Gradually reduce TODO file
|
1561
|
-
bundle exec rubocop --regenerate-todo
|
1562
|
-
```
|
1563
|
-
|
1564
|
-
</details>
|
1565
|
-
|
1566
|
-
### 🎯 **Migration Troubleshooting**
|
1567
|
-
|
1568
|
-
<details>
|
1569
|
-
<summary><strong>❌ Common Migration Issues</strong></summary>
|
1570
|
-
|
1571
|
-
#### **Issue: New Cops Breaking CI**
|
1572
|
-
```bash
|
1573
|
-
# Problem: New RuboCop version introduces breaking cops
|
1574
|
-
# Solution: Disable new cops temporarily
|
1575
|
-
echo "AllCops:
|
1576
|
-
NewCops: disable" >> .rubocop.yml
|
1577
|
-
|
1578
|
-
# Then enable them gradually
|
1579
|
-
```
|
1580
|
-
|
1581
|
-
#### **Issue: Rails Version Conflicts**
|
1582
|
-
```bash
|
1583
|
-
# Problem: RuboCop Rails cops not recognizing new Rails version
|
1584
|
-
# Solution: Update target Rails version
|
1585
|
-
sed -i 's/TargetRailsVersion: .*/TargetRailsVersion: 8.0/' .rubocop.yml
|
1586
|
-
```
|
1587
|
-
|
1588
|
-
#### **Issue: Performance Degradation**
|
1589
|
-
```bash
|
1590
|
-
# Problem: RuboCop running slower after upgrade
|
1591
|
-
# Solution: Clear cache and use parallel processing
|
1592
|
-
rm -rf tmp/rubocop_cache
|
1593
|
-
bundle exec rubocop --cache --parallel
|
1594
|
-
```
|
1595
|
-
|
1596
|
-
#### **Issue: Conflicting Style Rules**
|
1597
|
-
```bash
|
1598
|
-
# Problem: Team style conflicts with new defaults
|
1599
|
-
# Solution: Override specific rules
|
1600
|
-
echo "Style/StringLiterals:
|
1601
|
-
EnforcedStyle: single_quotes" >> .rubocop.yml
|
1602
|
-
```
|
1603
|
-
|
1604
|
-
</details>
|
1605
|
-
|
1606
|
-
### 📋 **Migration Checklist**
|
1607
|
-
|
1608
|
-
<details>
|
1609
|
-
<summary><strong>✅ Pre-Migration Checklist</strong></summary>
|
1610
|
-
|
1611
|
-
- [ ] **Backup current configuration**
|
1612
|
-
```bash
|
1613
|
-
cp .rubocop.yml .rubocop.yml.backup.$(date +%Y%m%d)
|
1614
|
-
```
|
1615
|
-
|
1616
|
-
- [ ] **Document current Ruby/Rails versions**
|
1617
|
-
```bash
|
1618
|
-
ruby --version > migration_log.txt
|
1619
|
-
rails --version >> migration_log.txt
|
1620
|
-
bundle exec rubocop --version >> migration_log.txt
|
1621
|
-
```
|
1622
|
-
|
1623
|
-
- [ ] **Clean current RuboCop state**
|
1624
|
-
```bash
|
1625
|
-
bundle exec rubocop # Should pass
|
1626
|
-
```
|
1627
|
-
|
1628
|
-
- [ ] **Full test suite passing**
|
1629
|
-
```bash
|
1630
|
-
bundle exec rspec # or your test command
|
1631
|
-
```
|
1632
|
-
|
1633
|
-
- [ ] **Dependencies audit**
|
1634
|
-
```bash
|
1635
|
-
bundle audit
|
1636
|
-
bundle outdated
|
1637
|
-
```
|
1638
|
-
|
1639
|
-
</details>
|
1640
|
-
|
1641
|
-
<details>
|
1642
|
-
<summary><strong>✅ Post-Migration Checklist</strong></summary>
|
1643
|
-
|
1644
|
-
- [ ] **Verify RuboCop configuration loads**
|
1645
|
-
```bash
|
1646
|
-
bundle exec rubocop --config .rubocop.yml --list-cops > /dev/null
|
1647
|
-
```
|
1648
|
-
|
1649
|
-
- [ ] **Run comprehensive RuboCop check**
|
1650
|
-
```bash
|
1651
|
-
bundle exec rubocop --format progress
|
1652
|
-
```
|
1653
|
-
|
1654
|
-
- [ ] **Verify application starts**
|
1655
|
-
```bash
|
1656
|
-
rails server --environment=development
|
1657
|
-
```
|
1658
|
-
|
1659
|
-
- [ ] **Run full test suite**
|
1660
|
-
```bash
|
1661
|
-
bundle exec rspec
|
1662
|
-
```
|
1663
|
-
|
1664
|
-
- [ ] **Check CI/CD pipeline**
|
1665
|
-
- Ensure CI passes with new configuration
|
1666
|
-
- Update CI Ruby/Rails versions if needed
|
1667
|
-
|
1668
|
-
- [ ] **Update documentation**
|
1669
|
-
- Update README.md with new versions
|
1670
|
-
- Update deployment guides
|
1671
|
-
- Notify team of changes
|
1672
|
-
|
1673
|
-
</details>
|
1674
|
-
|
1675
|
-
## 🏗️ Legacy Migration Guide
|
1676
|
-
|
1677
|
-
### 🔄 **Migrating from Other RuboCop Configurations**
|
1678
|
-
|
1679
|
-
<details>
|
1680
|
-
<summary><strong>📦 From Standard RuboCop</strong></summary>
|
1681
|
-
|
1682
|
-
**Before:**
|
1683
|
-
```yaml
|
1684
|
-
# Old .rubocop.yml
|
1685
|
-
inherit_from: .rubocop_todo.yml
|
1686
|
-
|
1687
|
-
AllCops:
|
1688
|
-
TargetRubyVersion: 2.7
|
1689
|
-
Exclude:
|
1690
|
-
- 'db/migrate/*.rb'
|
1691
|
-
|
1692
|
-
Style/StringLiterals:
|
1693
|
-
EnforcedStyle: single_quotes
|
1694
|
-
```
|
1695
|
-
|
1696
|
-
**After:**
|
1697
|
-
```yaml
|
1698
|
-
# New .rubocop.yml with RuboCop HK
|
1699
|
-
inherit_gem:
|
1700
|
-
rubocop-hk: config/default.yml
|
1701
|
-
|
1702
|
-
inherit_from: .rubocop_todo.yml
|
1703
|
-
|
1704
|
-
AllCops:
|
1705
|
-
TargetRubyVersion: 3.3
|
1706
|
-
TargetRailsVersion: 8.0
|
1707
|
-
|
1708
|
-
# RuboCop HK uses double quotes by default
|
1709
|
-
# Remove Style/StringLiterals override to adopt modern standards
|
1710
|
-
```
|
1711
|
-
|
1712
|
-
**Migration Steps:**
|
1713
|
-
```bash
|
1714
|
-
# 1. Backup current config
|
1715
|
-
cp .rubocop.yml .rubocop.yml.backup
|
1716
|
-
|
1717
|
-
# 2. Install RuboCop HK
|
1718
|
-
bundle add rubocop-hk --group development,test
|
1719
|
-
|
1720
|
-
# 3. Update configuration (see above)
|
1721
|
-
|
1722
|
-
# 4. Generate new TODO for remaining issues
|
1723
|
-
bundle exec rubocop --auto-gen-config --force
|
1724
|
-
|
1725
|
-
# 5. Auto-fix what's possible
|
1726
|
-
bundle exec rubocop --autocorrect-all --safe
|
1727
|
-
```
|
1728
|
-
|
1729
|
-
</details>
|
1730
|
-
|
1731
|
-
<details>
|
1732
|
-
<summary><strong>🏗️ From Shopify's RuboCop Config</strong></summary>
|
1733
|
-
|
1734
|
-
**Key Differences & Migration:**
|
1735
|
-
|
1736
|
-
```yaml
|
1737
|
-
# Shopify config similarities (keep these)
|
1738
|
-
Layout/LineLength:
|
1739
|
-
Max: 120
|
1740
|
-
|
1741
|
-
# RuboCop HK enhancements
|
1742
|
-
Style/StringLiterals:
|
1743
|
-
EnforcedStyle: double_quotes # RuboCop HK standard
|
1744
|
-
|
1745
|
-
Rails/ApplicationController:
|
1746
|
-
Enabled: true # Enhanced Rails rules
|
1747
|
-
|
1748
|
-
# Migration command
|
1749
|
-
bundle remove rubocop-shopify
|
1750
|
-
bundle add rubocop-hk --group development,test
|
1751
|
-
```
|
1752
|
-
|
1753
|
-
</details>
|
1754
|
-
|
1755
|
-
<details>
|
1756
|
-
<summary><strong>⚙️ From Custom Configuration</strong></summary>
|
1757
|
-
|
1758
|
-
**Step-by-Step Migration:**
|
1759
|
-
|
1760
|
-
```bash
|
1761
|
-
# 1. Audit current configuration
|
1762
|
-
bundle exec rubocop --list-cops > current_cops.txt
|
1763
|
-
|
1764
|
-
# 2. Create hybrid configuration
|
1765
|
-
cat > .rubocop.yml << 'EOF'
|
1766
|
-
inherit_gem:
|
1767
|
-
rubocop-hk: config/default.yml
|
1768
|
-
|
1769
|
-
# Preserve your custom rules temporarily
|
1770
|
-
Style/MyCustomRule:
|
1771
|
-
Enabled: true
|
1772
|
-
|
1773
|
-
# Override RuboCop HK rules as needed
|
1774
|
-
Layout/LineLength:
|
1775
|
-
Max: 100 # If you prefer shorter lines
|
1776
|
-
EOF
|
1777
|
-
|
1778
|
-
# 3. Gradual adoption
|
1779
|
-
bundle exec rubocop --auto-gen-config
|
1780
|
-
bundle exec rubocop --autocorrect-all --safe
|
1781
|
-
|
1782
|
-
# 4. Review and clean up overrides over time
|
1783
|
-
```
|
1784
|
-
|
1785
|
-
</details>
|
1786
|
-
|
1787
|
-
### 🎯 **Step-by-Step Migration Process**
|
1788
|
-
|
1789
|
-
1. **Assessment Phase** (Week 1)
|
1790
|
-
```bash
|
1791
|
-
# Analyze current violations
|
1792
|
-
bundle exec rubocop --format json > rubocop-baseline.json
|
1793
|
-
|
1794
|
-
# Count violations by department
|
1795
|
-
bundle exec rubocop --format offenses
|
1796
|
-
```
|
1797
|
-
|
1798
|
-
2. **Setup Phase** (Week 2)
|
1799
|
-
```bash
|
1800
|
-
# Install RuboCop HK
|
1801
|
-
bundle add rubocop-hk --group development,test
|
1802
|
-
|
1803
|
-
# Create migration-friendly config
|
1804
|
-
cat > .rubocop.yml << 'EOF'
|
1805
|
-
inherit_gem:
|
1806
|
-
rubocop-hk: config/default.yml
|
1807
|
-
inherit_from: .rubocop_todo.yml
|
1808
|
-
|
1809
|
-
AllCops:
|
1810
|
-
NewCops: disable # Start conservative
|
1811
|
-
EOF
|
1812
|
-
|
1813
|
-
# Generate TODO file
|
1814
|
-
bundle exec rubocop --auto-gen-config
|
1815
|
-
```
|
1816
|
-
|
1817
|
-
3. **Gradual Adoption** (Weeks 3-8)
|
1818
|
-
```bash
|
1819
|
-
# Week 3: Auto-fix safe issues
|
1820
|
-
bundle exec rubocop --autocorrect --safe
|
1821
|
-
|
1822
|
-
# Week 4: Enable Layout cops
|
1823
|
-
# Week 5: Enable Style cops
|
1824
|
-
# Week 6: Enable Rails cops
|
1825
|
-
# Week 7: Enable Lint cops
|
1826
|
-
# Week 8: Final cleanup
|
1827
|
-
```
|
1828
|
-
|
1829
|
-
---
|
1830
|
-
|
1831
|
-
## 🎯 Real-World Examples
|
1832
|
-
|
1833
|
-
### 🚀 **Startup Team Configuration (2-5 developers)**
|
1834
|
-
|
1835
|
-
**Scenario:** Early-stage startup moving fast, learning Rails best practices
|
1836
|
-
|
1837
|
-
```yaml
|
1838
|
-
# .rubocop.yml - Startup-friendly configuration
|
1839
|
-
inherit_gem:
|
1840
|
-
rubocop-hk: config/default.yml
|
1841
|
-
|
1842
|
-
AllCops:
|
1843
|
-
TargetRubyVersion: 3.3
|
1844
|
-
TargetRailsVersion: 8.0
|
1845
|
-
NewCops: enable
|
1846
|
-
|
1847
|
-
# Relaxed metrics for rapid development
|
1848
|
-
Metrics/ClassLength:
|
1849
|
-
Max: 150
|
1850
|
-
Metrics/MethodLength:
|
1851
|
-
Max: 15
|
1852
|
-
Metrics/BlockLength:
|
1853
|
-
Exclude:
|
1854
|
-
- "spec/**/*"
|
1855
|
-
- "config/**/*"
|
1856
|
-
|
1857
|
-
# Skip documentation requirement initially
|
1858
|
-
Style/Documentation:
|
1859
|
-
Enabled: false
|
1860
|
-
|
1861
|
-
# Allow longer lines for readability
|
1862
|
-
Layout/LineLength:
|
1863
|
-
Max: 120
|
1864
|
-
|
1865
|
-
# Startup-specific exclusions
|
1866
|
-
AllCops:
|
1867
|
-
Exclude:
|
1868
|
-
- "db/data/**/*" # Data migration scripts
|
1869
|
-
- "lib/tasks/**/*" # Rake tasks can be more flexible
|
1870
|
-
- "config/environments/**/*" # Environment configs
|
1871
|
-
```
|
1872
|
-
|
1873
|
-
**Benefits for Startups:**
|
1874
|
-
- ✅ Learn best practices gradually
|
1875
|
-
- ✅ Don't block rapid feature development
|
1876
|
-
- ✅ Establish foundation for growth
|
1877
|
-
- ✅ Easy to tighten rules as team matures
|
1878
|
-
|
1879
|
-
### 🏢 **Enterprise Team Configuration (10+ developers)**
|
1880
|
-
|
1881
|
-
**Scenario:** Large engineering team, strict code quality requirements
|
1882
|
-
|
1883
|
-
```yaml
|
1884
|
-
# .rubocop.yml - Enterprise configuration
|
1885
|
-
inherit_gem:
|
1886
|
-
rubocop-hk: config/default.yml
|
1887
|
-
|
1888
|
-
AllCops:
|
1889
|
-
TargetRubyVersion: 3.2 # Conservative for enterprise
|
1890
|
-
TargetRailsVersion: 7.0
|
1891
|
-
NewCops: disable # Evaluate new cops carefully
|
1892
|
-
|
1893
|
-
# Strict metrics for maintainability
|
1894
|
-
Metrics/ClassLength:
|
1895
|
-
Max: 100
|
1896
|
-
Metrics/MethodLength:
|
1897
|
-
Max: 10
|
1898
|
-
Metrics/CyclomaticComplexity:
|
1899
|
-
Max: 6
|
1900
|
-
Metrics/PerceivedComplexity:
|
1901
|
-
Max: 7
|
1902
|
-
|
1903
|
-
# Mandatory documentation
|
1904
|
-
Style/Documentation:
|
1905
|
-
Enabled: true
|
1906
|
-
Exclude:
|
1907
|
-
- "spec/**/*"
|
1908
|
-
- "test/**/*"
|
1909
|
-
- "db/**/*"
|
1910
|
-
|
1911
|
-
# Strict line length
|
1912
|
-
Layout/LineLength:
|
1913
|
-
Max: 100
|
1914
|
-
|
1915
|
-
# Security-first approach
|
1916
|
-
Security:
|
1917
|
-
Enabled: true
|
1918
|
-
Security/Eval:
|
1919
|
-
Enabled: true
|
1920
|
-
Security/Open:
|
1921
|
-
Enabled: true
|
1922
|
-
|
1923
|
-
# Performance requirements
|
1924
|
-
Performance:
|
1925
|
-
Enabled: true
|
1926
|
-
|
1927
|
-
# Strict RSpec requirements
|
1928
|
-
RSpec/ExampleLength:
|
1929
|
-
Max: 15
|
1930
|
-
RSpec/MultipleExpectations:
|
1931
|
-
Max: 3
|
1932
|
-
RSpec/NestedGroups:
|
1933
|
-
Max: 3
|
1934
|
-
RSpec/DescribedClass:
|
1935
|
-
Enabled: true
|
1936
|
-
```
|
1937
|
-
|
1938
|
-
**Benefits for Enterprise:**
|
1939
|
-
- ✅ Consistent code across large teams
|
1940
|
-
- ✅ Reduced technical debt
|
1941
|
-
- ✅ Enhanced security posture
|
1942
|
-
- ✅ Improved maintainability
|
1943
|
-
|
1944
|
-
### 🌍 **Open Source Project Configuration**
|
1945
|
-
|
1946
|
-
**Scenario:** Community-driven project with contributors worldwide
|
1947
|
-
|
1948
|
-
```yaml
|
1949
|
-
# .rubocop.yml - Open source configuration
|
1950
|
-
inherit_gem:
|
1951
|
-
rubocop-hk: config/default.yml
|
1952
|
-
|
1953
|
-
AllCops:
|
1954
|
-
TargetRubyVersion: 3.1 # Broad compatibility
|
1955
|
-
|
1956
|
-
# Documentation is crucial for open source
|
1957
|
-
Style/Documentation:
|
1958
|
-
Enabled: true
|
1959
|
-
Style/DocumentationMethod:
|
1960
|
-
Enabled: true
|
1961
|
-
|
1962
|
-
# Frozen string literals for performance
|
1963
|
-
Style/FrozenStringLiteralComment:
|
1964
|
-
Enabled: true
|
1965
|
-
|
1966
|
-
# Comprehensive error handling
|
1967
|
-
Style/RescueStandardError:
|
1968
|
-
EnforcedStyle: explicit
|
1969
|
-
|
1970
|
-
# Security for public code
|
1971
|
-
Security:
|
1972
|
-
Enabled: true
|
1973
|
-
|
1974
|
-
# Community-friendly settings
|
1975
|
-
Layout/LineLength:
|
1976
|
-
Max: 120
|
1977
|
-
|
1978
|
-
# Encourage good naming
|
1979
|
-
Naming/AccessorMethodName:
|
1980
|
-
Enabled: true
|
1981
|
-
Naming/PredicateName:
|
1982
|
-
Enabled: true
|
1983
|
-
|
1984
|
-
# Comprehensive testing requirements
|
1985
|
-
RSpec/ExampleLength:
|
1986
|
-
Max: 20 # Allow detailed examples for documentation
|
1987
|
-
RSpec/MultipleExpectations:
|
1988
|
-
Max: 5 # Complex scenarios may need more assertions
|
1989
|
-
```
|
1990
|
-
|
1991
|
-
### 📡 **Rails API-Only Application**
|
1992
|
-
|
1993
|
-
**Scenario:** Microservice or API-only Rails application
|
1994
|
-
|
1995
|
-
```yaml
|
1996
|
-
# .rubocop.yml - API-focused configuration
|
1997
|
-
inherit_gem:
|
1998
|
-
rubocop-hk: config/default.yml
|
1999
|
-
|
2000
|
-
AllCops:
|
2001
|
-
TargetRubyVersion: 3.3
|
2002
|
-
TargetRailsVersion: 8.0
|
2003
|
-
|
2004
|
-
# API-specific Rails rules
|
2005
|
-
Rails/ApplicationController:
|
2006
|
-
Enabled: true
|
2007
|
-
Rails/ApplicationRecord:
|
2008
|
-
Enabled: true
|
2009
|
-
|
2010
|
-
# Disable view-related cops
|
2011
|
-
Rails/OutputSafety:
|
2012
|
-
Enabled: false
|
2013
|
-
Rails/LinkToBlank:
|
2014
|
-
Enabled: false
|
2015
|
-
Rails/ContentTag:
|
2016
|
-
Enabled: false
|
2017
|
-
|
2018
|
-
# API response formatting
|
2019
|
-
Style/HashSyntax:
|
2020
|
-
EnforcedStyle: ruby19_no_mixed_keys
|
2021
|
-
Style/StringHashKeys:
|
2022
|
-
Enabled: false # Allow string keys in API responses
|
2023
|
-
|
2024
|
-
# JSON serialization patterns
|
2025
|
-
Layout/HashAlignment:
|
2026
|
-
EnforcedHashRocketStyle: key
|
2027
|
-
EnforcedColonStyle: key
|
2028
|
-
|
2029
|
-
# API testing patterns
|
2030
|
-
RSpec/ExampleLength:
|
2031
|
-
Max: 30 # API integration tests can be longer
|
2032
|
-
|
2033
|
-
# Exclude API documentation
|
2034
|
-
AllCops:
|
2035
|
-
Exclude:
|
2036
|
-
- "app/views/**/*" # No views in API-only
|
2037
|
-
- "app/helpers/**/*" # No view helpers
|
2038
|
-
- "public/**/*"
|
2039
|
-
```
|
2040
|
-
|
2041
|
-
### 🎪 **Microservices Architecture**
|
2042
|
-
|
2043
|
-
**Scenario:** Multiple small services with shared standards
|
2044
|
-
|
2045
|
-
```yaml
|
2046
|
-
# .rubocop.yml - Microservice template
|
2047
|
-
inherit_gem:
|
2048
|
-
rubocop-hk: config/default.yml
|
2049
|
-
|
2050
|
-
AllCops:
|
2051
|
-
TargetRubyVersion: 3.3
|
2052
|
-
TargetRailsVersion: 8.0
|
2053
|
-
|
2054
|
-
# Microservice-optimized metrics
|
2055
|
-
Metrics/ClassLength:
|
2056
|
-
Max: 80 # Keep services small
|
2057
|
-
Metrics/MethodLength:
|
2058
|
-
Max: 12 # Focused methods
|
2059
|
-
|
2060
|
-
# Essential for distributed systems
|
2061
|
-
Style/Documentation:
|
2062
|
-
Enabled: true
|
2063
|
-
|
2064
|
-
# Error handling is critical
|
2065
|
-
Style/RescueStandardError:
|
2066
|
-
EnforcedStyle: explicit
|
2067
|
-
Lint/RescueException:
|
2068
|
-
Enabled: true
|
2069
|
-
|
2070
|
-
# Performance matters in microservices
|
2071
|
-
Performance:
|
2072
|
-
Enabled: true
|
2073
|
-
Performance/StringReplacement:
|
2074
|
-
Enabled: true
|
2075
|
-
|
2076
|
-
# Container-friendly exclusions
|
2077
|
-
AllCops:
|
2078
|
-
Exclude:
|
2079
|
-
- "docker/**/*"
|
2080
|
-
- "k8s/**/*"
|
2081
|
-
- "helm/**/*"
|
2082
|
-
```
|
2083
|
-
|
2084
|
-
---
|
2085
|
-
|
2086
|
-
## 🎨 Modern Rails Conventions
|
2087
|
-
|
2088
|
-
### 🚀 **Rails 8 Patterns & Best Practices**
|
2089
|
-
|
2090
|
-
#### 🔍 **Modern Query Methods**
|
2091
|
-
|
2092
|
-
```ruby
|
2093
|
-
# ✅ Rails 6-8 preferred patterns
|
2094
|
-
user = User.find_by(email: params[:email])
|
2095
|
-
users = User.where(status: :active).limit(10)
|
2096
|
-
recent_posts = Post.includes(:author).recent.published
|
2097
|
-
|
2098
|
-
# ❌ Legacy patterns to avoid
|
2099
|
-
user = User.find_by_email(params[:email]) # Deprecated
|
2100
|
-
users = User.find(:all, conditions: {status: "active"}) # Rails 2 style
|
2101
|
-
```
|
2102
|
-
|
2103
|
-
#### 🔐 **Rails 8 Authentication Patterns**
|
2104
|
-
|
2105
|
-
```ruby
|
2106
|
-
# ✅ Rails 8 authentication (new pattern)
|
2107
|
-
class SessionsController < ApplicationController
|
2108
|
-
def create
|
2109
|
-
user = User.authenticate_by(email: params[:email], password: params[:password])
|
2110
|
-
|
2111
|
-
if user
|
2112
|
-
login(user)
|
2113
|
-
redirect_to dashboard_path, notice: "Welcome back!"
|
2114
|
-
else
|
2115
|
-
redirect_to login_path, alert: "Invalid credentials"
|
2116
|
-
end
|
2117
|
-
end
|
2118
|
-
|
2119
|
-
private
|
2120
|
-
|
2121
|
-
def login(user)
|
2122
|
-
session[:user_id] = user.id
|
2123
|
-
end
|
2124
|
-
end
|
2125
|
-
|
2126
|
-
# ✅ Rails 8 User model with authentication
|
2127
|
-
class User < ApplicationRecord
|
2128
|
-
has_secure_password
|
2129
|
-
|
2130
|
-
# New Rails 8 method
|
2131
|
-
def self.authenticate_by(email:, password:)
|
2132
|
-
find_by(email: email)&.authenticate(password)
|
2133
|
-
end
|
2134
|
-
end
|
2135
|
-
```
|
2136
|
-
|
2137
|
-
#### 🏗️ **Modern Controller Patterns**
|
2138
|
-
|
2139
|
-
```ruby
|
2140
|
-
# ✅ Rails 8 controller best practices
|
2141
|
-
class UsersController < ApplicationController
|
2142
|
-
before_action :authenticate_user!
|
2143
|
-
before_action :set_user, only: [:show, :edit, :update, :destroy]
|
2144
|
-
|
2145
|
-
def index
|
2146
|
-
@users = User.includes(:profile)
|
2147
|
-
.where(active: true)
|
2148
|
-
.page(params[:page])
|
2149
|
-
.per(20)
|
2150
|
-
end
|
2151
|
-
|
2152
|
-
def create
|
2153
|
-
@user = User.new(user_params)
|
2154
|
-
|
2155
|
-
if @user.save
|
2156
|
-
redirect_to @user, notice: "User created successfully."
|
2157
|
-
else
|
2158
|
-
render :new, status: :unprocessable_entity
|
2159
|
-
end
|
2160
|
-
end
|
2161
|
-
|
2162
|
-
private
|
2163
|
-
|
2164
|
-
def set_user
|
2165
|
-
@user = User.find(params[:id])
|
2166
|
-
end
|
2167
|
-
|
2168
|
-
def user_params
|
2169
|
-
params.require(:user).permit(:name, :email, :role)
|
2170
|
-
end
|
2171
|
-
end
|
2172
|
-
```
|
2173
|
-
|
2174
|
-
#### 💾 **Rails 8 Caching with Solid Cache**
|
2175
|
-
|
2176
|
-
```ruby
|
2177
|
-
# ✅ Modern Rails 8 caching patterns
|
2178
|
-
class ProductService
|
2179
|
-
def self.featured_products
|
2180
|
-
Rails.cache.fetch("featured_products", expires_in: 1.hour) do
|
2181
|
-
Product.includes(:images).featured.limit(10).to_a
|
2182
|
-
end
|
2183
|
-
end
|
2184
|
-
|
2185
|
-
def self.user_recommendations(user)
|
2186
|
-
cache_key = "recommendations/#{user.cache_key_with_version}"
|
2187
|
-
|
2188
|
-
Rails.cache.fetch(cache_key, expires_in: 30.minutes) do
|
2189
|
-
RecommendationEngine.generate_for(user)
|
2190
|
-
end
|
2191
|
-
end
|
2192
|
-
end
|
2193
|
-
```
|
2194
|
-
|
2195
|
-
#### 📊 **API Development Patterns**
|
2196
|
-
|
2197
|
-
```ruby
|
2198
|
-
# ✅ Rails 8 API controller patterns
|
2199
|
-
class Api::V1::UsersController < ApiController
|
2200
|
-
before_action :authenticate_api_user!
|
2201
|
-
|
2202
|
-
def index
|
2203
|
-
users = User.active.includes(:profile)
|
2204
|
-
|
2205
|
-
render json: {
|
2206
|
-
data: users.map(&:api_representation),
|
2207
|
-
meta: {
|
2208
|
-
total: users.size,
|
2209
|
-
page: params[:page] || 1,
|
2210
|
-
},
|
2211
|
-
}
|
2212
|
-
end
|
2213
|
-
|
2214
|
-
def create
|
2215
|
-
user = User.new(user_params)
|
2216
|
-
|
2217
|
-
if user.save
|
2218
|
-
render json: { data: user.api_representation }, status: :created
|
2219
|
-
else
|
2220
|
-
render json: { errors: user.errors.full_messages }, status: :unprocessable_entity
|
2221
|
-
end
|
2222
|
-
end
|
2223
|
-
|
2224
|
-
private
|
2225
|
-
|
2226
|
-
def user_params
|
2227
|
-
params.require(:user).permit(:name, :email)
|
2228
|
-
end
|
2229
|
-
end
|
2230
|
-
```
|
2231
|
-
|
2232
|
-
#### 🧪 **Modern Testing Conventions**
|
2233
|
-
|
2234
|
-
```ruby
|
2235
|
-
# ✅ RSpec with Rails 8 patterns
|
2236
|
-
RSpec.describe User, type: :model do
|
2237
|
-
describe ".authenticate_by" do
|
2238
|
-
let(:user) { create(:user, email: "user@example.com", password: "password") }
|
2239
|
-
|
2240
|
-
it "returns user with valid credentials" do
|
2241
|
-
result = User.authenticate_by(email: "user@example.com", password: "password")
|
2242
|
-
expect(result).to eq(user)
|
2243
|
-
end
|
2244
|
-
|
2245
|
-
it "returns nil with invalid credentials" do
|
2246
|
-
result = User.authenticate_by(email: "user@example.com", password: "wrong")
|
2247
|
-
expect(result).to be_nil
|
2248
|
-
end
|
2249
|
-
end
|
2250
|
-
end
|
2251
|
-
|
2252
|
-
# ✅ Controller testing with Rails 8
|
2253
|
-
RSpec.describe SessionsController, type: :controller do
|
2254
|
-
describe "POST #create" do
|
2255
|
-
let(:user) { create(:user, email: "test@example.com", password: "password") }
|
2256
|
-
|
2257
|
-
context "with valid credentials" do
|
2258
|
-
it "logs in the user" do
|
2259
|
-
post :create, params: { email: "test@example.com", password: "password" }
|
2260
|
-
|
2261
|
-
expect(session[:user_id]).to eq(user.id)
|
2262
|
-
expect(response).to redirect_to(dashboard_path)
|
2263
|
-
end
|
2264
|
-
end
|
2265
|
-
|
2266
|
-
context "with invalid credentials" do
|
2267
|
-
it "rejects the login" do
|
2268
|
-
post :create, params: { email: "test@example.com", password: "wrong" }
|
2269
|
-
|
2270
|
-
expect(session[:user_id]).to be_nil
|
2271
|
-
expect(response).to redirect_to(login_path)
|
2272
|
-
end
|
2273
|
-
end
|
2274
|
-
end
|
2275
|
-
end
|
2276
|
-
```
|
2277
|
-
|
2278
|
-
### ✨ **String Literals**
|
2279
|
-
|
2280
|
-
```ruby
|
2281
|
-
# ✅ Preferred - Double quotes everywhere for consistency
|
2282
|
-
message = "Hello, world!"
|
2283
|
-
greeting = "Welcome, #{user.name}!"
|
2284
|
-
multiline = "Line 1\nLine 2"
|
2285
|
-
sql_query = "SELECT * FROM users WHERE active = true"
|
2286
|
-
|
2287
|
-
# ❌ Avoid - Single quotes (inconsistent with interpolation)
|
2288
|
-
message = 'Hello, world!' # Inconsistent
|
2289
|
-
interpolation = 'Hello, ' + name # Inefficient concatenation
|
2290
|
-
```
|
2291
|
-
|
2292
|
-
### 🏗️ **Method Definitions**
|
2293
|
-
|
2294
|
-
```ruby
|
2295
|
-
# ✅ Preferred - Always use parentheses for clarity
|
2296
|
-
def calculate_total(items, tax_rate: 0.0)
|
2297
|
-
subtotal = items.sum(&:price)
|
2298
|
-
subtotal * (1 + tax_rate)
|
2299
|
-
end
|
2300
|
-
|
2301
|
-
def current_user_count
|
2302
|
-
User.active.count
|
2303
|
-
end
|
2304
|
-
|
2305
|
-
# ✅ Use keyword arguments for better readability
|
2306
|
-
def send_notification(user:, message:, urgent: false)
|
2307
|
-
NotificationService.deliver(
|
2308
|
-
recipient: user,
|
2309
|
-
content: message,
|
2310
|
-
priority: urgent ? :high : :normal,
|
2311
|
-
)
|
2312
|
-
end
|
2313
|
-
|
2314
|
-
# ❌ Avoid - Inconsistent parentheses and positional args
|
2315
|
-
def process_order items, options={} # Hard to read and maintain
|
2316
|
-
# ...
|
2317
|
-
end
|
2318
|
-
```
|
2319
|
-
|
2320
|
-
### 🎯 **Trailing Commas**
|
2321
|
-
|
2322
|
-
```ruby
|
2323
|
-
# ✅ Preferred - Consistent trailing commas for better diffs
|
2324
|
-
user_attributes = {
|
2325
|
-
name: "John",
|
2326
|
-
email: "john@example.com",
|
2327
|
-
role: "admin", # <- Trailing comma
|
2328
|
-
}
|
2329
|
-
|
2330
|
-
tags = [
|
2331
|
-
"ruby",
|
2332
|
-
"rails",
|
2333
|
-
"programming", # <- Trailing comma
|
2334
|
-
]
|
2335
|
-
|
2336
|
-
method_call(
|
2337
|
-
first_param,
|
2338
|
-
second_param,
|
2339
|
-
third_param, # <- Trailing comma in method calls
|
2340
|
-
)
|
2341
|
-
|
2342
|
-
# Benefits:
|
2343
|
-
# ✅ Cleaner git diffs when adding/removing items
|
2344
|
-
# ✅ Easier to reorder items
|
2345
|
-
# ✅ Consistent formatting across the codebase
|
2346
|
-
# ✅ Reduces merge conflicts
|
2347
|
-
```
|
2348
|
-
|
2349
|
-
### 🔒 **Enhanced Security Practices**
|
2350
|
-
|
2351
|
-
```ruby
|
2352
|
-
# ✅ Rails 8 security best practices
|
2353
|
-
class ApplicationController < ActionController::Base
|
2354
|
-
# CSRF protection (enabled by default in Rails 8)
|
2355
|
-
protect_from_forgery with: :exception
|
2356
|
-
|
2357
|
-
# Content Security Policy
|
2358
|
-
content_security_policy do |policy|
|
2359
|
-
policy.default_src :self
|
2360
|
-
policy.script_src :self, :https
|
2361
|
-
policy.style_src :self, :https, :unsafe_inline
|
2362
|
-
end
|
2363
|
-
|
2364
|
-
private
|
2365
|
-
|
2366
|
-
# Strong parameters with explicit allowlisting
|
2367
|
-
def user_params
|
2368
|
-
params.require(:user).permit(
|
2369
|
-
:name,
|
2370
|
-
:email,
|
2371
|
-
profile_attributes: [:bio, :avatar],
|
2372
|
-
)
|
2373
|
-
end
|
2374
|
-
|
2375
|
-
# Secure headers
|
2376
|
-
def set_security_headers
|
2377
|
-
response.headers["X-Frame-Options"] = "DENY"
|
2378
|
-
response.headers["X-Content-Type-Options"] = "nosniff"
|
2379
|
-
response.headers["Referrer-Policy"] = "strict-origin-when-cross-origin"
|
2380
|
-
end
|
2381
|
-
end
|
2382
|
-
|
2383
|
-
# ✅ Secure model validations
|
2384
|
-
class User < ApplicationRecord
|
2385
|
-
validates :email,
|
2386
|
-
presence: true,
|
2387
|
-
uniqueness: { case_sensitive: false },
|
2388
|
-
format: { with: URI::MailTo::EMAIL_REGEXP }
|
2389
|
-
|
2390
|
-
validates :password,
|
2391
|
-
length: { minimum: 8 },
|
2392
|
-
confirmation: true,
|
2393
|
-
if: :password_required?
|
2394
|
-
|
2395
|
-
# Sanitize user input
|
2396
|
-
before_save :normalize_email
|
2397
|
-
|
2398
|
-
private
|
2399
|
-
|
2400
|
-
def normalize_email
|
2401
|
-
self.email = email.downcase.strip if email.present?
|
2402
|
-
end
|
2403
|
-
end
|
2404
|
-
```
|
2405
|
-
|
2406
|
-
**👉 For complete style guide, see [STYLEGUIDE.md](STYLEGUIDE.md)**
|
2407
|
-
|
2408
|
-
---
|
2409
|
-
|
2410
|
-
## 🔧 Editor Integration
|
2411
|
-
|
2412
|
-
### 💙 **Visual Studio Code**
|
2413
|
-
|
2414
|
-
<details>
|
2415
|
-
<summary><strong>🛠️ Setup Instructions</strong></summary>
|
2416
|
-
|
2417
|
-
1. **Install Ruby extension:**
|
2418
|
-
```
|
2419
|
-
code --install-extension rebornix.Ruby
|
2420
|
-
```
|
2421
|
-
|
2422
|
-
2. **Configure settings** (`.vscode/settings.json`):
|
2423
|
-
```json
|
2424
|
-
{
|
2425
|
-
"ruby.rubocop.executePath": "bundle exec",
|
2426
|
-
"ruby.rubocop.configFilePath": ".rubocop.yml",
|
2427
|
-
"ruby.format": "rubocop",
|
2428
|
-
"[ruby]": {
|
2429
|
-
"editor.formatOnSave": true,
|
2430
|
-
"editor.defaultFormatter": "rebornix.Ruby"
|
2431
|
-
},
|
2432
|
-
"ruby.rubocop.autocorrect": true
|
2433
|
-
}
|
2434
|
-
```
|
2435
|
-
|
2436
|
-
3. **Keyboard shortcuts** (`.vscode/keybindings.json`):
|
2437
|
-
```json
|
2438
|
-
[
|
2439
|
-
{
|
2440
|
-
"key": "ctrl+alt+f",
|
2441
|
-
"command": "ruby.rubocop.autocorrect",
|
2442
|
-
"when": "editorLangId == ruby"
|
2443
|
-
}
|
2444
|
-
]
|
2445
|
-
```
|
2446
|
-
|
2447
|
-
</details>
|
2448
|
-
|
2449
|
-
### 💚 **Sublime Text**
|
2450
|
-
|
2451
|
-
<details>
|
2452
|
-
<summary><strong>🛠️ Setup Instructions</strong></summary>
|
2453
|
-
|
2454
|
-
1. **Install Package Control** and then install:
|
2455
|
-
- SublimeLinter
|
2456
|
-
- SublimeLinter-rubocop
|
2457
|
-
|
2458
|
-
2. **Configure** (`Preferences > Package Settings > SublimeLinter > Settings`):
|
2459
|
-
```json
|
2460
|
-
{
|
2461
|
-
"linters": {
|
2462
|
-
"rubocop": {
|
2463
|
-
"executable": ["bundle", "exec", "rubocop"]
|
2464
|
-
}
|
2465
|
-
}
|
2466
|
-
}
|
2467
|
-
```
|
2468
|
-
|
2469
|
-
</details>
|
2470
|
-
|
2471
|
-
### 🟣 **Vim/Neovim**
|
2472
|
-
|
2473
|
-
<details>
|
2474
|
-
<summary><strong>🛠️ Setup Instructions</strong></summary>
|
2475
|
-
|
2476
|
-
**Using ALE (Asynchronous Lint Engine):**
|
2477
|
-
|
2478
|
-
```vim
|
2479
|
-
" Install ALE plugin first
|
2480
|
-
Plug 'dense-analysis/ale'
|
2481
|
-
|
2482
|
-
" Configure RuboCop
|
2483
|
-
let g:ale_ruby_rubocop_executable = 'bundle exec rubocop'
|
2484
|
-
let g:ale_ruby_rubocop_options = '--autocorrect'
|
2485
|
-
let g:ale_fixers = {
|
2486
|
-
\ 'ruby': ['rubocop'],
|
2487
|
-
\}
|
2488
|
-
let g:ale_fix_on_save = 1
|
2489
|
-
```
|
2490
|
-
|
2491
|
-
</details>
|
2492
|
-
|
2493
|
-
### 🔵 **IntelliJ IDEA / RubyMine**
|
2494
|
-
|
2495
|
-
<details>
|
2496
|
-
<summary><strong>🛠️ Setup Instructions</strong></summary>
|
2497
|
-
|
2498
|
-
1. **Go to:** `Settings > Tools > External Tools`
|
2499
|
-
2. **Add new tool:**
|
2500
|
-
- Name: `RuboCop AutoCorrect`
|
2501
|
-
- Program: `bundle`
|
2502
|
-
- Arguments: `exec rubocop --autocorrect $FilePathRelativeToProjectRoot$`
|
2503
|
-
3. **Add keyboard shortcut** in `Settings > Keymap`
|
2504
|
-
|
2505
|
-
</details>
|
2506
|
-
|
2507
|
-
---
|
2508
|
-
|
2509
|
-
## 🐳 Docker Support
|
2510
|
-
|
2511
|
-
### 🚀 **Quick Docker Setup**
|
2512
|
-
|
2513
|
-
<details>
|
2514
|
-
<summary><strong>📦 Dockerfile Example</strong></summary>
|
2515
|
-
|
2516
|
-
```dockerfile
|
2517
|
-
FROM ruby:3.3-alpine
|
2518
|
-
|
2519
|
-
# Install dependencies
|
2520
|
-
RUN apk add --no-cache \
|
2521
|
-
build-base \
|
2522
|
-
git \
|
2523
|
-
linux-headers
|
2524
|
-
|
2525
|
-
# Set working directory
|
2526
|
-
WORKDIR /app
|
2527
|
-
|
2528
|
-
# Copy Gemfile
|
2529
|
-
COPY Gemfile Gemfile.lock ./
|
2530
|
-
|
2531
|
-
# Install gems
|
2532
|
-
RUN bundle install --jobs 4 --retry 3
|
2533
|
-
|
2534
|
-
# Copy application
|
2535
|
-
COPY . .
|
2536
|
-
|
2537
|
-
# Run RuboCop
|
2538
|
-
CMD ["bundle", "exec", "rubocop"]
|
2539
|
-
```
|
2540
|
-
|
2541
|
-
</details>
|
2542
|
-
|
2543
|
-
<details>
|
2544
|
-
<summary><strong>🐳 Docker Compose for CI</strong></summary>
|
2545
|
-
|
2546
|
-
```yaml
|
2547
|
-
version: '3.8'
|
2548
|
-
services:
|
2549
|
-
rubocop:
|
2550
|
-
build: .
|
2551
|
-
volumes:
|
2552
|
-
- .:/app
|
2553
|
-
- bundle_cache:/usr/local/bundle
|
2554
|
-
command: bundle exec rubocop --format json --out rubocop-results.json
|
2555
|
-
|
2556
|
-
volumes:
|
2557
|
-
bundle_cache:
|
2558
|
-
```
|
2559
|
-
|
2560
|
-
</details>
|
2561
|
-
|
2562
|
-
<details>
|
2563
|
-
<summary><strong>⚡ One-liner Docker Command</strong></summary>
|
2564
|
-
|
2565
|
-
```bash
|
2566
|
-
# Run RuboCop in Docker without building an image
|
2567
|
-
docker run --rm -v $(pwd):/app -w /app ruby:3.3 \
|
2568
|
-
bash -c "gem install rubocop-hk -v '~> 1.0.0' && rubocop --autocorrect"
|
2569
|
-
```
|
2570
|
-
|
2571
|
-
</details>
|
2572
|
-
|
2573
|
-
---
|
2574
|
-
|
2575
|
-
## 📈 CI/CD Integration
|
2576
|
-
|
2577
|
-
### 🏃♂️ **GitHub Actions**
|
2578
|
-
|
2579
|
-
<details>
|
2580
|
-
<summary><strong>🔧 Complete Workflow</strong></summary>
|
2581
|
-
|
2582
|
-
```yaml
|
2583
|
-
# .github/workflows/rubocop.yml
|
2584
|
-
name: 🔧 RuboCop Code Quality
|
2585
|
-
|
2586
|
-
on:
|
2587
|
-
push:
|
2588
|
-
branches: [ main, develop ]
|
2589
|
-
pull_request:
|
2590
|
-
branches: [ main ]
|
2591
|
-
|
2592
|
-
jobs:
|
2593
|
-
rubocop:
|
2594
|
-
name: 🔍 RuboCop Analysis
|
2595
|
-
runs-on: ubuntu-latest
|
2596
|
-
|
2597
|
-
steps:
|
2598
|
-
- name: 📥 Checkout code
|
2599
|
-
uses: actions/checkout@v4
|
2600
|
-
|
2601
|
-
- name: 💎 Setup Ruby
|
2602
|
-
uses: ruby/setup-ruby@v1
|
2603
|
-
with:
|
2604
|
-
ruby-version: 3.3
|
2605
|
-
bundler-cache: true
|
2606
|
-
|
2607
|
-
- name: 📋 Cache RuboCop
|
2608
|
-
uses: actions/cache@v3
|
2609
|
-
with:
|
2610
|
-
path: ~/.cache/rubocop_cache
|
2611
|
-
key: ${{ runner.os }}-rubocop-${{ hashFiles('.rubocop.yml') }}
|
2612
|
-
|
2613
|
-
- name: 🔍 Run RuboCop
|
2614
|
-
run: |
|
2615
|
-
bundle exec rubocop \
|
2616
|
-
--format github \
|
2617
|
-
--format json \
|
2618
|
-
--out rubocop-results.json
|
2619
|
-
|
2620
|
-
- name: 📊 Upload Results
|
2621
|
-
uses: actions/upload-artifact@v3
|
2622
|
-
if: always()
|
2623
|
-
with:
|
2624
|
-
name: rubocop-results
|
2625
|
-
path: rubocop-results.json
|
2626
|
-
```
|
2627
|
-
|
2628
|
-
</details>
|
2629
|
-
|
2630
|
-
### 🦊 **GitLab CI**
|
2631
|
-
|
2632
|
-
<details>
|
2633
|
-
<summary><strong>🔧 Pipeline Configuration</strong></summary>
|
2634
|
-
|
2635
|
-
```yaml
|
2636
|
-
# .gitlab-ci.yml
|
2637
|
-
stages:
|
2638
|
-
- quality
|
2639
|
-
|
2640
|
-
🔧 RuboCop:
|
2641
|
-
stage: quality
|
2642
|
-
image: ruby:3.3
|
2643
|
-
cache:
|
2644
|
-
key: gems-cache
|
2645
|
-
paths:
|
2646
|
-
- vendor/ruby
|
2647
|
-
before_script:
|
2648
|
-
- bundle config set --local path vendor/ruby
|
2649
|
-
- bundle install --jobs $(nproc)
|
2650
|
-
script:
|
2651
|
-
- bundle exec rubocop --format junit --out rubocop-results.xml
|
2652
|
-
artifacts:
|
2653
|
-
reports:
|
2654
|
-
junit: rubocop-results.xml
|
2655
|
-
paths:
|
2656
|
-
- rubocop-results.xml
|
2657
|
-
expire_in: 1 week
|
2658
|
-
only:
|
2659
|
-
- merge_requests
|
2660
|
-
- main
|
2661
|
-
```
|
2662
|
-
|
2663
|
-
</details>
|
2664
|
-
|
2665
|
-
### 🔄 **Circle CI**
|
2666
|
-
|
2667
|
-
<details>
|
2668
|
-
<summary><strong>🔧 Configuration</strong></summary>
|
2669
|
-
|
2670
|
-
```yaml
|
2671
|
-
# .circleci/config.yml
|
2672
|
-
version: 2.1
|
2673
|
-
|
2674
|
-
executors:
|
2675
|
-
ruby-executor:
|
2676
|
-
docker:
|
2677
|
-
- image: cimg/ruby:3.3
|
2678
|
-
working_directory: ~/project
|
2679
|
-
|
2680
|
-
jobs:
|
2681
|
-
rubocop:
|
2682
|
-
executor: ruby-executor
|
2683
|
-
steps:
|
2684
|
-
- checkout
|
2685
|
-
- restore_cache:
|
2686
|
-
keys:
|
2687
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
2688
|
-
- run:
|
2689
|
-
name: 📦 Install dependencies
|
2690
|
-
command: bundle install --jobs=4 --retry=3 --path vendor/bundle
|
2691
|
-
- save_cache:
|
2692
|
-
paths:
|
2693
|
-
- ./vendor/bundle
|
2694
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
2695
|
-
- run:
|
2696
|
-
name: 🔍 Run RuboCop
|
2697
|
-
command: |
|
2698
|
-
mkdir -p test-results/rubocop
|
2699
|
-
bundle exec rubocop --format RspecJunitFormatter \
|
2700
|
-
--out test-results/rubocop/results.xml
|
2701
|
-
- store_test_results:
|
2702
|
-
path: test-results
|
2703
|
-
|
2704
|
-
workflows:
|
2705
|
-
version: 2
|
2706
|
-
test:
|
2707
|
-
jobs:
|
2708
|
-
- rubocop
|
2709
|
-
```
|
2710
|
-
|
2711
|
-
</details>
|
2712
|
-
|
2713
|
-
### 🎯 **Jenkins**
|
2714
|
-
|
2715
|
-
<details>
|
2716
|
-
<summary><strong>🔧 Pipeline Script</strong></summary>
|
2717
|
-
|
2718
|
-
```groovy
|
2719
|
-
pipeline {
|
2720
|
-
agent any
|
2721
|
-
|
2722
|
-
environment {
|
2723
|
-
BUNDLE_PATH = "${WORKSPACE}/vendor/bundle"
|
2724
|
-
}
|
2725
|
-
|
2726
|
-
stages {
|
2727
|
-
stage('🔧 Setup') {
|
2728
|
-
steps {
|
2729
|
-
sh 'bundle config set --local path ${BUNDLE_PATH}'
|
2730
|
-
sh 'bundle install --jobs 4'
|
2731
|
-
}
|
2732
|
-
}
|
2733
|
-
|
2734
|
-
stage('🔍 RuboCop Analysis') {
|
2735
|
-
steps {
|
2736
|
-
sh '''
|
2737
|
-
bundle exec rubocop \
|
2738
|
-
--format json \
|
2739
|
-
--out rubocop-results.json \
|
2740
|
-
--format junit \
|
2741
|
-
--out rubocop-junit.xml
|
2742
|
-
'''
|
2743
|
-
}
|
2744
|
-
post {
|
2745
|
-
always {
|
2746
|
-
archiveArtifacts artifacts: 'rubocop-*.json,rubocop-*.xml'
|
2747
|
-
publishTestResults testResultsPattern: 'rubocop-junit.xml'
|
2748
|
-
}
|
2749
|
-
}
|
2750
|
-
}
|
2751
|
-
}
|
2752
|
-
}
|
2753
|
-
```
|
2754
|
-
|
2755
|
-
</details>
|
2756
|
-
|
2757
|
-
---
|
2758
|
-
|
2759
|
-
### 🏭 **Production Version Recommendations**
|
2760
|
-
|
2761
|
-
<details>
|
2762
|
-
<summary><strong>🏆 Best Version Combinations for Production (2025)</strong></summary>
|
2763
|
-
|
2764
|
-
#### **🥇 Tier 1: Recommended for New Projects**
|
2765
|
-
|
2766
|
-
| Combination | Stability | Performance | Support | Use Case |
|
2767
|
-
|:------------|:----------|:-----------|:--------|:---------|
|
2768
|
-
| **Ruby 3.3 + Rails 8.0** | ⭐⭐⭐⭐⭐ | ⚡⚡⚡⚡⚡ | 🛡️ 5+ years | New applications, greenfield projects |
|
2769
|
-
| **Ruby 3.2 + Rails 7.2** | ⭐⭐⭐⭐⭐ | ⚡⚡⚡⚡ | 🛡️ 4+ years | Enterprise applications, risk-averse teams |
|
2770
|
-
|
2771
|
-
#### **🥈 Tier 2: Solid Production Choices**
|
2772
|
-
|
2773
|
-
| Combination | Stability | Performance | Support | Use Case |
|
2774
|
-
|:------------|:----------|:-----------|:--------|:---------|
|
2775
|
-
| **Ruby 3.2 + Rails 8.0** | ⭐⭐⭐⭐ | ⚡⚡⚡⚡⚡ | 🛡️ 4+ years | Balanced approach, good performance |
|
2776
|
-
| **Ruby 3.3 + Rails 7.1** | ⭐⭐⭐⭐ | ⚡⚡⚡⚡ | 🛡️ 3+ years | Latest Ruby with stable Rails |
|
2777
|
-
| **Ruby 3.1 + Rails 7.0** | ⭐⭐⭐⭐ | ⚡⚡⚡ | 🛡️ 2+ years | Conservative enterprise choice |
|
2778
|
-
|
2779
|
-
#### **🥉 Tier 3: Maintenance Mode**
|
2780
|
-
|
2781
|
-
| Combination | Stability | Performance | Support | Use Case |
|
2782
|
-
|:------------|:----------|:-----------|:--------|:---------|
|
2783
|
-
| **Ruby 3.1 + Rails 6.1** | ⭐⭐⭐ | ⚡⚡ | 🛡️ 1+ year | Legacy applications only |
|
2784
|
-
|
2785
|
-
**Production Deployment Checklist**:
|
2786
|
-
```bash
|
2787
|
-
# Before deploying to production
|
2788
|
-
bundle exec rubocop --fail-level error # Zero tolerance
|
2789
|
-
bundle exec rspec # Full test suite
|
2790
|
-
bundle audit # Security check
|
2791
|
-
bundle outdated # Dependency check
|
2792
|
-
```
|
2793
|
-
|
2794
|
-
</details>
|
2795
|
-
|
2796
|
-
<details>
|
2797
|
-
<summary><strong>⚡ Performance Benchmarks by Version</strong></summary>
|
2798
|
-
|
2799
|
-
#### **RuboCop Execution Time (1000 files)**
|
2800
|
-
|
2801
|
-
| Ruby Version | Rails Version | Execution Time | Memory Usage | Relative Performance |
|
2802
|
-
|:-------------|:--------------|:---------------|:-------------|:---------------------|
|
2803
|
-
| **Ruby 3.3** | Rails 8.0 | 12s | 180MB | 🚀 **Baseline (100%)** |
|
2804
|
-
| **Ruby 3.2** | Rails 8.0 | 14s | 195MB | 🏃 **85% performance** |
|
2805
|
-
| **Ruby 3.3** | Rails 7.2 | 13s | 175MB | 🏃 **92% performance** |
|
2806
|
-
| **Ruby 3.2** | Rails 7.1 | 15s | 200MB | 🚶 **80% performance** |
|
2807
|
-
| **Ruby 3.1** | Rails 7.0 | 18s | 220MB | 🐌 **67% performance** |
|
2808
|
-
| **Ruby 3.1** | Rails 6.1 | 22s | 240MB | 🐌 **55% performance** |
|
2809
|
-
|
2810
|
-
**Performance Optimization Tips**:
|
2811
|
-
```bash
|
2812
|
-
# Use parallel processing (2x speed improvement)
|
2813
|
-
bundle exec rubocop --parallel
|
2814
|
-
|
2815
|
-
# Enable caching (3x speed improvement on subsequent runs)
|
2816
|
-
export RUBOCOP_OPTS="--cache --parallel"
|
2817
|
-
|
2818
|
-
# For CI environments
|
2819
|
-
export RUBOCOP_CACHE_ROOT="tmp/rubocop_cache"
|
2820
|
-
```
|
2821
|
-
|
2822
|
-
#### **Memory Usage Optimization**
|
2823
|
-
|
2824
|
-
```yaml
|
2825
|
-
# .rubocop.yml - Memory-optimized for large codebases
|
2826
|
-
AllCops:
|
2827
|
-
# Limit file processing for memory-constrained environments
|
2828
|
-
MaxFilesInCache: 5000
|
2829
|
-
|
2830
|
-
# Optimize exclusions to reduce memory footprint
|
2831
|
-
Exclude:
|
2832
|
-
- "**/*.log"
|
2833
|
-
- "tmp/**/*"
|
2834
|
-
- "node_modules/**/*"
|
2835
|
-
- "public/assets/**/*"
|
2836
|
-
- "vendor/bundle/**/*"
|
2837
|
-
```
|
2838
|
-
|
2839
|
-
</details>
|
2840
|
-
|
2841
|
-
<details>
|
2842
|
-
<summary><strong>🔒 Security Considerations by Version</strong></summary>
|
2843
|
-
|
2844
|
-
#### **Security Support Timeline**
|
2845
|
-
|
2846
|
-
| Version | Security Support Until | Risk Level | Recommendation |
|
2847
|
-
|:--------|:----------------------|:-----------|:---------------|
|
2848
|
-
| **Ruby 3.3** | March 2027+ | 🟢 **Low** | ✅ Use in production |
|
2849
|
-
| **Ruby 3.2** | March 2026+ | 🟢 **Low** | ✅ Use in production |
|
2850
|
-
| **Ruby 3.1** | March 2025+ | 🟡 **Medium** | ⚠️ Plan upgrade |
|
2851
|
-
| **Ruby 3.0** | March 2024 | 🔴 **High** | ❌ Upgrade immediately |
|
2852
|
-
| **Rails 8.0** | 2029+ | 🟢 **Low** | ✅ Latest security features |
|
2853
|
-
| **Rails 7.1** | 2026+ | 🟢 **Low** | ✅ Active security support |
|
2854
|
-
| **Rails 7.0** | 2025+ | 🟡 **Medium** | ✅ Security patches only |
|
2855
|
-
| **Rails 6.1** | 2024+ | 🟡 **Medium** | ⚠️ Limited security support |
|
2856
|
-
|
2857
|
-
**Security-Enhanced Configuration**:
|
2858
|
-
```yaml
|
2859
|
-
# .rubocop.yml - Security-first configuration
|
2860
|
-
inherit_gem:
|
2861
|
-
rubocop-hk: config/default.yml
|
2862
|
-
|
2863
|
-
# Enable all security cops
|
2864
|
-
Security:
|
2865
|
-
Enabled: true
|
2866
|
-
|
2867
|
-
Security/Open:
|
2868
|
-
Enabled: true
|
2869
|
-
|
2870
|
-
Security/Eval:
|
2871
|
-
Enabled: true
|
2872
|
-
|
2873
|
-
Security/MarshalLoad:
|
2874
|
-
Enabled: true
|
2875
|
-
|
2876
|
-
# Rails security patterns
|
2877
|
-
Rails/OutputSafety:
|
2878
|
-
Enabled: true
|
2879
|
-
|
2880
|
-
Rails/LinkToBlank:
|
2881
|
-
Enabled: true
|
2882
|
-
```
|
2883
|
-
|
2884
|
-
#### **Vulnerability Scanning Integration**
|
2885
|
-
|
2886
|
-
```bash
|
2887
|
-
# Add to your CI pipeline
|
2888
|
-
bundle audit --update # Check for vulnerabilities
|
2889
|
-
bundle exec rubocop --only Security # Run security cops only
|
2890
|
-
```
|
2891
|
-
|
2892
|
-
</details>
|
2893
|
-
|
2894
|
-
### 📋 **Version-Specific Features & Limitations**
|
2895
|
-
|
2896
|
-
<details>
|
2897
|
-
<summary><strong>🚀 Rails 8 Exclusive Features</strong></summary>
|
2898
|
-
|
2899
|
-
#### **New in Rails 8 (Supported by RuboCop HK)**
|
2900
|
-
|
2901
|
-
- ✅ **Omakase RuboCop Integration** - Works alongside Rails 8's built-in config
|
2902
|
-
- ✅ **Enhanced Authentication** - `authenticate_by` method patterns
|
2903
|
-
- ✅ **Solid Cache Integration** - Modern caching patterns
|
2904
|
-
- ✅ **Propshaft Asset Pipeline** - New asset handling
|
2905
|
-
- ✅ **Kamal Deployment** - Container deployment patterns
|
2906
|
-
- ✅ **Enhanced Performance** - YJIT integration, better memory usage
|
2907
|
-
|
2908
|
-
```ruby
|
2909
|
-
# Rails 8 patterns fully supported by RuboCop HK
|
2910
|
-
class SessionsController < ApplicationController
|
2911
|
-
# New Rails 8 authentication pattern
|
2912
|
-
def create
|
2913
|
-
user = User.authenticate_by(email: params[:email], password: params[:password])
|
2914
|
-
if user
|
2915
|
-
session[:user_id] = user.id
|
2916
|
-
redirect_to dashboard_path
|
2917
|
-
else
|
2918
|
-
redirect_to login_path, alert: "Invalid credentials"
|
2919
|
-
end
|
2920
|
-
end
|
2921
|
-
end
|
2922
|
-
|
2923
|
-
# Solid Cache patterns
|
2924
|
-
class ProductService
|
2925
|
-
def self.trending
|
2926
|
-
Rails.cache.fetch("products:trending", expires_in: 1.hour) do
|
2927
|
-
Product.where("created_at > ?", 1.week.ago)
|
2928
|
-
.order(views_count: :desc)
|
2929
|
-
.limit(10)
|
2930
|
-
end
|
2931
|
-
end
|
2932
|
-
end
|
2933
|
-
```
|
2934
|
-
|
2935
|
-
</details>
|
2936
|
-
|
2937
|
-
<details>
|
2938
|
-
<summary><strong>⭐ Rails 7 Specific Features</strong></summary>
|
2939
|
-
|
2940
|
-
#### **Rails 7.0-7.2 Features (RuboCop HK Enhanced)**
|
2941
|
-
|
2942
|
-
- ✅ **Zeitwerk Autoloader** - Enhanced file organization rules
|
2943
|
-
- ✅ **Hotwire Integration** - Turbo and Stimulus patterns
|
2944
|
-
- ✅ **Encrypted Attributes** - Security-focused rules
|
2945
|
-
- ✅ **ActiveStorage Variants** - Image processing patterns
|
2946
|
-
- ✅ **Parallel Testing** - CI/CD optimizations
|
2947
|
-
|
2948
|
-
```ruby
|
2949
|
-
# Rails 7 patterns with RuboCop HK validation
|
2950
|
-
class User < ApplicationRecord
|
2951
|
-
# Rails 7 encrypted attributes
|
2952
|
-
encrypts :ssn, deterministic: true
|
2953
|
-
encrypts :notes
|
2954
|
-
|
2955
|
-
# Enhanced validation patterns
|
2956
|
-
validates :email, presence: true, uniqueness: { case_sensitive: false }
|
2957
|
-
end
|
2958
|
-
|
2959
|
-
# Hotwire patterns
|
2960
|
-
class PostsController < ApplicationController
|
2961
|
-
def create
|
2962
|
-
@post = Post.new(post_params)
|
2963
|
-
|
2964
|
-
if @post.save
|
2965
|
-
respond_to do |format|
|
2966
|
-
format.html { redirect_to @post }
|
2967
|
-
format.turbo_stream # Rails 7 Turbo integration
|
2968
|
-
end
|
2969
|
-
else
|
2970
|
-
render :new, status: :unprocessable_entity
|
2971
|
-
end
|
2972
|
-
end
|
2973
|
-
end
|
2974
|
-
```
|
2975
|
-
|
2976
|
-
</details>
|
2977
|
-
|
2978
|
-
<details>
|
2979
|
-
<summary><strong>🏗️ Rails 6 Legacy Support</strong></summary>
|
2980
|
-
|
2981
|
-
#### **Rails 6.0-6.1 Limitations & Workarounds**
|
2982
|
-
|
2983
|
-
- ⚠️ **Limited Modern Cops** - Some newer RuboCop rules not applicable
|
2984
|
-
- ⚠️ **Performance Differences** - Slower than Rails 7+
|
2985
|
-
- ⚠️ **Security Patches Only** - Limited feature updates
|
2986
|
-
|
2987
|
-
**Rails 6 Compatibility Configuration**:
|
2988
|
-
```yaml
|
2989
|
-
# .rubocop.yml - Rails 6 specific
|
2990
|
-
inherit_gem:
|
2991
|
-
rubocop-hk: config/default.yml
|
2992
|
-
|
2993
|
-
AllCops:
|
2994
|
-
TargetRailsVersion: 6.1 # Maximum for Rails 6
|
2995
|
-
NewCops: disable # Avoid incompatible cops
|
2996
|
-
|
2997
|
-
# Disable Rails 7+ specific cops
|
2998
|
-
Rails/CompactBlank:
|
2999
|
-
Enabled: false # Not available in Rails 6
|
3000
|
-
|
3001
|
-
Rails/ResponseParsedBody:
|
3002
|
-
Enabled: false # Rails 7+ feature
|
3003
|
-
|
3004
|
-
# Rails 6 specific allowances
|
3005
|
-
Rails/SkipsModelValidations:
|
3006
|
-
AllowedMethods:
|
3007
|
-
- update_attribute # Common in Rails 6 patterns
|
3008
|
-
```
|
3009
|
-
|
3010
|
-
**Upgrade Path from Rails 6**:
|
3011
|
-
```bash
|
3012
|
-
# Phase 1: Prepare (Week 1-2)
|
3013
|
-
bundle update --patch # Security updates only
|
3014
|
-
bundle exec rubocop --autocorrect-all --safe
|
3015
|
-
|
3016
|
-
# Phase 2: Dependencies (Week 3)
|
3017
|
-
bundle update --minor # Minor version updates
|
3018
|
-
|
3019
|
-
# Phase 3: Rails Upgrade (Week 4)
|
3020
|
-
bundle update rails # Full Rails upgrade
|
3021
|
-
# Update .rubocop.yml TargetRailsVersion
|
3022
|
-
|
3023
|
-
# Phase 4: Modernization (Week 5+)
|
3024
|
-
# Adopt Rails 7/8 patterns gradually
|
3025
|
-
```
|
3026
|
-
|
3027
|
-
</details>
|
3028
|
-
|
3029
|
-
### 🧪 **Testing Strategies by Version**
|
3030
|
-
|
3031
|
-
<details>
|
3032
|
-
<summary><strong>🔬 Continuous Integration Testing Matrix</strong></summary>
|
3033
|
-
|
3034
|
-
#### **Recommended CI Testing Strategy**
|
3035
|
-
|
3036
|
-
```yaml
|
3037
|
-
# .github/workflows/compatibility_matrix.yml
|
3038
|
-
name: Version Compatibility Matrix
|
3039
|
-
|
3040
|
-
on: [push, pull_request]
|
3041
|
-
|
3042
|
-
jobs:
|
3043
|
-
test:
|
3044
|
-
runs-on: ubuntu-latest
|
3045
|
-
strategy:
|
3046
|
-
fail-fast: false
|
3047
|
-
matrix:
|
3048
|
-
ruby: ['3.1', '3.2', '3.3']
|
3049
|
-
rails: ['6.1', '7.0', '7.1', '8.0']
|
3050
|
-
exclude:
|
3051
|
-
- ruby: '3.1'
|
3052
|
-
rails: '8.0' # Not recommended combination
|
3053
|
-
- ruby: '3.3'
|
3054
|
-
rails: '6.1' # Unnecessary combination
|
3055
|
-
|
3056
|
-
steps:
|
3057
|
-
- uses: actions/checkout@v4
|
3058
|
-
- uses: ruby/setup-ruby@v1
|
3059
|
-
with:
|
3060
|
-
ruby-version: ${{ matrix.ruby }}
|
3061
|
-
bundler-cache: true
|
3062
|
-
|
3063
|
-
- name: Create version-specific Gemfile
|
3064
|
-
run: |
|
3065
|
-
echo "source 'https://rubygems.org'" > Gemfile.test
|
3066
|
-
echo "gem 'rails', '~> ${{ matrix.rails }}'" >> Gemfile.test
|
3067
|
-
echo "gem 'rubocop-hk', path: '.'" >> Gemfile.test
|
3068
|
-
echo "gem 'rspec'" >> Gemfile.test
|
3069
|
-
|
3070
|
-
- name: Run RuboCop with version matrix
|
3071
|
-
env:
|
3072
|
-
BUNDLE_GEMFILE: Gemfile.test
|
3073
|
-
run: |
|
3074
|
-
bundle install
|
3075
|
-
bundle exec rubocop --version
|
3076
|
-
bundle exec rubocop config/ lib/ --format json > results.json
|
3077
|
-
|
3078
|
-
- name: Validate configuration compatibility
|
3079
|
-
run: |
|
3080
|
-
bundle exec ruby -e "
|
3081
|
-
require 'rubocop'
|
3082
|
-
config = RuboCop::ConfigLoader.load_file('config/default.yml')
|
3083
|
-
puts 'Configuration valid for Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}'
|
3084
|
-
"
|
3085
|
-
```
|
3086
|
-
|
3087
|
-
</details>
|
3088
|
-
|
3089
|
-
<details>
|
3090
|
-
<summary><strong>📊 Performance Testing Across Versions</strong></summary>
|
3091
|
-
|
3092
|
-
#### **Benchmark Testing Setup**
|
3093
|
-
|
3094
|
-
```ruby
|
3095
|
-
# benchmark/version_performance.rb
|
3096
|
-
require 'benchmark'
|
3097
|
-
require 'rubocop'
|
3098
|
-
|
3099
|
-
class VersionBenchmark
|
3100
|
-
def self.run
|
3101
|
-
puts "RuboCop HK Performance Benchmark"
|
3102
|
-
puts "Ruby: #{RUBY_VERSION}"
|
3103
|
-
puts "Rails: #{Rails.version}" if defined?(Rails)
|
3104
|
-
puts "RuboCop: #{RuboCop::Version.version}"
|
3105
|
-
puts "=" * 50
|
3106
|
-
|
3107
|
-
# Test different configurations
|
3108
|
-
configs = {
|
3109
|
-
"Basic" => "config/default.yml",
|
3110
|
-
"Rails" => "config/rubocop-rails.yml",
|
3111
|
-
"Performance" => "config/rubocop-performance.yml"
|
3112
|
-
}
|
3113
|
-
|
3114
|
-
configs.each do |name, config_file|
|
3115
|
-
time = Benchmark.measure do
|
3116
|
-
system("bundle exec rubocop --config #{config_file} lib/ > /dev/null 2>&1")
|
3117
|
-
end
|
3118
|
-
|
3119
|
-
puts "#{name}: #{time.real.round(2)}s (real), #{time.utime.round(2)}s (user)"
|
3120
|
-
end
|
3121
|
-
end
|
3122
|
-
end
|
3123
|
-
|
3124
|
-
VersionBenchmark.run
|
3125
|
-
```
|
3126
|
-
|
3127
|
-
**Run benchmarks**:
|
3128
|
-
```bash
|
3129
|
-
# Test current environment
|
3130
|
-
ruby benchmark/version_performance.rb
|
3131
|
-
|
3132
|
-
# Test with different Ruby versions (using rbenv/rvm)
|
3133
|
-
for version in 3.1.4 3.2.2 3.3.0; do
|
3134
|
-
echo "Testing Ruby $version"
|
3135
|
-
rbenv local $version
|
3136
|
-
ruby benchmark/version_performance.rb
|
3137
|
-
done
|
3138
|
-
```
|
3139
|
-
|
3140
|
-
</details>
|
3141
|
-
|
3142
|
-
## ❓ Version-Specific FAQ & Troubleshooting
|
3143
|
-
|
3144
|
-
<details>
|
3145
|
-
<summary><strong>🚨 Common Issues & Solutions</strong></summary>
|
3146
|
-
|
3147
|
-
### **❌ "Gem not found" Error**
|
3148
|
-
```bash
|
3149
|
-
# Problem: Bundle can't find rubocop-hk
|
3150
|
-
LoadError: cannot load such file -- rubocop-hk
|
3151
|
-
|
3152
|
-
# Solution: Ensure proper installation
|
3153
|
-
bundle install
|
3154
|
-
# Or for global installation:
|
3155
|
-
gem install rubocop-hk -v "~> 1.0.0"
|
3156
|
-
|
3157
|
-
# Version-specific fix for Rails 6:
|
3158
|
-
echo 'gem "rubocop-hk", "~> 1.1.1", require: false' >> Gemfile
|
3159
|
-
bundle install
|
3160
|
-
```
|
3161
|
-
|
3162
|
-
### **❌ Configuration Not Found**
|
3163
|
-
```bash
|
3164
|
-
# Problem: RuboCop can't find configuration
|
3165
|
-
Configuration file not found: config/default.yml
|
3166
|
-
|
3167
|
-
# Solution: Check your .rubocop.yml syntax
|
3168
|
-
inherit_gem:
|
3169
|
-
rubocop-hk: config/default.yml # Note: no quotes around config path
|
3170
|
-
|
3171
|
-
# Verify gem installation
|
3172
|
-
bundle exec gem list | grep rubocop-hk
|
3173
|
-
```
|
3174
|
-
|
3175
|
-
### **❌ Too Many Offenses**
|
3176
|
-
```bash
|
3177
|
-
# Problem: Overwhelming number of violations in legacy code
|
3178
|
-
1847 offenses detected
|
3179
|
-
|
3180
|
-
# Solution: Generate TODO file for gradual adoption
|
3181
|
-
bundle exec rubocop --auto-gen-config
|
3182
|
-
echo "inherit_from: .rubocop_todo.yml" >> .rubocop.yml
|
3183
|
-
|
3184
|
-
# For Rails 6 legacy projects:
|
3185
|
-
bundle exec rubocop --auto-gen-config --exclude-limit 1000
|
3186
|
-
```
|
3187
|
-
|
3188
|
-
### **❌ Performance Issues**
|
3189
|
-
```bash
|
3190
|
-
# Problem: RuboCop running slowly
|
3191
|
-
# Solution: Enable caching and parallel processing
|
3192
|
-
bundle exec rubocop --cache --parallel
|
3193
|
-
|
3194
|
-
# For older Ruby versions (3.1), use single-threaded mode:
|
3195
|
-
bundle exec rubocop --cache --no-parallel
|
3196
|
-
```
|
3197
|
-
|
3198
|
-
### **❌ Rails Version Conflicts**
|
3199
|
-
```bash
|
3200
|
-
# Problem: RuboCop cops not recognizing Rails features
|
3201
|
-
Rails/CompactBlank: undefined method `compact_blank'
|
3202
|
-
|
3203
|
-
# Solution: Check Rails version compatibility
|
3204
|
-
grep -r "TargetRailsVersion" .rubocop.yml
|
3205
|
-
# Ensure it matches your actual Rails version
|
3206
|
-
|
3207
|
-
# For Rails 6: Disable Rails 7+ cops
|
3208
|
-
echo "Rails/CompactBlank:
|
3209
|
-
Enabled: false" >> .rubocop.yml
|
3210
|
-
```
|
3211
|
-
|
3212
|
-
### **❌ Ruby Version Incompatibility**
|
3213
|
-
```bash
|
3214
|
-
# Problem: Cops requiring newer Ruby features
|
3215
|
-
SyntaxError: unexpected token
|
3216
|
-
|
3217
|
-
# Solution: Update Ruby version in configuration
|
3218
|
-
sed -i 's/TargetRubyVersion: .*/TargetRubyVersion: 3.1/' .rubocop.yml
|
3219
|
-
|
3220
|
-
# Or upgrade Ruby version:
|
3221
|
-
rbenv install 3.2.0
|
3222
|
-
rbenv local 3.2.0
|
3223
|
-
bundle install
|
3224
|
-
```
|
3225
|
-
|
3226
|
-
### **❌ Memory Issues in CI**
|
3227
|
-
```bash
|
3228
|
-
# Problem: RuboCop consuming too much memory in CI
|
3229
|
-
killed: memory limit exceeded
|
3230
|
-
|
3231
|
-
# Solution: Optimize for CI environments
|
3232
|
-
export RUBY_GC_HEAP_GROWTH_FACTOR=1.1
|
3233
|
-
export RUBY_GC_MALLOC_LIMIT=4000000
|
3234
|
-
bundle exec rubocop --no-parallel # Disable parallel processing
|
3235
|
-
```
|
3236
|
-
|
3237
|
-
</details>
|
3238
|
-
|
3239
|
-
<details>
|
3240
|
-
<summary><strong>🤔 Frequently Asked Questions</strong></summary>
|
3241
|
-
|
3242
|
-
### **Q: Can I use this with other RuboCop configs?**
|
3243
|
-
A: Yes! You can inherit multiple configurations:
|
3244
|
-
```yaml
|
3245
|
-
inherit_gem:
|
3246
|
-
rubocop-hk: config/default.yml
|
3247
|
-
other-config: config/base.yml
|
3248
|
-
|
3249
|
-
# Or combine with Rails 8 Omakase
|
3250
|
-
inherit_from:
|
3251
|
-
- .rubocop_rails_omakase.yml # Rails 8 built-in config
|
3252
|
-
|
3253
|
-
inherit_gem:
|
3254
|
-
rubocop-hk: config/default.yml # RuboCop HK enhancements
|
3255
|
-
```
|
3256
|
-
|
3257
|
-
### **Q: How do I disable specific cops?**
|
3258
|
-
A: Add them to your `.rubocop.yml`:
|
3259
|
-
```yaml
|
3260
|
-
Style/Documentation:
|
3261
|
-
Enabled: false
|
3262
|
-
|
3263
|
-
# Version-specific disabling:
|
3264
|
-
Rails/CompactBlank:
|
3265
|
-
Enabled: false # Disable for Rails 6 projects
|
3266
|
-
```
|
3267
|
-
|
3268
|
-
### **Q: Can I use this in a non-Rails Ruby project?**
|
3269
|
-
A: Absolutely! Just use the base configuration:
|
3270
|
-
```yaml
|
3271
|
-
inherit_gem:
|
3272
|
-
rubocop-hk: config/default.yml
|
3273
|
-
|
3274
|
-
# Rails-specific cops will be automatically disabled
|
3275
|
-
Rails:
|
3276
|
-
Enabled: false
|
3277
|
-
|
3278
|
-
# For gems, enable documentation
|
3279
|
-
Style/Documentation:
|
3280
|
-
Enabled: true
|
3281
|
-
```
|
3282
|
-
|
3283
|
-
### **Q: How do I contribute new rules?**
|
3284
|
-
A: Check our [Contributing Guide](CONTRIBUTING.md) for details on adding new cops or modifying existing ones.
|
3285
|
-
|
3286
|
-
### **Q: Which Ruby/Rails versions should I use for new projects?**
|
3287
|
-
A: **Recommended for 2025**:
|
3288
|
-
- **Ruby 3.3** + **Rails 8.0** - Best performance and latest features
|
3289
|
-
- **Ruby 3.2** + **Rails 7.2** - Enterprise-grade stability
|
3290
|
-
|
3291
|
-
### **Q: How do I upgrade from Rails 6 to Rails 7/8?**
|
3292
|
-
A: Follow our [Migration Guide](#🏗️-migration--upgrade-guide) with step-by-step instructions for safe upgrades.
|
3293
|
-
|
3294
|
-
### **Q: Is RuboCop HK compatible with Rails 8 Omakase?**
|
3295
|
-
A: Yes! RuboCop HK works alongside Rails 8's built-in Omakase configuration. You can use both together for enhanced code quality.
|
3296
|
-
|
3297
|
-
### **Q: What if I'm stuck on an older Ruby/Rails version?**
|
3298
|
-
A: RuboCop HK provides legacy support:
|
3299
|
-
- **Ruby 3.1** + **Rails 6.1**: Basic support with limited features
|
3300
|
-
- **Ruby 3.0** and below: Not recommended for security reasons
|
3301
|
-
|
3302
|
-
### **Q: How do I handle version conflicts in my team?**
|
3303
|
-
A: Use our team-specific configurations:
|
3304
|
-
```yaml
|
3305
|
-
# .rubocop.yml - Team consensus configuration
|
3306
|
-
inherit_gem:
|
3307
|
-
rubocop-hk: config/default.yml
|
3308
|
-
|
3309
|
-
AllCops:
|
3310
|
-
TargetRubyVersion: 3.2 # Team's minimum Ruby version
|
3311
|
-
TargetRailsVersion: 7.0 # Team's Rails version
|
3312
|
-
NewCops: disable # Avoid surprise changes
|
3313
|
-
```
|
3314
|
-
|
3315
|
-
</details>
|
3316
|
-
|
3317
|
-
<details>
|
3318
|
-
<summary><strong>⚡ Performance Tips</strong></summary>
|
3319
|
-
|
3320
|
-
```bash
|
3321
|
-
# 🚀 Speed up RuboCop with these flags:
|
3322
|
-
bundle exec rubocop \
|
3323
|
-
--cache \ # Enable caching
|
3324
|
-
--parallel \ # Run in parallel
|
3325
|
-
--format simple # Faster output format
|
3326
|
-
|
3327
|
-
# 📊 For CI environments:
|
3328
|
-
bundle exec rubocop \
|
3329
|
-
--cache false \ # Disable cache in CI
|
3330
|
-
--parallel \ # Still use parallel
|
3331
|
-
--format json # Machine-readable output
|
3332
|
-
```
|
3333
|
-
|
3334
|
-
</details>
|
3335
|
-
|
3336
|
-
---
|
3337
|
-
|
3338
|
-
## ⚡ Performance Optimization
|
3339
|
-
|
3340
|
-
### 🚀 **Speed Up RuboCop for Large Codebases**
|
3341
|
-
|
3342
|
-
<details>
|
3343
|
-
<summary><strong>🎯 Essential Performance Settings</strong></summary>
|
3344
|
-
|
3345
|
-
```yaml
|
3346
|
-
# .rubocop.yml - Performance optimized configuration
|
3347
|
-
inherit_gem:
|
3348
|
-
rubocop-hk: config/default.yml
|
3349
|
-
|
3350
|
-
AllCops:
|
3351
|
-
# Enable caching for faster subsequent runs
|
3352
|
-
UseCache: true
|
3353
|
-
CacheRootDirectory: tmp
|
3354
|
-
MaxFilesInCache: 20000
|
3355
|
-
|
3356
|
-
# Parallel processing
|
3357
|
-
TargetRubyVersion: 3.3
|
3358
|
-
TargetRailsVersion: 8.0
|
3359
|
-
|
3360
|
-
# Optimize file exclusions
|
3361
|
-
Exclude:
|
3362
|
-
- "tmp/**/*"
|
3363
|
-
- "log/**/*"
|
3364
|
-
- "node_modules/**/*"
|
3365
|
-
- "**/vendor/**/*"
|
3366
|
-
- "public/assets/**/*"
|
3367
|
-
- "public/packs/**/*"
|
3368
|
-
- "coverage/**/*"
|
3369
|
-
- ".git/**/*"
|
3370
|
-
```
|
3371
|
-
|
3372
|
-
</details>
|
3373
|
-
|
3374
|
-
<details>
|
3375
|
-
<summary><strong>⚡ Command-Line Optimizations</strong></summary>
|
3376
|
-
|
3377
|
-
```bash
|
3378
|
-
# 🚀 Fastest RuboCop execution
|
3379
|
-
bundle exec rubocop \
|
3380
|
-
--cache \
|
3381
|
-
--parallel \
|
3382
|
-
--format simple
|
3383
|
-
|
3384
|
-
# 📊 For CI environments (no cache, but parallel)
|
3385
|
-
bundle exec rubocop \
|
3386
|
-
--cache false \
|
3387
|
-
--parallel \
|
3388
|
-
--format json \
|
3389
|
-
--out rubocop-results.json
|
3390
|
-
|
3391
|
-
# 🔧 Auto-correct with performance optimizations
|
3392
|
-
bundle exec rubocop \
|
3393
|
-
--autocorrect \
|
3394
|
-
--cache \
|
3395
|
-
--parallel \
|
3396
|
-
--format progress
|
3397
|
-
|
3398
|
-
# 📈 Profile RuboCop performance
|
3399
|
-
time bundle exec rubocop --cache --parallel
|
3400
|
-
```
|
3401
|
-
|
3402
|
-
</details>
|
3403
|
-
|
3404
|
-
<details>
|
3405
|
-
<summary><strong>🏗️ Large Codebase Strategies</strong></summary>
|
3406
|
-
|
3407
|
-
**1. Selective Analysis:**
|
3408
|
-
```bash
|
3409
|
-
# Only check changed files in Git
|
3410
|
-
git diff --name-only --diff-filter=AM | grep '\.rb$' | xargs bundle exec rubocop
|
3411
|
-
|
3412
|
-
# Only check specific directories
|
3413
|
-
bundle exec rubocop app/ lib/ --parallel
|
3414
|
-
|
3415
|
-
# Only run specific cops
|
3416
|
-
bundle exec rubocop --only Style/StringLiterals,Layout/LineLength
|
3417
|
-
```
|
3418
|
-
|
3419
|
-
**2. Incremental Adoption:**
|
3420
|
-
```yaml
|
3421
|
-
# Focus on new code first
|
3422
|
-
inherit_gem:
|
3423
|
-
rubocop-hk: config/default.yml
|
3424
|
-
|
3425
|
-
AllCops:
|
3426
|
-
NewCops: enable
|
3427
|
-
|
3428
|
-
# Use TODO file for legacy code
|
3429
|
-
inherit_from: .rubocop_todo.yml
|
3430
|
-
|
3431
|
-
# Custom exclusions for legacy parts
|
3432
|
-
Style/Documentation:
|
3433
|
-
Exclude:
|
3434
|
-
- "app/models/legacy/**/*"
|
3435
|
-
- "lib/legacy/**/*"
|
3436
|
-
```
|
3437
|
-
|
3438
|
-
**3. Performance Monitoring:**
|
3439
|
-
```bash
|
3440
|
-
# Measure performance improvements
|
3441
|
-
echo "Before optimization:"
|
3442
|
-
time bundle exec rubocop > /dev/null
|
3443
|
-
|
3444
|
-
echo "After optimization:"
|
3445
|
-
time bundle exec rubocop --cache --parallel > /dev/null
|
3446
|
-
```
|
3447
|
-
|
3448
|
-
</details>
|
3449
|
-
|
3450
|
-
### 🎯 **CI/CD Performance Tips**
|
3451
|
-
|
3452
|
-
<details>
|
3453
|
-
<summary><strong>📈 GitHub Actions Optimization</strong></summary>
|
3454
|
-
|
3455
|
-
```yaml
|
3456
|
-
# .github/workflows/rubocop.yml - Optimized
|
3457
|
-
name: RuboCop Analysis
|
3458
|
-
|
3459
|
-
on: [push, pull_request]
|
3460
|
-
|
3461
|
-
jobs:
|
3462
|
-
rubocop:
|
3463
|
-
runs-on: ubuntu-latest
|
3464
|
-
steps:
|
3465
|
-
- uses: actions/checkout@v4
|
3466
|
-
|
3467
|
-
- uses: ruby/setup-ruby@v1
|
3468
|
-
with:
|
3469
|
-
ruby-version: 3.3
|
3470
|
-
bundler-cache: true
|
3471
|
-
|
3472
|
-
# Cache RuboCop analysis results
|
3473
|
-
- uses: actions/cache@v3
|
3474
|
-
with:
|
3475
|
-
path: ~/.cache/rubocop_cache
|
3476
|
-
key: ${{ runner.os }}-rubocop-${{ hashFiles('.rubocop.yml') }}-${{ hashFiles('Gemfile.lock') }}
|
3477
|
-
restore-keys: |
|
3478
|
-
${{ runner.os }}-rubocop-${{ hashFiles('.rubocop.yml') }}-
|
3479
|
-
${{ runner.os }}-rubocop-
|
3480
|
-
|
3481
|
-
# Run RuboCop with performance optimizations
|
3482
|
-
- name: Run RuboCop
|
3483
|
-
run: |
|
3484
|
-
bundle exec rubocop \
|
3485
|
-
--parallel \
|
3486
|
-
--format github \
|
3487
|
-
--format json --out rubocop-results.json
|
3488
|
-
|
3489
|
-
- uses: actions/upload-artifact@v3
|
3490
|
-
if: always()
|
3491
|
-
with:
|
3492
|
-
name: rubocop-results
|
3493
|
-
path: rubocop-results.json
|
3494
|
-
```
|
3495
|
-
|
3496
|
-
</details>
|
3497
|
-
|
3498
|
-
### 🔧 **Memory Usage Optimization**
|
3499
|
-
|
3500
|
-
<details>
|
3501
|
-
<summary><strong>💾 Reduce Memory Footprint</strong></summary>
|
3502
|
-
|
3503
|
-
```yaml
|
3504
|
-
# .rubocop.yml - Memory optimized
|
3505
|
-
inherit_gem:
|
3506
|
-
rubocop-hk: config/default.yml
|
3507
|
-
|
3508
|
-
AllCops:
|
3509
|
-
# Limit parallel workers for memory-constrained environments
|
3510
|
-
# Default uses all CPU cores, but you can limit it
|
3511
|
-
TargetRubyVersion: 3.3
|
3512
|
-
|
3513
|
-
# For memory-constrained CI environments, disable parallel processing
|
3514
|
-
# Remove --parallel flag and run single-threaded
|
3515
|
-
|
3516
|
-
# Disable memory-intensive cops for large codebases
|
3517
|
-
Metrics/ClassLength:
|
3518
|
-
Enabled: false # Disable for initial runs on large legacy codebases
|
3519
|
-
|
3520
|
-
Metrics/MethodLength:
|
3521
|
-
Enabled: false # Can be memory intensive on huge methods
|
3522
|
-
```
|
3523
|
-
|
3524
|
-
**Memory usage monitoring:**
|
3525
|
-
```bash
|
3526
|
-
# Monitor memory usage during RuboCop run
|
3527
|
-
/usr/bin/time -v bundle exec rubocop 2>&1 | grep "Maximum resident set size"
|
3528
|
-
|
3529
|
-
# For macOS
|
3530
|
-
/usr/bin/time -l bundle exec rubocop 2>&1 | grep "maximum resident set size"
|
3531
|
-
```
|
3532
|
-
|
3533
|
-
</details>
|
3534
|
-
|
3535
|
-
### 📊 **Benchmarking and Metrics**
|
3536
|
-
|
3537
|
-
<details>
|
3538
|
-
<summary><strong>📈 Performance Measurement</strong></summary>
|
3539
|
-
|
3540
|
-
```bash
|
3541
|
-
# Create performance benchmark script
|
3542
|
-
cat > benchmark_rubocop.rb << 'EOF'
|
3543
|
-
require 'benchmark'
|
3544
|
-
|
3545
|
-
puts "RuboCop Performance Benchmark"
|
3546
|
-
puts "=" * 50
|
3547
|
-
|
3548
|
-
# Test different configurations
|
3549
|
-
configs = {
|
3550
|
-
"Default (no flags)" => "",
|
3551
|
-
"With cache" => "--cache",
|
3552
|
-
"With parallel" => "--parallel",
|
3553
|
-
"Cache + Parallel" => "--cache --parallel",
|
3554
|
-
"Cache + Parallel + Simple format" => "--cache --parallel --format simple"
|
3555
|
-
}
|
3556
|
-
|
3557
|
-
configs.each do |name, flags|
|
3558
|
-
puts "\n#{name}:"
|
3559
|
-
time = Benchmark.measure do
|
3560
|
-
`bundle exec rubocop #{flags} > /dev/null 2>&1`
|
3561
|
-
end
|
3562
|
-
puts " Real time: #{time.real.round(2)}s"
|
3563
|
-
puts " User time: #{time.utime.round(2)}s"
|
3564
|
-
puts " System time: #{time.stime.round(2)}s"
|
3565
|
-
end
|
3566
|
-
EOF
|
3567
|
-
|
3568
|
-
ruby benchmark_rubocop.rb
|
3569
|
-
```
|
3570
|
-
|
3571
|
-
</details>
|
3572
|
-
|
3573
|
-
### 🎯 **Version Testing Strategies**
|
3574
|
-
|
3575
|
-
<details>
|
3576
|
-
<summary><strong>🔬 Local Development Testing</strong></summary>
|
3577
|
-
|
3578
|
-
#### **Multi-Version Testing Setup**
|
3579
|
-
|
3580
|
-
```bash
|
3581
|
-
# Create version-specific gemfiles for testing
|
3582
|
-
# Gemfile.rails6
|
3583
|
-
source 'https://rubygems.org'
|
3584
|
-
gem 'rails', '~> 6.1'
|
3585
|
-
gem 'rubocop-hk', path: '.'
|
3586
|
-
|
3587
|
-
# Gemfile.rails7
|
3588
|
-
source 'https://rubygems.org'
|
3589
|
-
gem 'rails', '~> 7.1'
|
3590
|
-
gem 'rubocop-hk', path: '.'
|
3591
|
-
|
3592
|
-
# Gemfile.rails8
|
3593
|
-
source 'https://rubygems.org'
|
3594
|
-
gem 'rails', '~> 8.0'
|
3595
|
-
gem 'rubocop-hk', path: '.'
|
3596
|
-
|
3597
|
-
# Test script
|
3598
|
-
#!/bin/bash
|
3599
|
-
# test_versions.sh
|
3600
|
-
for rails in rails6 rails7 rails8; do
|
3601
|
-
echo "Testing with $rails"
|
3602
|
-
BUNDLE_GEMFILE="Gemfile.$rails" bundle install
|
3603
|
-
BUNDLE_GEMFILE="Gemfile.$rails" bundle exec rubocop
|
3604
|
-
done
|
3605
|
-
```
|
3606
|
-
|
3607
|
-
#### **Ruby Version Management**
|
3608
|
-
|
3609
|
-
```bash
|
3610
|
-
# Using rbenv
|
3611
|
-
rbenv install 3.1.4
|
3612
|
-
rbenv install 3.2.2
|
3613
|
-
rbenv install 3.3.0
|
3614
|
-
|
3615
|
-
# Test across Ruby versions
|
3616
|
-
for version in 3.1.4 3.2.2 3.3.0; do
|
3617
|
-
rbenv local $version
|
3618
|
-
bundle install
|
3619
|
-
bundle exec rubocop
|
3620
|
-
done
|
3621
|
-
|
3622
|
-
# Using Docker for isolation
|
3623
|
-
docker run --rm -v $(pwd):/app -w /app ruby:3.1 bundle exec rubocop
|
3624
|
-
docker run --rm -v $(pwd):/app -w /app ruby:3.2 bundle exec rubocop
|
3625
|
-
docker run --rm -v $(pwd):/app -w /app ruby:3.3 bundle exec rubocop
|
3626
|
-
```
|
3627
|
-
|
3628
|
-
</details>
|
3629
|
-
|
3630
|
-
<details>
|
3631
|
-
<summary><strong>🏗️ Production Deployment Testing</strong></summary>
|
3632
|
-
|
3633
|
-
#### **Staging Environment Validation**
|
3634
|
-
|
3635
|
-
```bash
|
3636
|
-
# staging_validation.sh
|
3637
|
-
#!/bin/bash
|
3638
|
-
set -e
|
3639
|
-
|
3640
|
-
echo "🔍 Production Deployment Validation"
|
3641
|
-
echo "Ruby: $(ruby --version)"
|
3642
|
-
echo "Rails: $(rails --version)"
|
3643
|
-
echo "RuboCop HK: $(bundle list | grep rubocop-hk)"
|
3644
|
-
echo "==============================================="
|
3645
|
-
|
3646
|
-
# 1. Configuration validation
|
3647
|
-
echo "📋 Validating RuboCop configuration..."
|
3648
|
-
bundle exec rubocop --config .rubocop.yml --list-cops > /dev/null
|
3649
|
-
echo "✅ Configuration valid"
|
3650
|
-
|
3651
|
-
# 2. Zero-tolerance RuboCop check
|
3652
|
-
echo "🔍 Running RuboCop analysis..."
|
3653
|
-
bundle exec rubocop --fail-level error --format progress
|
3654
|
-
echo "✅ No RuboCop violations"
|
3655
|
-
|
3656
|
-
# 3. Security audit
|
3657
|
-
echo "🔒 Security audit..."
|
3658
|
-
bundle audit --update
|
3659
|
-
echo "✅ No known vulnerabilities"
|
3660
|
-
|
3661
|
-
# 4. Performance check
|
3662
|
-
echo "⚡ Performance validation..."
|
3663
|
-
time bundle exec rubocop --cache --parallel > /dev/null
|
3664
|
-
echo "✅ Performance acceptable"
|
3665
|
-
|
3666
|
-
# 5. Memory usage check
|
3667
|
-
echo "💾 Memory usage check..."
|
3668
|
-
/usr/bin/time -v bundle exec rubocop 2>&1 | grep "Maximum resident set size"
|
3669
|
-
echo "✅ Memory usage within limits"
|
3670
|
-
|
3671
|
-
echo "🎉 All validation checks passed - Ready for production!"
|
3672
|
-
```
|
3673
|
-
|
3674
|
-
#### **Blue-Green Deployment with RuboCop**
|
3675
|
-
|
3676
|
-
```yaml
|
3677
|
-
# .github/workflows/deploy.yml
|
3678
|
-
name: Blue-Green Deployment with Code Quality
|
3679
|
-
|
3680
|
-
on:
|
3681
|
-
push:
|
3682
|
-
branches: [main]
|
3683
|
-
|
3684
|
-
jobs:
|
3685
|
-
quality-gate:
|
3686
|
-
runs-on: ubuntu-latest
|
3687
|
-
outputs:
|
3688
|
-
quality-passed: ${{ steps.rubocop.outcome == 'success' }}
|
3689
|
-
steps:
|
3690
|
-
- uses: actions/checkout@v4
|
3691
|
-
- uses: ruby/setup-ruby@v1
|
3692
|
-
with:
|
3693
|
-
ruby-version: 3.3
|
3694
|
-
bundler-cache: true
|
3695
|
-
|
3696
|
-
- name: RuboCop Quality Gate
|
3697
|
-
id: rubocop
|
3698
|
-
run: |
|
3699
|
-
bundle exec rubocop --fail-level error --format github
|
3700
|
-
echo "RUBOCOP_VIOLATIONS=$(bundle exec rubocop --format json | jq '.summary.offense_count')" >> $GITHUB_OUTPUT
|
3701
|
-
|
3702
|
-
- name: Block deployment on violations
|
3703
|
-
if: steps.rubocop.outputs.RUBOCOP_VIOLATIONS != '0'
|
3704
|
-
run: |
|
3705
|
-
echo "❌ Deployment blocked: ${{ steps.rubocop.outputs.RUBOCOP_VIOLATIONS }} RuboCop violations"
|
3706
|
-
exit 1
|
3707
|
-
|
3708
|
-
deploy:
|
3709
|
-
needs: quality-gate
|
3710
|
-
if: needs.quality-gate.outputs.quality-passed == 'true'
|
3711
|
-
runs-on: ubuntu-latest
|
3712
|
-
steps:
|
3713
|
-
- name: Deploy to production
|
3714
|
-
run: echo "🚀 Deploying clean code to production..."
|
3715
|
-
```
|
3716
|
-
|
3717
|
-
</details>
|
3718
|
-
|
3719
|
-
---
|
3720
|
-
|
3721
|
-
## 📚 Additional Resources
|
3722
|
-
|
3723
|
-
### 📖 **Documentation**
|
3724
|
-
- **[📋 Quick Start Guide](QUICK_START.md)** - Get up and running in minutes
|
3725
|
-
- **[📚 Usage Examples](USAGE.md)** - Comprehensive usage scenarios
|
3726
|
-
- **[⚙️ Customization Guide](CUSTOMIZATION.md)** - Advanced configuration options
|
3727
|
-
- **[🎨 Style Guide](STYLEGUIDE.md)** - Complete coding standards
|
3728
|
-
- **[🏗️ Architecture](ARCHITECTURE.md)** - Technical implementation details
|
3729
|
-
|
3730
|
-
### 🔗 **Useful Links**
|
3731
|
-
- **[RuboCop Documentation](https://docs.rubocop.org/)** - Official RuboCop docs
|
3732
|
-
- **[Ruby Style Guide](https://rubystyle.guide/)** - Community Ruby style guide
|
3733
|
-
- **[Rails Coding Conventions](https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions)** - Rails team conventions
|
3734
|
-
- **[Ruby Version Support](https://www.ruby-lang.org/en/downloads/branches/)** - Official Ruby support timeline
|
3735
|
-
- **[Rails Maintenance Policy](https://guides.rubyonrails.org/maintenance_policy.html)** - Rails version support policy
|
3736
|
-
- **[RuboCop HK Compatibility Testing](https://github.com/hammadxcm/rubocop-hk/actions)** - CI/CD compatibility matrix
|
3737
|
-
|
3738
|
-
### 🤝 **Community & Support**
|
3739
|
-
- **[Issues](https://github.com/hammadxcm/rubocop-hk/issues)** - Report bugs or request features
|
3740
|
-
- **[Discussions](https://github.com/hammadxcm/rubocop-hk/discussions)** - Ask questions and share ideas
|
3741
|
-
- **[Wiki](https://github.com/hammadxcm/rubocop-hk/wiki)** - Community-driven documentation
|
3742
|
-
- **[Version Compatibility Reports](https://github.com/hammadxcm/rubocop-hk/issues?q=label%3A%22version+compatibility%22)** - Version-specific issues and solutions
|
3743
|
-
- **[Migration Help](https://github.com/hammadxcm/rubocop-hk/discussions/categories/migration-help)** - Get help with version upgrades
|
3744
|
-
|
3745
|
-
---
|
3746
|
-
|
3747
|
-
## 🤝 Contributing
|
3748
|
-
|
3749
|
-
We ❤️ contributions! Whether it's:
|
3750
|
-
|
3751
|
-
- 🐛 **Bug reports**
|
3752
|
-
- 💡 **Feature requests**
|
3753
|
-
- 📖 **Documentation improvements**
|
3754
|
-
- 🔧 **Code contributions**
|
3755
|
-
- 💬 **Community discussions**
|
3756
|
-
|
3757
|
-
**👉 See our [Contributing Guide](CONTRIBUTING.md) to get started!**
|
3758
|
-
|
3759
|
-
### 🚀 **Quick Development Setup**
|
3760
|
-
|
3761
|
-
```bash
|
3762
|
-
# 1. Fork & clone the repository
|
3763
|
-
git clone https://github.com/hammadxcm/rubocop-hk.git
|
3764
|
-
cd rubocop-hk
|
3765
|
-
|
3766
|
-
# 2. Install dependencies
|
3767
|
-
bundle install
|
3768
|
-
|
3769
|
-
# 3. Run tests
|
3770
|
-
bundle exec rspec
|
3771
|
-
|
3772
|
-
# 4. Check code quality
|
3773
|
-
bundle exec rubocop
|
3774
|
-
|
3775
|
-
# 5. Make your changes and submit a PR! 🎉
|
3776
|
-
```
|
66
|
+
See [CUSTOMIZATION.md](CUSTOMIZATION.md) for detailed configuration options.
|
3777
67
|
|
3778
|
-
|
68
|
+
## Documentation
|
3779
69
|
|
3780
|
-
|
70
|
+
- **[Usage Guide](USAGE.md)** - Comprehensive usage instructions and examples
|
71
|
+
- **[Gradual Adoption Guide](GRADUAL_ADOPTION_GUIDE.md)** - Team-focused 4-phase adoption strategy
|
72
|
+
- **[Modern Rules Reference](MODERN_RULES_REFERENCE.md)** - Educational explanations for all 45+ new rules
|
73
|
+
- **[Customization Guide](CUSTOMIZATION.md)** - Advanced configuration and customization options
|
74
|
+
- **[Quick Start Guide](QUICK_START.md)** - Getting started and basic setup
|
3781
75
|
|
3782
|
-
|
76
|
+
## Requirements
|
3783
77
|
|
3784
|
-
|
78
|
+
- Ruby >= 3.3.0
|
79
|
+
- RuboCop >= 1.78.0
|
80
|
+
- Rails >= 7.1.0 (if using Rails cops)
|
3785
81
|
|
3786
|
-
|
82
|
+
## New in v1.2.1
|
3787
83
|
|
3788
|
-
|
84
|
+
This hotfix release resolves CI/CD pipeline issues and establishes Ruby 3.3+ support:
|
3789
85
|
|
3790
|
-
|
86
|
+
- **Fixed RuboCop 1.80+ compatibility** - Resolved Rails cop validation errors
|
87
|
+
- **Added missing gem entry point** - Proper gem loading with `require 'rubocop-hk'`
|
88
|
+
- **Updated Ruby version requirement** - Now requires Ruby >= 3.3.0
|
89
|
+
- **45+ warning-only modern rules** - Gradual adoption without breaking builds
|
3791
90
|
|
3792
|
-
|
3793
|
-
🐦 **[Share on Twitter](https://twitter.com/intent/tweet?text=Just%20found%20an%20awesome%20RuboCop%20config%20gem%21&url=https%3A//github.com/hammadxcm/rubocop-hk)** •
|
3794
|
-
💬 **[Spread the word](https://github.com/hammadxcm/rubocop-hk/discussions)**
|
91
|
+
See [CHANGELOG.md](CHANGELOG.md) for complete release notes.
|
3795
92
|
|
3796
|
-
|
93
|
+
## Contributing
|
3797
94
|
|
3798
|
-
|
95
|
+
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
|
3799
96
|
|
3800
|
-
|
97
|
+
1. Fork it
|
98
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
99
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
100
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
101
|
+
5. Create a new Pull Request
|
3801
102
|
|
3802
|
-
|
3803
|
-
[✨ Request Feature](https://github.com/hammadxcm/rubocop-hk/issues/new?template=feature_request.md) •
|
3804
|
-
[📖 Documentation](https://github.com/hammadxcm/rubocop-hk/wiki) •
|
3805
|
-
[💬 Get Support](https://github.com/hammadxcm/rubocop-hk/discussions)**
|
103
|
+
## License
|
3806
104
|
|
3807
|
-
|
105
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|