Fix assorted RuboCop spacing volations (#1203)

* Alphabetize gem listing in various Gemfiles [Rubocop Bundler/OrderedGems]

* Fix alignment of if/else/end statement [Rubocop Layout/ElseAlignment]

* Method definitions should have a empty line between them [Rubocop Layout/EmptyLineBetweenDefs]

* Modules, Classes, and blocks should have an empty line around them [Rubocop]

Cops:
Layout/EmptyLinesAroundBlockBody
Layout/EmptyLinesAroundModuleBody
Layout/EmptyLinesAroundClassBody
Layout/EmptyLinesAroundAccessModifier

* Keep a blank line before and after access modifiers [Rubocop Layout/EmptyLinesAroundAccessModifier]

* Remove misc extra whitespace [Rubocop Layout/ExtraSpacing]

* Indent the first line of the right-hand-side of a multi-line assignment [Rubocop Layout/IndentAssignment]

* Remove extraneous whitespace [Rubocop]

Cops:
  Layout/IndentationWidth
  Layout/LeadingCommentSpace
  Layout/SpaceAroundEqualsInParameterDefault
  Layout/SpaceInsideArrayLiteralBrackets
  Layout/SpaceInsideBlockBraces
  Layout/SpaceInsideParens
  Layout/TrailingBlankLines

* Revert rubocop changes to gemfiles; exclude files from rubocop checks

The files in gemfiles/ are generated by Appraisal, so we shouldn't edit them. Instead, let's tell RuboCop to exclude this directory.
This commit is contained in:
Colin Ross 2018-09-27 18:35:05 -07:00 committed by Daniel Colson
parent 89dd55aaf5
commit a56b68bc9c
23 changed files with 31 additions and 170 deletions

View File

@ -1,5 +1,8 @@
inherit_from:
- https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml
AllCops:
Exclude:
- 'gemfiles/*'
# TODO:
# This configuration was generated by
@ -10,91 +13,6 @@ inherit_from:
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: Include, TreatCommentsAsGroupSeparators.
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
Bundler/OrderedGems:
Exclude:
- 'gemfiles/4.2.gemfile'
- 'gemfiles/5.0.gemfile'
- 'gemfiles/5.1.gemfile'
- 'gemfiles/5.2.gemfile'
# Offense count: 1
# Cop supports --auto-correct.
Layout/ElseAlignment:
Exclude:
- 'lib/factory_bot/factory.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Exclude:
- 'lib/factory_bot/null_factory.rb'
# Offense count: 8
# Cop supports --auto-correct.
Layout/EmptyLinesAroundAccessModifier:
Exclude:
- 'lib/factory_bot/callback.rb'
- 'lib/factory_bot/declaration.rb'
- 'lib/factory_bot/declaration/association.rb'
- 'lib/factory_bot/declaration/dynamic.rb'
- 'lib/factory_bot/declaration/implicit.rb'
- 'lib/factory_bot/trait.rb'
- 'spec/acceptance/attribute_existing_on_object_spec.rb'
- 'spec/acceptance/private_attributes_spec.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Exclude:
- 'spec/acceptance/activesupport_instrumentation_spec.rb'
- 'spec/factory_bot/definition_proxy_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
Exclude:
- 'lib/factory_bot/linter.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Exclude:
- 'lib/factory_bot/sequence.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, AutoCorrect, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Layout/EndAlignment:
Exclude:
- 'lib/factory_bot/factory.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Exclude:
- 'spec/acceptance/attribute_existing_on_object_spec.rb'
- 'spec/acceptance/parent_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: IndentationWidth.
Layout/IndentAssignment:
Exclude:
- 'lib/factory_bot/linter.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
@ -104,51 +22,6 @@ Layout/IndentHeredoc:
- 'lib/factory_bot/linter.rb'
- 'spec/acceptance/lint_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: Width, IgnoredPatterns.
Layout/IndentationWidth:
Exclude:
- 'lib/factory_bot/factory.rb'
# Offense count: 1
# Cop supports --auto-correct.
Layout/LeadingCommentSpace:
Exclude:
- 'spec/acceptance/parent_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Exclude:
- 'lib/factory_bot/null_object.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBrackets: space, no_space
Layout/SpaceInsideArrayLiteralBrackets:
Exclude:
- 'spec/acceptance/traits_spec.rb'
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- 'lib/factory_bot/attribute.rb'
- 'lib/factory_bot/definition.rb'
- 'spec/acceptance/parent_spec.rb'
- 'spec/acceptance/traits_spec.rb'
- 'spec/acceptance/transient_attributes_spec.rb'
- 'spec/factory_bot/attribute/dynamic_spec.rb'
- 'spec/factory_bot/definition_proxy_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForEmptyBraces.
@ -157,20 +30,6 @@ Layout/SpaceInsideBlockBraces:
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: space
# Offense count: 1
# Cop supports --auto-correct.
Layout/SpaceInsideParens:
Exclude:
- 'spec/factory_bot/attribute/dynamic_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingBlankLines:
Exclude:
- 'Rakefile'
# Offense count: 1
Lint/RescueException:
Exclude:
@ -293,10 +152,6 @@ Style/FormatStringToken:
Style/HashSyntax:
Exclude:
- 'Rakefile'
- 'gemfiles/4.2.gemfile'
- 'gemfiles/5.0.gemfile'
- 'gemfiles/5.1.gemfile'
- 'gemfiles/5.2.gemfile'
- 'spec/acceptance/build_stubbed_spec.rb'
- 'spec/acceptance/nested_attributes_spec.rb'
- 'spec/acceptance/transient_attributes_spec.rb'

View File

@ -33,4 +33,3 @@ end
YARD::Rake::YardocTask.new do |t|
end

View File

@ -14,7 +14,7 @@ module FactoryBot
end
def to_proc
-> { }
-> {}
end
def association?

View File

@ -22,6 +22,7 @@ module FactoryBot
end
protected
attr_reader :block
private

View File

@ -17,6 +17,7 @@ module FactoryBot
end
protected
attr_reader :ignored
end
end

View File

@ -15,6 +15,7 @@ module FactoryBot
end
protected
attr_reader :options
private

View File

@ -14,6 +14,7 @@ module FactoryBot
end
protected
attr_reader :block
private

View File

@ -14,6 +14,7 @@ module FactoryBot
end
protected
attr_reader :factory
private

View File

@ -74,7 +74,7 @@ module FactoryBot
end
def skip_create
@to_create = ->(instance) { }
@to_create = ->(instance) {}
end
def define_trait(trait)

View File

@ -21,10 +21,10 @@ module FactoryBot
def build_class
@build_class ||= if class_name.is_a? Class
class_name
else
class_name.to_s.camelize.constantize
end
class_name
else
class_name.to_s.camelize.constantize
end
end
def run(build_strategy, overrides, &block)

View File

@ -1,6 +1,5 @@
module FactoryBot
class Linter
def initialize(factories, linting_strategy, factory_strategy = :create)
@factories_to_lint = factories
@linting_method = "lint_#{linting_strategy}"
@ -70,7 +69,7 @@ module FactoryBot
FactoryBot.public_send(factory_strategy, factory.name, trait_name)
rescue => error
result |=
[FactoryTraitError.new(error, factory, trait_name)]
[FactoryTraitError.new(error, factory, trait_name)]
end
end
result

View File

@ -11,8 +11,11 @@ module FactoryBot
:to_create, to: :definition
def compile; end
def class_name; end
def evaluator_class; FactoryBot::Evaluator; end
def hierarchy_class; FactoryBot::DefinitionHierarchy; end
end
end

View File

@ -13,7 +13,7 @@ module FactoryBot
end
end
def respond_to?(method, include_private=false)
def respond_to?(method, include_private = false)
@methods_to_respond_to.include? method.to_s
end

View File

@ -1,5 +1,4 @@
module FactoryBot
# Sequences are defined using sequence within a FactoryBot.define block.
# Sequence values are generated using next.
# @api private

View File

@ -25,6 +25,7 @@ module FactoryBot
end
protected
attr_reader :block
end
end

View File

@ -24,7 +24,6 @@ describe "using ActiveSupport::Instrumentation to track factory interaction" do
after(:build) { Kernel.sleep(0.1) }
end
end
end
end

View File

@ -20,10 +20,11 @@ end
describe "assigning overrides that are also private methods on object" do
before do
define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string)
define_model("Website", format: :string, y: :integer, more_format: :string, some_funky_method: :string)
Object.class_eval do
private
def some_funky_method(args)
end
end

View File

@ -23,7 +23,7 @@ describe "an instance generated by a factory that inherits from another factory"
end
factory :bill do
name { "Bill" } #block to make attribute dynamic
name { "Bill" } # block to make attribute dynamic
end
end
end
@ -41,7 +41,7 @@ describe "an instance generated by a factory that inherits from another factory"
it { should be_admin }
its(:name) { should eq "admin" }
its(:email) { should eq "admin@example.com" }
its(:upper_email) { should eq "ADMIN@EXAMPLE.COM"}
its(:upper_email) { should eq "ADMIN@EXAMPLE.COM" }
end
describe "the child class redefining parent's dynamic method" do

View File

@ -2,6 +2,7 @@ describe 'setting private attributes' do
it 'raises a NoMethodError' do
define_class('User') do
private
attr_accessor :foo
end

View File

@ -141,7 +141,7 @@ describe "an instance generated by a factory with multiple traits" do
context "factory using global trait" do
subject { FactoryBot.create(:user_with_email) }
its(:name) { should eq "Bill" }
its(:email) { should eq "Bill@example.com"}
its(:email) { should eq "Bill@example.com" }
end
context "factory created with alternate syntax for specifying trait" do
@ -333,7 +333,7 @@ describe "applying inline traits" do
FactoryBot.define do
factory :user do
trait :with_post do
posts { [ Post.new ] }
posts { [Post.new] }
end
end
end

View File

@ -105,7 +105,7 @@ describe "assigning values from a transient attribute" do
FactoryBot.define do
factory :user do
transient do
foo { Foo.new('id-of-foo', 'name-of-foo')}
foo { Foo.new('id-of-foo', 'name-of-foo') }
end
foo_id { foo.id }

View File

@ -1,6 +1,6 @@
describe FactoryBot::Attribute::Dynamic do
let(:name) { :first_name }
let(:block) { -> { } }
let(:block) { -> {} }
subject { FactoryBot::Attribute::Dynamic.new(name, false, block) }
@ -54,6 +54,6 @@ describe FactoryBot::Attribute::Dynamic do
end
describe FactoryBot::Attribute::Dynamic, "with a string name" do
subject { FactoryBot::Attribute::Dynamic.new("name", false, -> { } ) }
subject { FactoryBot::Attribute::Dynamic.new("name", false, -> {}) }
its(:name) { should eq :name }
end

View File

@ -63,7 +63,6 @@ describe FactoryBot::DefinitionProxy, "#method_missing" do
end
describe FactoryBot::DefinitionProxy, "#sequence" do
before do
allow(FactoryBot::Sequence).to receive(:new).and_call_original
end
@ -179,7 +178,7 @@ describe FactoryBot::DefinitionProxy, "#factory" do
end
it "with a block" do
child_block = -> { }
child_block = -> {}
proxy.factory(:child, {}, &child_block)
expect(proxy.child_factories).to include([:child, {}, child_block])
end