Skip to content

Commit 9fb6c9c

Browse files
babrovkapirj
andauthored
Fix Rubocop offences (rspec#2272)
* Fix Style/ExpandPathArguments cop * Layout/SpaceInsideBlockBraces Offences count: space: 51 no_space: 1395 * Style/PercentLiteralDelimiters * Gemspec/OrderedDependencies * Layout/ArgumentAlignment Offences count: with_first_argument: 13 with_fixed_indentation: 47 * Layout/BlockAlignment Offences count: either: 1 start_of_block: 4 start_of_line: 22 * Layout/ClosingHeredocIndentation * Layout/DotPosition Offences count: leading: 34 trailing: 1 * Layout/EmptyLineAfterGuardClause * Bundler/DuplicatedGem * Layout/EmptyLines * Layout/IndentationWidth * Layout/SpaceAfterComma * Layout/SpaceAroundEqualsInParameterDefault Offenses count: space: 3 no_space: 29 * Layout/SpaceBeforeBlockBraces Offenses count: space: 16 no_space: 52 * Layout/SpaceInsideHashLiteralBraces Offenses count: space: 73 no_space: 37 compact: 73 Set configuration for consistency: `no_space` for non empty braces `no_space` for empty braces * Layout/SpaceInsideParens Offenses count: space: 5311 no_space: 24 * Lint/AmbiguousBlockAssociation exclude `specs` folder * Lint/AmbiguousOperator exclude `Rakefile` * Lint/AmbiguousRegexpLiteral * Lint/DuplicateMethods * Lint/SuppressedException * Lint/UnderscorePrefixedVariableName * Lint/UnusedBlockArgument * Lint/UnusedMethodArgument * Metrics/ModuleLength * Metrics/ParameterLists * Naming/HeredocDelimiterCase * Style/BarePercentLiterals * Style/BracesAroundHashParameters * Style/ClassAndModuleChildren * Style/CommentedKeyword * Style/Encoding * Style/GlobalVars * Style/HashSyntax * Style/InverseMethods * Style/Lambda * Style/LineEndConcatenation * Style/NegatedIf * Style/NumericLiterals * Style/Proc * Style/RaiseArgs * Style/RedundantPercentQ * Style/Semicolon * Style/SingleLineMethods Use exclude since auto-correction causes spec fail: `rspec ./spec/rspec/rails_spec.rb:18` * Layout/LineLength * Style/NumericLiteralPrefix * Style/RedundantSelf * Style/EachWithObject * Style/PerlBackrefs Co-authored-by: Phil Pirozhkov <[email protected]>
1 parent d529c43 commit 9fb6c9c

File tree

82 files changed

+508
-443
lines changed

Some content is hidden

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

82 files changed

+508
-443
lines changed

.rubocop.yml

+89-1
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ inherit_from:
44
AllCops:
55
Exclude:
66
# Templates are really ERB which Rubocop does not parse
7-
- 'lib/generators/rspec/*/templates/**/*'
7+
- bin/**/*
8+
- lib/generators/rspec/*/templates/**/*
9+
10+
Bundler/DuplicatedGem:
11+
Enabled: false
812

913
Layout/AccessModifierIndentation:
1014
Enabled: false
1115

1216
Layout/AssignmentIndentation:
1317
Enabled: false
1418

19+
Layout/BlockAlignment:
20+
EnforcedStyleAlignWith: start_of_block
21+
1522
Layout/ClosingParenthesisIndentation:
1623
Enabled: false
1724

@@ -54,13 +61,20 @@ Layout/MultilineOperationIndentation:
5461
Layout/ParameterAlignment:
5562
EnforcedStyle: with_first_parameter
5663

64+
Layout/SpaceInsideHashLiteralBraces:
65+
EnforcedStyle: no_space
66+
EnforcedStyleForEmptyBraces: no_space
67+
5768
Layout/SpaceInsidePercentLiteralDelimiters:
5869
Enabled: false
5970

6071
# We use spaces, so it's less of a change to stick with that.
6172
Layout/SpaceAroundEqualsInParameterDefault:
6273
EnforcedStyle: space
6374

75+
Layout/SpaceInsideBlockBraces:
76+
EnforcedStyleForEmptyBraces: space
77+
6478
Layout/SpaceAroundBlockParameters:
6579
Enabled: false
6680

@@ -73,9 +87,29 @@ Layout/SpaceBeforeComma:
7387
Layout/SpaceInsideStringInterpolation:
7488
Enabled: false
7589

90+
Lint/AmbiguousBlockAssociation:
91+
Exclude:
92+
- spec/**/*
93+
94+
Lint/AmbiguousOperator:
95+
Exclude:
96+
- Rakefile
97+
98+
Lint/AmbiguousRegexpLiteral:
99+
Exclude:
100+
- features/step_definitions/additional_cli_steps.rb
101+
76102
Lint/AssignmentInCondition:
77103
Enabled: false
78104

105+
Lint/DuplicateMethods:
106+
Exclude:
107+
- example_app_generator/no_active_record/app/models/in_memory/model.rb
108+
109+
Lint/NonDeterministicRequireOrder:
110+
Exclude:
111+
- spec/spec_helper.rb
112+
79113
Lint/EmptyExpression:
80114
Enabled: false
81115

@@ -94,6 +128,8 @@ Lint/SuppressedException:
94128
# RSpec is tightly coupled to capybara right now, this should be
95129
# re-evaluted in the future. For now we allow the empty rescue
96130
- lib/rspec/rails/vendor/capybara.rb
131+
- example_app_generator/generate_stuff.rb
132+
- example_app_generator/spec/support/default_preview_path
97133

98134
Metrics/AbcSize:
99135
Enabled: false
@@ -108,6 +144,14 @@ Metrics/ClassLength:
108144
Metrics/PerceivedComplexity:
109145
Enabled: false
110146

147+
Metrics/ModuleLength:
148+
Exclude:
149+
- spec/**/*
150+
151+
Metrics/ParameterLists:
152+
Exclude:
153+
- example_app_generator/spec/verify_custom_renderers_spec.rb
154+
111155
# Who cares what we call the argument for binary operator methods?
112156
Naming/BinaryOperatorParameterName:
113157
Enabled: false
@@ -162,9 +206,16 @@ Style/BlockDelimiters:
162206
Style/CaseEquality:
163207
Enabled: false
164208

209+
Style/ClassAndModuleChildren:
210+
Enabled: false
211+
165212
Style/ClassCheck:
166213
Enabled: false
167214

215+
Style/CommentedKeyword:
216+
Exclude:
217+
- spec/rspec/rails/example/view_example_group_spec.rb
218+
168219
Style/ConditionalAssignment:
169220
Enabled: false
170221

@@ -198,9 +249,22 @@ Style/FormatStringToken:
198249
Style/FrozenStringLiteralComment:
199250
Enabled: false
200251

252+
Style/GlobalVars:
253+
Exclude:
254+
- spec/support/shared_examples.rb
255+
201256
Style/GuardClause:
202257
Enabled: false
203258

259+
Style/HashEachMethods:
260+
Enabled: true
261+
262+
Style/HashTransformKeys:
263+
Enabled: true
264+
265+
Style/HashTransformValues:
266+
Enabled: true
267+
204268
Style/IdenticalConditionalBranches:
205269
Enabled: false
206270

@@ -237,6 +301,13 @@ Style/NestedModifier:
237301
Style/NestedParenthesizedCalls:
238302
Enabled: false
239303

304+
Style/NumericLiterals:
305+
Exclude:
306+
- spec/rspec/rails/matchers/action_cable/have_stream_spec.rb
307+
308+
Style/NumericLiteralPrefix:
309+
EnforcedOctalStyle: zero_only
310+
240311
Style/NumericPredicate:
241312
Enabled: false
242313

@@ -258,6 +329,13 @@ Style/PercentLiteralDelimiters:
258329
'%W': '[]' # array of double-quoted strings
259330
'%x': () # a shell command as a string
260331

332+
Style/RaiseArgs:
333+
Exclude:
334+
- spec/rspec/rails/matchers/be_routable_spec.rb
335+
- spec/rspec/rails/matchers/have_rendered_spec.rb
336+
- spec/rspec/rails/matchers/redirect_to_spec.rb
337+
- spec/rspec/rails/matchers/route_to_spec.rb
338+
261339
Style/RegexpLiteral:
262340
Enabled: false
263341

@@ -274,6 +352,16 @@ Style/RescueStandardError:
274352
Style/SignalException:
275353
Enabled: false
276354

355+
Style/SingleLineMethods:
356+
Exclude:
357+
- spec/rspec/rails/example/controller_example_group_spec.rb
358+
- spec/rspec/rails/matchers/active_job_spec.rb
359+
- spec/rspec/rails/matchers/be_a_new_spec.rb
360+
- spec/rspec/rails/matchers/has_spec.rb
361+
- spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
362+
- spec/rspec/rails/matchers/have_rendered_spec.rb
363+
- spec/rspec/rails/setup_and_teardown_adapter_spec.rb
364+
277365
# This rule favors constant names from the English standard library which we don't load.
278366
Style/SpecialGlobalVars:
279367
Enabled: false

.rubocop_todo.yml

-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# ruby 1.8.7 required trailing dots
2-
Layout/DotPosition:
3-
EnforcedStyle: trailing
4-
51
# Over time we'd like to get this down, but this is what we're at now.
62
Metrics/CyclomaticComplexity:
73
Max: 9 # default: 6
@@ -13,22 +9,3 @@ Layout/LineLength:
139
# Over time we'd like to get this down, but this is what we're at now.
1410
Metrics/MethodLength:
1511
Max: 43 # default: 10
16-
17-
# each_with_object was unavailable on ruby 1.8.7
18-
Style/EachWithObject:
19-
Enabled: false
20-
21-
# the new lambda syntax was not supported in ruby 1.8.7
22-
Style/Lambda:
23-
Enabled: false
24-
25-
# we couldn't use named matches in ruby 1.8.7
26-
Style/PerlBackrefs:
27-
Exclude:
28-
- lib/generators/rspec/scaffold/scaffold_generator.rb
29-
30-
# On 1.8 `proc` was `lambda`, so we used `Proc.new` to ensure we got real procs
31-
# on all supported versions.
32-
# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/
33-
Style/Proc:
34-
Enabled: false

BUILD_DETAIL.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ $ bin/yard doc --no-cache
9999

100100
## Rubocop
101101

102-
We use [Rubocop](https://github.com/bbatsov/rubocop) to enforce style conventions on the project so
102+
We use [Rubocop](https://github.com/rubocop-hq/rubocop) to enforce style conventions on the project so
103103
that the code has stylistic consistency throughout. Run with:
104104

105105
```
106-
$ bundle exec rubocop lib
106+
$ bundle exec rubocop
107107
108108
# or, if you installed your bundle with `--standalone --binstubs`:
109109
110-
$ bin/rubocop lib
110+
$ bin/rubocop
111111
```
112112

113113
Our Rubocop configuration is a work-in-progress, so if you get a failure

DEVELOPMENT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Here's a short, non-exhaustive checklist of things we typically ask contributors
108108
- [ ] New behavior is covered by tests and all tests are passing.
109109
- [ ] No Ruby warnings are issued by your changes.
110110
- [ ] Documentation reflects changes and renders as intended.
111-
- [ ] Rubocop passes (e.g. `bundle exec rubocop lib`).
111+
- [ ] Rubocop passes (e.g. `bundle exec rubocop`).
112112
- [ ] Commits are squashed into a reasonable number of logical changesets that tell an easy-to-follow story.
113113
- [ ] No changelog entry is necessary (we'll add it as part of the merge process!)
114114

Gemfile

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
source "https://rubygems.org"
2-
version_file = File.expand_path("../.rails-version", __FILE__)
2+
version_file = File.expand_path('.rails-version', __dir__)
33
RAILS_VERSION = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ""
44

55
gemspec
66

7-
rspec_dependencies_gemfile = File.expand_path("../Gemfile-rspec-dependencies", __FILE__)
8-
eval_gemfile rspec_dependencies_gemfile
7+
eval_gemfile 'Gemfile-rspec-dependencies'
98

10-
gem 'yard', '~> 0.9.24', :require => false
9+
gem 'yard', '~> 0.9.24', require: false
1110

1211
group :documentation do
1312
gem 'github-markup', '~> 3.0.3'
@@ -57,10 +56,9 @@ end
5756

5857
gem "rubyzip", '~> 1.2'
5958

60-
gem 'rubocop', '~> 0.79.0'
59+
gem 'rubocop', '~> 0.80.1'
6160

62-
custom_gemfile = File.expand_path("../Gemfile-custom", __FILE__)
61+
custom_gemfile = File.expand_path('Gemfile-custom', __dir__)
6362
eval_gemfile custom_gemfile if File.exist?(custom_gemfile)
6463

65-
rails_dependencies_gemfile = File.expand_path("../Gemfile-rails-dependencies", __FILE__)
66-
eval_gemfile rails_dependencies_gemfile
64+
eval_gemfile 'Gemfile-rails-dependencies'

Rakefile

+14-11
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ namespace :generate do
6262

6363
# Rails 4+ cannot use a `rails` binstub generated by Bundler
6464
sh "rm -f #{bindir}/rails"
65-
sh "bundle exec rails new ./tmp/example_app --no-rc --skip-javascript --skip-bootsnap -skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
65+
sh "bundle exec rails new ./tmp/example_app --no-rc --skip-javascript --skip-bootsnap --skip-sprockets " \
66+
"--skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
6667

6768
in_example_app do
6869
sh "./travis_retry_bundle_install.sh 2>&1"
@@ -122,7 +123,7 @@ end
122123

123124
namespace :smoke do
124125
desc "create a new example app with generated specs and run them"
125-
task :app => ["clobber:app", "generate:app", "generate:stuff", :smoke]
126+
task app: ["clobber:app", "generate:app", "generate:stuff", :smoke]
126127
end
127128

128129
desc 'clobber generated files'
@@ -143,6 +144,7 @@ end
143144
desc "Push docs/cukes to relishapp using the relish-client-gem"
144145
task :relish, :version do |_t, args|
145146
raise "rake relish[VERSION]" unless args[:version]
147+
146148
sh "cp Changelog.md features/"
147149
if `relish versions rspec/rspec-rails`.split.map(&:strip).include? args[:version]
148150
puts "Version #{args[:version]} already exists"
@@ -159,12 +161,12 @@ namespace :no_active_record do
159161
desc "run a variety of specs against a non-ActiveRecord generated app"
160162
task :smoke do
161163
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rake #{rails_template_command} --backtrace",
162-
:app_dir => example_app_dir
164+
app_dir: example_app_dir
163165
end
164166

165167
namespace :smoke do
166168
desc "create a new example app without active record including generated specs and run them"
167-
task :app => [
169+
task app: [
168170
"no_active_record:clobber",
169171
"no_active_record:generate:app",
170172
"no_active_record:generate:stuff",
@@ -185,17 +187,18 @@ namespace :no_active_record do
185187

186188
# Rails 4+ cannot use a `rails` binstub generated by Bundler
187189
sh "rm -f #{bindir}/rails"
188-
sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-bootsnap --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
190+
sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-bootsnap " \
191+
"--skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
189192

190-
in_example_app(:app_dir => example_app_dir) do
193+
in_example_app(app_dir: example_app_dir) do
191194
sh "./travis_retry_bundle_install.sh 2>&1"
192195
# Rails 4+ cannot use a `rails` binstub generated by Bundler
193196
sh "bundle binstubs bundler rspec-core rake --force"
194197
sh "bundle binstubs railties" unless File.exist?("bin/rails")
195198

196199
application_file = File.read("config/application.rb")
197200
sh "rm config/application.rb"
198-
File.open("config/application.rb","w") do |f|
201+
File.open("config/application.rb", "w") do |f|
199202
f.write application_file.gsub(
200203
"config.assets.enabled = true",
201204
"config.assets.enabled = false"
@@ -207,14 +210,14 @@ namespace :no_active_record do
207210

208211
desc "generate a bunch of stuff with generators"
209212
task :stuff do
210-
in_example_app "bin/rake #{rails_template_command} LOCATION='../../example_app_generator/generate_stuff.rb'", :app_dir => example_app_dir
213+
in_example_app "bin/rake #{rails_template_command} LOCATION='../../example_app_generator/generate_stuff.rb'", app_dir: example_app_dir
211214
end
212215
end
213216
end
214217

215-
task :acceptance => ['smoke:app', 'no_active_record:smoke:app', :cucumber]
218+
task acceptance: ['smoke:app', 'no_active_record:smoke:app', :cucumber]
216219

217-
task :default => [:spec, :acceptance]
220+
task default: [:spec, :acceptance]
218221

219222
task :verify_private_key_present do
220223
private_key = File.expand_path('~/.gem/rspec-gem-private_key.pem')
@@ -223,4 +226,4 @@ task :verify_private_key_present do
223226
end
224227
end
225228

226-
task :build => :verify_private_key_present
229+
task build: :verify_private_key_present

benchmarks/before_block_capture_block_vs_yield.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ def yield_n_times(n)
88
before_n_times(n) { yield }
99
end
1010

11-
def capture_block_and_yield_n_times(n, &block)
11+
def capture_block_and_yield_n_times(n, &block) # rubocop:disable Lint/UnusedMethodArgument
1212
before_n_times(n) { yield }
1313
end
1414

1515
def capture_block_and_call_n_times(n, &block)
1616
before_n_times(n) { block.call }
1717
end
1818

19-
[10, 25, 50, 100, 1000, 10000].each do |count|
19+
[10, 25, 50, 100, 1000, 10_000].each do |count|
2020
puts "\n\nInvoking the block #{count} times\n"
2121

2222
Benchmark.ips do |x|
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
if Rails.application.config.respond_to?(:active_record) && !(RUBY_ENGINE == "jruby")
1+
if Rails.application.config.respond_to?(:active_record) && RUBY_ENGINE != "jruby"
22
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
33
end

example_app_generator/generate_action_mailer_specs.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'active_support'
22
require 'active_support/core_ext/module'
33

4-
using_source_path(File.expand_path('..', __FILE__)) do
4+
using_source_path(File.expand_path(__dir__)) do
55
# Comment out the default mailer stuff
66
comment_lines 'config/environments/development.rb', /action_mailer/
77
comment_lines 'config/environments/test.rb', /action_mailer/

0 commit comments

Comments
 (0)