Skip to content

Fix Rubocop offences #2272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 83 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
ea0057b
Fix Style/ExpandPathArguments cop
babrovka Jan 31, 2020
3281227
Layout/SpaceInsideBlockBraces
babrovka Jan 31, 2020
2454be7
Style/PercentLiteralDelimiters
babrovka Jan 31, 2020
1b7a457
Gemspec/OrderedDependencies
babrovka Jan 31, 2020
52c8ebe
Layout/ArgumentAlignment
babrovka Jan 31, 2020
e4c72a4
Layout/BlockAlignment
babrovka Jan 31, 2020
e017ab0
Layout/ClosingHeredocIndentation
babrovka Jan 31, 2020
4f1e87e
Layout/DotPosition
babrovka Jan 31, 2020
dd534a3
Layout/EmptyLineAfterGuardClause
babrovka Jan 31, 2020
277d8bb
rubocop through whole project
babrovka Feb 3, 2020
fe21baa
Bundler/DuplicatedGem
babrovka Feb 3, 2020
1956c74
Layout/EmptyLines
babrovka Feb 3, 2020
e19704f
Layout/IndentationWidth
babrovka Feb 3, 2020
08e5d0b
Layout/SpaceAfterComma
babrovka Feb 13, 2020
1bebe33
Layout/SpaceAroundEqualsInParameterDefault
babrovka Feb 13, 2020
b561b56
Layout/SpaceBeforeBlockBraces
babrovka Feb 13, 2020
8e29e64
Layout/SpaceInsideHashLiteralBraces
babrovka Feb 13, 2020
2899f5c
Layout/SpaceInsideParens
babrovka Feb 13, 2020
591cbd8
Lint/AmbiguousBlockAssociation
babrovka Feb 13, 2020
50e2e78
Lint/AmbiguousOperator
babrovka Feb 13, 2020
3c75e5e
Lint/AmbiguousRegexpLiteral
babrovka Feb 13, 2020
cef7788
Lint/DuplicateMethods
babrovka Feb 14, 2020
a642013
Lint/SuppressedException
babrovka Feb 14, 2020
72ed72a
Lint/UnderscorePrefixedVariableName
babrovka Feb 14, 2020
d80dc0c
Lint/UnusedBlockArgument
babrovka Feb 14, 2020
b739a98
Lint/UnusedMethodArgument
babrovka Feb 14, 2020
71df4df
Metrics/ModuleLength
babrovka Feb 14, 2020
65c2291
Metrics/ParameterLists
babrovka Feb 14, 2020
a477373
Naming/HeredocDelimiterCase
babrovka Feb 14, 2020
603d282
Style/BarePercentLiterals
babrovka Feb 14, 2020
3b79e45
Style/BracesAroundHashParameters
babrovka Feb 14, 2020
3f15a19
Style/ClassAndModuleChildren
babrovka Feb 14, 2020
e9172af
Style/CommentedKeyword
babrovka Feb 14, 2020
66e559b
Style/Encoding
babrovka Feb 14, 2020
fea2704
Style/GlobalVars
babrovka Feb 14, 2020
aa84174
Style/HashSyntax
babrovka Feb 14, 2020
4d370e8
Style/InverseMethods
babrovka Feb 14, 2020
3c63aeb
Style/Lambda
babrovka Feb 14, 2020
a3497fd
Style/LineEndConcatenation
babrovka Feb 14, 2020
deeeb51
Style/NegatedIf
babrovka Feb 14, 2020
3391a49
Style/NumericLiterals
babrovka Feb 14, 2020
2a61a87
Style/Proc
babrovka Feb 14, 2020
c27574e
Style/RaiseArgs
babrovka Feb 14, 2020
fa3bb26
Style/RedundantPercentQ
babrovka Feb 14, 2020
d2ace5c
Style/Semicolon
babrovka Feb 14, 2020
d55ba8e
Style/SingleLineMethods
babrovka Feb 14, 2020
07de36c
Lint/DuplicateMethods
babrovka Feb 14, 2020
b3b1550
Layout/LineLength
babrovka Feb 14, 2020
8fc0071
PR comments:
babrovka Feb 17, 2020
752c1d5
Style/NumericLiteralPrefix
babrovka Feb 17, 2020
03a3f82
Style/RedundantSelf
babrovka Feb 17, 2020
410895a
PR comments:
babrovka Feb 17, 2020
baa3f8a
update Metrics/ModuleLength
babrovka Feb 17, 2020
5802519
PR comments:
babrovka Feb 19, 2020
8acf6ee
PR Comments:
babrovka Feb 19, 2020
4a91544
PR comments:
babrovka Feb 19, 2020
447ca22
Fix Style/ExpandPathArguments cop
babrovka Jan 31, 2020
a2090f2
Layout/SpaceInsideBlockBraces
babrovka Jan 31, 2020
aa656b6
Bundler/DuplicatedGem
babrovka Feb 3, 2020
00dbc54
Lint/AmbiguousOperator
babrovka Feb 13, 2020
4906fb7
Lint/AmbiguousRegexpLiteral
babrovka Feb 13, 2020
5782e57
Metrics/ParameterLists
babrovka Feb 14, 2020
0cf5da6
Style/Semicolon
babrovka Feb 14, 2020
50f88ae
PR comments:
babrovka Feb 17, 2020
e5d2792
PR comments:
babrovka Feb 17, 2020
f02d5f5
update Metrics/ModuleLength
babrovka Feb 17, 2020
57e3bda
fixup! Fix hash rocket
pirj Mar 6, 2020
b6ab142
fixup! Appease RuboCop's Style/MultilineBlockChain
pirj Mar 6, 2020
7e759a8
fixup! Fix Style/HashSyntax
pirj Mar 6, 2020
c759c41
PR comments:
babrovka Mar 6, 2020
0c94c8c
update Layout/BlockAlignment
babrovka Mar 6, 2020
9770e77
update Style/NumericLiterals
babrovka Mar 6, 2020
a23c8d4
update Layout/SpaceInsideHashLiteralBraces
babrovka Mar 6, 2020
8df2b81
Enable Layout/DotPosition
babrovka Mar 6, 2020
84848dd
Enable Style/EachWithObject
babrovka Mar 6, 2020
d1a553c
Style/Lambda
babrovka Mar 6, 2020
7258415
Style/PerlBackrefs
babrovka Mar 6, 2020
684e2a3
Bundle with Rubocop 0.80.1
babrovka Mar 6, 2020
c20644e
Switch SpaceInsideHashLiteralBraces to no_space
pirj Mar 10, 2020
b76460b
Cosmetic styling fixes
pirj Mar 10, 2020
201cffb
Adjust SpaceInsideBlockBraces to give some space
pirj Mar 10, 2020
cec3d2e
Revert block capture removal
pirj Mar 10, 2020
213d1a3
Fix bad rebase
pirj Mar 10, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 89 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ inherit_from:
AllCops:
Exclude:
# Templates are really ERB which Rubocop does not parse
- 'lib/generators/rspec/*/templates/**/*'
- bin/**/*
- lib/generators/rspec/*/templates/**/*

Bundler/DuplicatedGem:
Enabled: false

Layout/AccessModifierIndentation:
Enabled: false

Layout/AssignmentIndentation:
Enabled: false

Layout/BlockAlignment:
EnforcedStyleAlignWith: start_of_block

Layout/ClosingParenthesisIndentation:
Enabled: false

Expand Down Expand Up @@ -54,13 +61,20 @@ Layout/MultilineOperationIndentation:
Layout/ParameterAlignment:
EnforcedStyle: with_first_parameter

Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space
EnforcedStyleForEmptyBraces: no_space

Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false

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

Layout/SpaceInsideBlockBraces:
EnforcedStyleForEmptyBraces: space

Layout/SpaceAroundBlockParameters:
Enabled: false

Expand All @@ -73,9 +87,29 @@ Layout/SpaceBeforeComma:
Layout/SpaceInsideStringInterpolation:
Enabled: false

Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*

Lint/AmbiguousOperator:
Exclude:
- Rakefile

Lint/AmbiguousRegexpLiteral:
Exclude:
- features/step_definitions/additional_cli_steps.rb

Lint/AssignmentInCondition:
Enabled: false

Lint/DuplicateMethods:
Exclude:
- example_app_generator/no_active_record/app/models/in_memory/model.rb

Lint/NonDeterministicRequireOrder:
Exclude:
- spec/spec_helper.rb

Lint/EmptyExpression:
Enabled: false

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

Metrics/AbcSize:
Enabled: false
Expand All @@ -108,6 +144,14 @@ Metrics/ClassLength:
Metrics/PerceivedComplexity:
Enabled: false

Metrics/ModuleLength:
Exclude:
- spec/**/*

Metrics/ParameterLists:
Exclude:
- example_app_generator/spec/verify_custom_renderers_spec.rb

# Who cares what we call the argument for binary operator methods?
Naming/BinaryOperatorParameterName:
Enabled: false
Expand Down Expand Up @@ -162,9 +206,16 @@ Style/BlockDelimiters:
Style/CaseEquality:
Enabled: false

Style/ClassAndModuleChildren:
Enabled: false

Style/ClassCheck:
Enabled: false

Style/CommentedKeyword:
Exclude:
- spec/rspec/rails/example/view_example_group_spec.rb

Style/ConditionalAssignment:
Enabled: false

Expand Down Expand Up @@ -198,9 +249,22 @@ Style/FormatStringToken:
Style/FrozenStringLiteralComment:
Enabled: false

Style/GlobalVars:
Exclude:
- spec/support/shared_examples.rb

Style/GuardClause:
Enabled: false

Style/HashEachMethods:
Enabled: true

Style/HashTransformKeys:
Enabled: true

Style/HashTransformValues:
Enabled: true

Style/IdenticalConditionalBranches:
Enabled: false

Expand Down Expand Up @@ -237,6 +301,13 @@ Style/NestedModifier:
Style/NestedParenthesizedCalls:
Enabled: false

Style/NumericLiterals:
Exclude:
- spec/rspec/rails/matchers/action_cable/have_stream_spec.rb

Style/NumericLiteralPrefix:
EnforcedOctalStyle: zero_only

Style/NumericPredicate:
Enabled: false

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

Style/RaiseArgs:
Exclude:
- spec/rspec/rails/matchers/be_routable_spec.rb
- spec/rspec/rails/matchers/have_rendered_spec.rb
- spec/rspec/rails/matchers/redirect_to_spec.rb
- spec/rspec/rails/matchers/route_to_spec.rb

Style/RegexpLiteral:
Enabled: false

Expand All @@ -274,6 +352,16 @@ Style/RescueStandardError:
Style/SignalException:
Enabled: false

Style/SingleLineMethods:
Exclude:
- spec/rspec/rails/example/controller_example_group_spec.rb
- spec/rspec/rails/matchers/active_job_spec.rb
- spec/rspec/rails/matchers/be_a_new_spec.rb
- spec/rspec/rails/matchers/has_spec.rb
- spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
- spec/rspec/rails/matchers/have_rendered_spec.rb
- spec/rspec/rails/setup_and_teardown_adapter_spec.rb

# This rule favors constant names from the English standard library which we don't load.
Style/SpecialGlobalVars:
Enabled: false
Expand Down
23 changes: 0 additions & 23 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# ruby 1.8.7 required trailing dots
Layout/DotPosition:
EnforcedStyle: trailing

# Over time we'd like to get this down, but this is what we're at now.
Metrics/CyclomaticComplexity:
Max: 9 # default: 6
Expand All @@ -13,22 +9,3 @@ Layout/LineLength:
# Over time we'd like to get this down, but this is what we're at now.
Metrics/MethodLength:
Max: 43 # default: 10

# each_with_object was unavailable on ruby 1.8.7
Style/EachWithObject:
Enabled: false

# the new lambda syntax was not supported in ruby 1.8.7
Style/Lambda:
Enabled: false

# we couldn't use named matches in ruby 1.8.7
Style/PerlBackrefs:
Exclude:
- lib/generators/rspec/scaffold/scaffold_generator.rb

# On 1.8 `proc` was `lambda`, so we used `Proc.new` to ensure we got real procs
# on all supported versions.
# http://batsov.com/articles/2014/02/04/the-elements-of-style-in-ruby-number-12-proc-vs-proc-dot-new/
Style/Proc:
Enabled: false
6 changes: 3 additions & 3 deletions BUILD_DETAIL.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ $ bin/yard doc --no-cache

## Rubocop

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

```
$ bundle exec rubocop lib
$ bundle exec rubocop

# or, if you installed your bundle with `--standalone --binstubs`:

$ bin/rubocop lib
$ bin/rubocop
```

Our Rubocop configuration is a work-in-progress, so if you get a failure
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Here's a short, non-exhaustive checklist of things we typically ask contributors
- [ ] New behavior is covered by tests and all tests are passing.
- [ ] No Ruby warnings are issued by your changes.
- [ ] Documentation reflects changes and renders as intended.
- [ ] Rubocop passes (e.g. `bundle exec rubocop lib`).
- [ ] Rubocop passes (e.g. `bundle exec rubocop`).
- [ ] Commits are squashed into a reasonable number of logical changesets that tell an easy-to-follow story.
- [ ] No changelog entry is necessary (we'll add it as part of the merge process!)

Expand Down
14 changes: 6 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
source "https://rubygems.org"
version_file = File.expand_path("../.rails-version", __FILE__)
version_file = File.expand_path('.rails-version', __dir__)
RAILS_VERSION = ENV['RAILS_VERSION'] || (File.exist?(version_file) && File.read(version_file).chomp) || ""

gemspec

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

gem 'yard', '~> 0.9.24', :require => false
gem 'yard', '~> 0.9.24', require: false

group :documentation do
gem 'github-markup', '~> 3.0.3'
Expand Down Expand Up @@ -57,10 +56,9 @@ end

gem "rubyzip", '~> 1.2'

gem 'rubocop', '~> 0.79.0'
gem 'rubocop', '~> 0.80.1'

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

rails_dependencies_gemfile = File.expand_path("../Gemfile-rails-dependencies", __FILE__)
eval_gemfile rails_dependencies_gemfile
eval_gemfile 'Gemfile-rails-dependencies'
25 changes: 14 additions & 11 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ namespace :generate do

# Rails 4+ cannot use a `rails` binstub generated by Bundler
sh "rm -f #{bindir}/rails"
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"
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"

in_example_app do
sh "./travis_retry_bundle_install.sh 2>&1"
Expand Down Expand Up @@ -122,7 +123,7 @@ end

namespace :smoke do
desc "create a new example app with generated specs and run them"
task :app => ["clobber:app", "generate:app", "generate:stuff", :smoke]
task app: ["clobber:app", "generate:app", "generate:stuff", :smoke]
end

desc 'clobber generated files'
Expand All @@ -143,6 +144,7 @@ end
desc "Push docs/cukes to relishapp using the relish-client-gem"
task :relish, :version do |_t, args|
raise "rake relish[VERSION]" unless args[:version]

sh "cp Changelog.md features/"
if `relish versions rspec/rspec-rails`.split.map(&:strip).include? args[:version]
puts "Version #{args[:version]} already exists"
Expand All @@ -159,12 +161,12 @@ namespace :no_active_record do
desc "run a variety of specs against a non-ActiveRecord generated app"
task :smoke do
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rake #{rails_template_command} --backtrace",
:app_dir => example_app_dir
app_dir: example_app_dir
end

namespace :smoke do
desc "create a new example app without active record including generated specs and run them"
task :app => [
task app: [
"no_active_record:clobber",
"no_active_record:generate:app",
"no_active_record:generate:stuff",
Expand All @@ -185,17 +187,18 @@ namespace :no_active_record do

# Rails 4+ cannot use a `rails` binstub generated by Bundler
sh "rm -f #{bindir}/rails"
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"
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"

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

application_file = File.read("config/application.rb")
sh "rm config/application.rb"
File.open("config/application.rb","w") do |f|
File.open("config/application.rb", "w") do |f|
f.write application_file.gsub(
"config.assets.enabled = true",
"config.assets.enabled = false"
Expand All @@ -207,14 +210,14 @@ namespace :no_active_record do

desc "generate a bunch of stuff with generators"
task :stuff do
in_example_app "bin/rake #{rails_template_command} LOCATION='../../example_app_generator/generate_stuff.rb'", :app_dir => example_app_dir
in_example_app "bin/rake #{rails_template_command} LOCATION='../../example_app_generator/generate_stuff.rb'", app_dir: example_app_dir
end
end
end

task :acceptance => ['smoke:app', 'no_active_record:smoke:app', :cucumber]
task acceptance: ['smoke:app', 'no_active_record:smoke:app', :cucumber]

task :default => [:spec, :acceptance]
task default: [:spec, :acceptance]

task :verify_private_key_present do
private_key = File.expand_path('~/.gem/rspec-gem-private_key.pem')
Expand All @@ -223,4 +226,4 @@ task :verify_private_key_present do
end
end

task :build => :verify_private_key_present
task build: :verify_private_key_present
4 changes: 2 additions & 2 deletions benchmarks/before_block_capture_block_vs_yield.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ def yield_n_times(n)
before_n_times(n) { yield }
end

def capture_block_and_yield_n_times(n, &block)
def capture_block_and_yield_n_times(n, &block) # rubocop:disable Lint/UnusedMethodArgument
before_n_times(n) { yield }
end

def capture_block_and_call_n_times(n, &block)
before_n_times(n) { block.call }
end

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

Benchmark.ips do |x|
Expand Down
2 changes: 1 addition & 1 deletion example_app_generator/config/initializers/sqlite3_fix.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if Rails.application.config.respond_to?(:active_record) && !(RUBY_ENGINE == "jruby")
if Rails.application.config.respond_to?(:active_record) && RUBY_ENGINE != "jruby"
Rails.application.config.active_record.sqlite3.represent_boolean_as_integer = true
end
2 changes: 1 addition & 1 deletion example_app_generator/generate_action_mailer_specs.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'active_support'
require 'active_support/core_ext/module'

using_source_path(File.expand_path('..', __FILE__)) do
using_source_path(File.expand_path(__dir__)) do
# Comment out the default mailer stuff
comment_lines 'config/environments/development.rb', /action_mailer/
comment_lines 'config/environments/test.rb', /action_mailer/
Expand Down
Loading