Skip to content

Commit 5c93087

Browse files
ahangarhaJudahmeek
andauthored
Improve rubocop rules and fix issues (#1281)
* Update rubocop config based on ReactOnRails config * Fix auto-correctable rubocop issues * Manually resolving additional linting issues --------- Co-authored-by: Judah Meek <[email protected]>
1 parent 3fa3c54 commit 5c93087

File tree

93 files changed

+1524
-1107
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1524
-1107
lines changed

.github/workflows/rubocop.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Rubocop
2+
3+
on: [push]
4+
5+
jobs:
6+
rubocop:
7+
name: Rubocop
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
matrix:
11+
os: [ubuntu-latest]
12+
ruby: ['2.7', '3.0']
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: ruby/setup-ruby@v1
17+
with:
18+
ruby-version: ${{ matrix.ruby }}
19+
bundler-cache: true
20+
- name: Install linting gems
21+
run: gem install rubocop rubocop-performance rubocop-minitest
22+
- name: Run rubocop
23+
run: rubocop

.rubocop.yml

+86-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,89 @@
1+
inherit_from: .rubocop_todo.yml
2+
3+
require:
4+
- rubocop-performance
5+
- rubocop-minitest
6+
17
AllCops:
2-
TargetRubyVersion: 2.3
8+
NewCops: enable
9+
TargetRubyVersion: 2.5
310
DisplayCopNames: true
11+
12+
Include:
13+
- '**/Rakefile'
14+
- '**/config.ru'
15+
- 'Gemfile'
16+
- '**/*.rb'
17+
- '**/*.rake'
18+
419
Exclude:
5-
- test/dummy_sprockets/**/*
6-
- test/dummy_webpacker1/**/*
7-
- test/dummy_webpacker2/**/*
8-
- test/dummy_webpacker3/**/*
9-
- node_modules/**/*
10-
- react_ujs/**/*
20+
<% `git status --ignored --porcelain`.lines.grep(/^!! /).each do |path| %>
21+
- <%= path.sub(/^!! /, '') %>
22+
<% end %>
23+
- '**/*.js'
24+
- '**/node_modules/**/*'
25+
- '**/public/**/*'
26+
- '**/tmp/**/*'
27+
- 'vendor/**/*'
28+
- 'test/dummy_sprockets/**/*'
29+
- 'test/dummy_webpacker1/**/*'
30+
- 'test/dummy_webpacker2/**/*'
31+
- 'test/dummy_webpacker3/**/*'
32+
- 'react_ujs/**/*'
33+
34+
Naming/FileName:
35+
Exclude:
36+
- '**/Gemfile'
37+
- '**/Rakefile'
38+
- 'lib/react-rails.rb'
39+
40+
Layout/LineLength:
41+
Max: 120
42+
43+
Style/StringLiterals:
44+
EnforcedStyle: double_quotes
45+
46+
Style/Documentation:
47+
Enabled: false
48+
49+
Style/HashEachMethods:
50+
Enabled: true
51+
52+
Style/HashTransformKeys:
53+
Enabled: true
54+
55+
Style/HashTransformValues:
56+
Enabled: true
57+
58+
Metrics/AbcSize:
59+
Max: 28
60+
61+
Metrics/CyclomaticComplexity:
62+
Max: 7
63+
64+
Metrics/PerceivedComplexity:
65+
Max: 10
66+
67+
Metrics/ClassLength:
68+
Max: 150
69+
70+
Metrics/ParameterLists:
71+
Max: 5
72+
CountKeywordArgs: false
73+
74+
Metrics/MethodLength:
75+
Max: 41
76+
77+
Metrics/ModuleLength:
78+
Max: 180
79+
80+
Naming/RescuedExceptionsVariableName:
81+
Enabled: false
82+
83+
# Style/GlobalVars:
84+
# Exclude:
85+
# - 'spec/dummy/config/environments/development.rb'
86+
87+
Metrics/BlockLength:
88+
Exclude:
89+
- 'test/**/*_test.rb'

.rubocop_todo.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2023-06-30 00:26:13 UTC using RuboCop version 1.53.1.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 2
10+
Lint/IneffectiveAccessModifier:
11+
Exclude:
12+
- 'lib/generators/react/component_generator.rb'
13+
14+
# Offense count: 1
15+
# Configuration parameters: CountComments, CountAsOne.
16+
Metrics/ClassLength:
17+
Exclude:
18+
- 'lib/generators/react/component_generator.rb'

Gemfile

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
source 'http://rubygems.org'
1+
# frozen_string_literal: true
2+
3+
source "http://rubygems.org"
24

35
gemspec
46
# This is an optional dev-dependency, required whenever sprockets is required

Gemfile.lock

+2-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,9 @@ GEM
103103
matrix (0.4.2)
104104
method_source (1.0.0)
105105
mini_mime (1.0.2)
106-
mini_portile2 (2.8.1)
107106
minitest (5.17.0)
108107
nenv (0.3.0)
109-
nokogiri (1.14.3)
110-
mini_portile2 (~> 2.8.0)
108+
nokogiri (1.14.3-x86_64-darwin)
111109
racc (~> 1.4)
112110
nokogiri (1.14.3-x86_64-linux)
113111
racc (~> 1.4)
@@ -168,7 +166,7 @@ GEM
168166
zeitwerk (2.6.6)
169167

170168
PLATFORMS
171-
ruby
169+
x86_64-darwin-20
172170
x86_64-linux
173171

174172
DEPENDENCIES

Rakefile

+26-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# frozen_string_literal: true
2+
13
begin
2-
require 'bundler/setup'
4+
require "bundler/setup"
35
rescue LoadError
4-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
57
end
68

79
Bundler::GemHelper.install_tasks
@@ -20,22 +22,22 @@ def yarn_run_in(dirname, cmd)
2022
end
2123

2224
namespace :react do
23-
desc 'Run the JS build process to put files in the gem source'
24-
task update: [:install, :build, :copy]
25+
desc "Run the JS build process to put files in the gem source"
26+
task update: %i[install build copy]
2527

26-
desc 'Install the JavaScript dependencies'
28+
desc "Install the JavaScript dependencies"
2729
task :install do
28-
yarn_run_in('react-builds', 'install')
30+
yarn_run_in("react-builds", "install")
2931
end
3032

31-
desc 'Build the JS bundles with Webpack'
33+
desc "Build the JS bundles with Webpack"
3234
task :build do
33-
yarn_run_in('react-builds', 'build')
35+
yarn_run_in("react-builds", "build")
3436
end
3537

3638
desc "Copy browser-ready JS files to the gem's asset paths"
3739
task :copy do
38-
environments = ['development', 'production']
40+
environments = %w[development production]
3941
environments.each do |environment|
4042
copy_react_asset("#{environment}/react-browser.js", "#{environment}/react.js")
4143
copy_react_asset("#{environment}/react-server.js", "#{environment}/react-server.js")
@@ -44,48 +46,48 @@ namespace :react do
4446
end
4547

4648
namespace :ujs do
47-
desc 'Run the JS build process to put files in the gem source'
48-
task update: [:install, :build, :copy]
49+
desc "Run the JS build process to put files in the gem source"
50+
task update: %i[install build copy]
4951

50-
desc 'Install the JavaScript dependencies'
52+
desc "Install the JavaScript dependencies"
5153
task :install do
5254
`yarn install`
5355
end
5456

55-
desc 'Build the JS bundles with Webpack'
57+
desc "Build the JS bundles with Webpack"
5658
task :build do
5759
`yarn build`
5860
end
5961

6062
desc "Copy browser-ready JS files to the gem's asset paths"
6163
task :copy do
62-
full_webpack_path = File.expand_path('../react_ujs/dist/react_ujs.js', __FILE__)
63-
full_destination_path = File.expand_path('../lib/assets/javascripts/react_ujs.js', __FILE__)
64+
full_webpack_path = File.expand_path("react_ujs/dist/react_ujs.js", __dir__)
65+
full_destination_path = File.expand_path("lib/assets/javascripts/react_ujs.js", __dir__)
6466
FileUtils.cp(full_webpack_path, full_destination_path)
6567
end
6668

67-
desc 'Publish the package in ./react_ujs/ to npm as `react_ujs`'
69+
desc "Publish the package in ./react_ujs/ to npm as `react_ujs`"
6870
task publish: :update do
6971
`npm publish`
7072
end
7173
end
7274

73-
require 'appraisal'
74-
require 'minitest/test_task'
75+
require "appraisal"
76+
require "minitest/test_task"
7577

7678
Minitest::TestTask.create(:test) do |t|
77-
t.libs << 'lib'
78-
t.libs << 'test'
79-
t.test_globs = ENV['TEST_PATTERN'] || 'test/**/*_test.rb'
80-
t.verbose = ENV['TEST_VERBOSE'] == '1'
79+
t.libs << "lib"
80+
t.libs << "test"
81+
t.test_globs = ENV["TEST_PATTERN"] || "test/**/*_test.rb"
82+
t.verbose = ENV["TEST_VERBOSE"] == "1"
8183
t.warning = false
8284
end
8385

8486
task default: :test
8587

8688
task :test_setup do
87-
load 'webdrivers/Rakefile'
88-
Dir.chdir('./test/dummy') do
89+
load "webdrivers/Rakefile"
90+
Dir.chdir("./test/dummy") do
8991
`yarn install`
9092
end
9193
end

0 commit comments

Comments
 (0)