Skip to content

Commit 945228d

Browse files
alexeyr-ci2alexeyrgithub-actions[bot]ihabadhamclaude
authored
Unify Rubocop config (#2153)
### Summary Extracted from #1868 because it adds `spec/performance/bench.rb` and the default Rubocop config doesn't fit our repo. ### Pull Request checklist - [ ] ~Add/update test to cover these changes~ - [ ] ~Update documentation~ - [ ] ~Update CHANGELOG file~ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Centralized RuboCop configuration across the monorepo by establishing a shared root configuration file inherited by all projects, ensuring consistent code quality standards. * Consolidated development dependencies into a shared file to reduce duplication across projects. * **Chores** * Removed inline linting suppressions throughout the codebase for uniform code quality enforcement. * Updated test metadata formatting for consistency. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alexey Romanov <[email protected]> Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Ihab Adham <[email protected]> Co-authored-by: ihabadham <[email protected]> Co-authored-by: Claude Opus 4.5 <[email protected]>
1 parent e96e560 commit 945228d

File tree

20 files changed

+179
-258
lines changed

20 files changed

+179
-258
lines changed

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ spec/dummy/public
1919
*.res.js
2020

2121
# Prettier doesn't understand ERB syntax in YAML files and can damage templates
22-
.rubocop.yml
2322
*.yml
2423
*.yaml
2524
# Intentionally invalid

.rubocop.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Root RuboCop configuration for React on Rails monorepo
2+
# This contains shared settings inherited by react_on_rails/ and react_on_rails_pro/
3+
require:
4+
- rubocop-performance
5+
- rubocop-rspec
6+
7+
AllCops:
8+
NewCops: enable
9+
DisplayCopNames: true
10+
SuggestExtensions: false
11+
TargetRubyVersion: 3.0
12+
13+
Include:
14+
- '**/Rakefile'
15+
- '**/config.ru'
16+
- '**/Gemfile'
17+
- '**/*.rb'
18+
- '**/*.rake'
19+
20+
Exclude:
21+
- '**/*.js'
22+
- '**/node_modules/**/*'
23+
- '**/public/**/*'
24+
- '**/tmp/**/*'
25+
- 'coverage/**/*'
26+
- 'gen-examples/**/*'
27+
- 'node_modules/**/*'
28+
- 'spec/fixtures/**/*'
29+
- 'spec/react_on_rails/dummy-for-generators/**/*'
30+
- '**/vendor/**/*'
31+
32+
Naming/FileName:
33+
Exclude:
34+
- '**/Gemfile'
35+
- '**/Gemfile.*'
36+
- '**/Rakefile'
37+
38+
Layout/LineLength:
39+
Max: 120
40+
41+
Style/StringLiterals:
42+
EnforcedStyle: double_quotes
43+
44+
Style/Documentation:
45+
Enabled: false
46+
47+
Style/HashEachMethods:
48+
Enabled: true
49+
50+
Style/HashTransformKeys:
51+
Enabled: true
52+
53+
Style/HashTransformValues:
54+
Enabled: true
55+
56+
Metrics/AbcSize:
57+
Max: 28
58+
59+
Metrics/ClassLength:
60+
Max: 150
61+
62+
Metrics/CyclomaticComplexity:
63+
Max: 8
64+
65+
Metrics/PerceivedComplexity:
66+
Max: 10
67+
68+
Metrics/ParameterLists:
69+
Max: 5
70+
CountKeywordArgs: false
71+
72+
Metrics/MethodLength:
73+
Max: 41
74+
75+
Metrics/ModuleLength:
76+
Max: 180
77+
78+
RSpec/DescribeClass:
79+
Enabled: false
80+
81+
RSpec/ExampleLength:
82+
Enabled: false
83+
84+
RSpec/MessageSpies:
85+
Enabled: false
86+
87+
RSpec/MessageChain:
88+
Enabled: false
89+
90+
RSpec/MultipleExpectations:
91+
Enabled: false
92+
93+
RSpec/MultipleMemoizedHelpers:
94+
Max: 12
95+
96+
RSpec/NestedGroups:
97+
Max: 5
98+
99+
Style/FrozenStringLiteralComment:
100+
EnforcedStyle: always

Gemfile.shared_dev_dependencies

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# frozen_string_literal: true
2+
3+
# Shared development dependencies for react_on_rails and react_on_rails_pro
4+
# This ensures consistent versions across the monorepo
5+
6+
group :development, :test do
7+
gem "rubocop", "1.61.0", require: false
8+
gem "rubocop-performance", "~>1.20.0", require: false
9+
gem "rubocop-rspec", "~>2.26", require: false
10+
end

react_on_rails/.rubocop.yml

Lines changed: 7 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,23 @@
1-
# This is the configuration used to check the rubocop source code.
2-
# Check out: https://github.com/bbatsov/rubocop
3-
require:
4-
- rubocop-performance
5-
- rubocop-rspec
1+
# Inherits from root config
2+
inherit_from: ../.rubocop.yml
3+
4+
# Merge Exclude arrays with parent instead of replacing them
5+
inherit_mode:
6+
merge:
7+
- Exclude
68

79
AllCops:
8-
NewCops: enable
9-
DisplayCopNames: true
10-
TargetRubyVersion: 3.0.0
1110
SuggestExtensions: false
1211

13-
Include:
14-
- '**/Rakefile'
15-
- '**/config.ru'
16-
- 'Gemfile'
17-
- '**/*.rb'
18-
- '**/*.rake'
19-
2012
Exclude:
21-
- '**/*.js'
22-
- '**/node_modules/**/*'
23-
- '**/public/**/*'
24-
- '**/tmp/**/*'
25-
- 'coverage/**/*'
26-
- 'gen-examples/examples/**/*'
27-
- 'node_modules/**/*'
28-
- '../react_on_rails_pro/**/*' # Exclude pro package (has its own linting)
2913
- 'spec/dummy/bin/*'
30-
- 'spec/fixtures/**/*'
31-
- 'spec/react_on_rails/dummy-for-generators/**/*'
32-
- 'tmp/**/*'
33-
- 'vendor/**/*'
3414

3515
Naming/FileName:
3616
Exclude:
3717
- '**/Gemfile*'
3818
- '**/Rakefile'
3919
- '**/Steepfile'
4020

41-
Layout/LineLength:
42-
Max: 120
43-
44-
Style/StringLiterals:
45-
EnforcedStyle: double_quotes
46-
47-
Style/Documentation:
48-
Enabled: false
49-
50-
Style/HashEachMethods:
51-
Enabled: true
52-
53-
Style/HashTransformKeys:
54-
Enabled: true
55-
56-
Style/HashTransformValues:
57-
Enabled: true
58-
5921
Lint/AssignmentInCondition:
6022
Exclude:
6123
- 'spec/dummy/bin/spring'
@@ -66,33 +28,19 @@ Lint/SuppressedException:
6628
- 'spec/dummy/bin/rake'
6729

6830
Metrics/AbcSize:
69-
Max: 28
7031
Exclude:
7132
- 'lib/generators/react_on_rails/install_generator.rb' # Generator setup methods require comprehensive error handling
7233

73-
Metrics/CyclomaticComplexity:
74-
Max: 7
75-
76-
Metrics/PerceivedComplexity:
77-
Max: 10
78-
7934
Metrics/ClassLength:
80-
Max: 150
8135
Exclude:
8236
- 'lib/generators/react_on_rails/base_generator.rb' # Generator complexity justified
8337
- 'lib/react_on_rails/dev/server_manager.rb' # Dev tool with comprehensive help system
8438

85-
Metrics/ParameterLists:
86-
Max: 5
87-
CountKeywordArgs: false
88-
8939
Metrics/MethodLength:
90-
Max: 41
9140
Exclude:
9241
- 'lib/generators/react_on_rails/install_generator.rb' # Generator setup methods require comprehensive error handling
9342

9443
Metrics/ModuleLength:
95-
Max: 180
9644
Exclude:
9745
- 'spec/react_on_rails/engine_spec.rb' # Comprehensive engine tests require many examples
9846

@@ -107,18 +55,6 @@ RSpec/AnyInstance:
10755
- 'spec/react_on_rails/binstubs/dev_static_spec.rb'
10856
- 'spec/react_on_rails/dev/**/*_spec.rb' # Dev module tests require system mocking
10957

110-
RSpec/DescribeClass:
111-
Enabled: false
112-
113-
RSpec/ExampleLength:
114-
Enabled: false
115-
116-
RSpec/MessageSpies:
117-
Enabled: false
118-
119-
RSpec/NestedGroups:
120-
Max: 4
121-
12258
RSpec/BeforeAfterAll:
12359
Exclude:
12460
- 'spec/react_on_rails/generators/dev_tests_generator_spec.rb'
@@ -127,19 +63,10 @@ RSpec/BeforeAfterAll:
12763
- 'spec/react_on_rails/binstubs/dev_static_spec.rb'
12864
- 'spec/react_on_rails/dev/**/*_spec.rb' # Dev module tests require global setup
12965

130-
RSpec/MessageChain:
131-
Enabled: false
132-
133-
RSpec/MultipleExpectations:
134-
Enabled: false
135-
13666
RSpec/MultipleDescribes:
13767
Exclude:
13868
- 'spec/dummy/spec/system/integration_spec.rb'
13969

140-
RSpec/MultipleMemoizedHelpers:
141-
Max: 12
142-
14370
Style/GlobalVars:
14471
Exclude:
14572
- 'spec/dummy/config/environments/development.rb'
@@ -156,4 +83,3 @@ RSpec/InstanceVariable:
15683
RSpec/StubbedMock:
15784
Exclude:
15885
- 'spec/react_on_rails/dev/**/*_spec.rb' # Dev module tests use mixed stub/mock patterns
159-

react_on_rails/Gemfile.development_dependencies

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
eval_gemfile File.expand_path("../Gemfile.shared_dev_dependencies", __dir__)
4+
35
gem "shakapacker", "9.4.0"
46
gem "bootsnap", require: false
57
gem "rails", "~> 7.1"
@@ -35,9 +37,6 @@ group :development, :test do
3537
gem "pry-rescue"
3638
gem "rbs", require: false
3739
gem "steep", require: false
38-
gem "rubocop", "1.61.0", require: false
39-
gem "rubocop-performance", "~>1.20.0", require: false
40-
gem "rubocop-rspec", "~>2.26", require: false
4140
gem "spring", "~> 4.0"
4241
gem "lefthook", require: false
4342
# Added for Ruby 3.5+ compatibility to silence warnings

react_on_rails/lib/generators/react_on_rails/templates/base/base/bin/switch-bundler

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class BundlerSwitcher
6161
puts "✅ Updated assets_bundler to '#{@target_bundler}'"
6262
end
6363

64-
# rubocop:disable Metrics/CyclomaticComplexity
6564
def update_dependencies
6665
puts "📦 Updating package.json dependencies..."
6766

@@ -86,9 +85,7 @@ class BundlerSwitcher
8685
puts "✅ Removed #{@target_bundler == 'rspack' ? 'webpack' : 'rspack'} dependencies"
8786
File.write(package_json_path, JSON.pretty_generate(package_json))
8887
end
89-
# rubocop:enable Metrics/CyclomaticComplexity
9088

91-
# rubocop:disable Metrics/CyclomaticComplexity
9289
def install_dependencies
9390
puts "📥 Installing #{@target_bundler} dependencies..."
9491

@@ -123,7 +120,6 @@ class BundlerSwitcher
123120

124121
puts "✅ Installed #{@target_bundler} dependencies"
125122
end
126-
# rubocop:enable Metrics/CyclomaticComplexity
127123

128124
def detect_package_manager
129125
return "yarn" if File.exist?("yarn.lock")

react_on_rails/lib/react_on_rails/doctor.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,6 @@ def check_version_wildcards
468468
check_npm_wildcards
469469
end
470470

471-
# rubocop:disable Metrics/CyclomaticComplexity
472471
def check_gem_wildcards
473472
gemfile_path = ENV["BUNDLE_GEMFILE"] || "Gemfile"
474473
return unless File.exist?(gemfile_path)
@@ -490,9 +489,7 @@ def check_gem_wildcards
490489
# Ignore errors reading Gemfile
491490
end
492491
end
493-
# rubocop:enable Metrics/CyclomaticComplexity
494492

495-
# rubocop:disable Metrics/CyclomaticComplexity
496493
def check_npm_wildcards
497494
return unless File.exist?("package.json")
498495

@@ -514,7 +511,6 @@ def check_npm_wildcards
514511
# Ignore other errors
515512
end
516513
end
517-
# rubocop:enable Metrics/CyclomaticComplexity
518514

519515
def check_key_configuration_files
520516
files_to_check = {
@@ -538,7 +534,6 @@ def check_key_configuration_files
538534
check_server_rendering_engine
539535
end
540536

541-
# rubocop:disable Metrics/CyclomaticComplexity
542537
def check_layout_files
543538
layout_files = Dir.glob("app/views/layouts/**/*.erb")
544539
return if layout_files.empty?
@@ -565,7 +560,6 @@ def check_layout_files
565560
end
566561
end
567562
end
568-
# rubocop:enable Metrics/CyclomaticComplexity
569563

570564
# rubocop:disable Metrics/CyclomaticComplexity
571565
def check_server_rendering_engine
@@ -603,7 +597,6 @@ def check_server_rendering_engine
603597
end
604598
# rubocop:enable Metrics/CyclomaticComplexity
605599

606-
# rubocop:disable Metrics/CyclomaticComplexity
607600
def check_shakapacker_configuration_details
608601
return unless File.exist?("config/shakapacker.yml")
609602

@@ -632,7 +625,6 @@ def check_shakapacker_configuration_details
632625
checker.add_warning(" ⚠️ Could not run 'rake shakapacker:info': #{e.message}")
633626
end
634627
end
635-
# rubocop:enable Metrics/CyclomaticComplexity
636628

637629
def check_react_on_rails_configuration_details
638630
check_react_on_rails_initializer

react_on_rails/lib/react_on_rails/server_rendering_pool/ruby_embedded_java_script.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def reset_pool_if_server_bundle_was_modified
4949
# Note, js_code does not have to be based on React.
5050
# js_code MUST RETURN json stringify Object
5151
# Calling code will probably call 'html_safe' on return value before rendering to the view.
52-
# rubocop:disable Metrics/CyclomaticComplexity
5352
def exec_server_render_js(js_code, render_options, js_evaluator = nil)
5453
js_evaluator ||= self
5554
if render_options.trace
@@ -86,7 +85,6 @@ def exec_server_render_js(js_code, render_options, js_evaluator = nil)
8685
# We need to parse each chunk and replay the console messages.
8786
result.transform { |chunk| parse_result_and_replay_console_messages(chunk, render_options) }
8887
end
89-
# rubocop:enable Metrics/CyclomaticComplexity
9088

9189
def trace_js_code_used(msg, js_code, file_name = "tmp/server-generated.js", force: false)
9290
return unless ReactOnRails.configuration.trace || force

0 commit comments

Comments
 (0)