1
0
Fork 0
mirror of https://github.com/thoughtbot/factory_bot.git synced 2022-11-09 11:43:51 -05:00

Add rubocop

to run rubocop locally and not to wait for HoundCI to bark at us.

The version is locked to 0.54 because this is the version HoundCI is using.
Using a newer version will not work as config changed from 0.54 to currently 0.59
and rubocop would complain with the old configuration.

thoughtbot uses the .rubocop.yml in thoughtbot/guides
as the orginizational config on Hound, so we inherit
from it so we can use the same config locally.

Fix #1195.
This commit is contained in:
Christian Bruckmayer 2018-09-15 16:16:10 +02:00 committed by Daniel Colson
parent c2d82b2631
commit 5b0257363c
6 changed files with 445 additions and 1 deletions

1
.gitignore vendored
View file

@ -8,3 +8,4 @@ coverage
.bundle
tmp
bin
.rubocop-https*

410
.rubocop.yml Normal file
View file

@ -0,0 +1,410 @@
inherit_from:
- https://raw.githubusercontent.com/thoughtbot/guides/master/style/ruby/.rubocop.yml
# TODO:
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-09-18 22:44:09 -0400 using RuboCop version 0.54.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# 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.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Exclude:
- '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.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
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:
- 'spec/support/macros/define_constant.rb'
# Offense count: 13
# Cop supports --auto-correct.
# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments.
Lint/UnusedBlockArgument:
Exclude:
- 'spec/acceptance/activesupport_instrumentation_spec.rb'
- 'spec/acceptance/build_list_spec.rb'
- 'spec/acceptance/callbacks_spec.rb'
- 'spec/acceptance/create_list_spec.rb'
- 'spec/acceptance/sequence_context_spec.rb'
- 'spec/factory_bot/factory_spec.rb'
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods.
Lint/UnusedMethodArgument:
Exclude:
- 'lib/factory_bot/evaluator.rb'
- 'lib/factory_bot/null_object.rb'
- 'lib/factory_bot/syntax/default.rb'
- 'spec/acceptance/activesupport_instrumentation_spec.rb'
# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'lib/factory_bot/declaration_list.rb'
- 'spec/factory_bot/evaluator_class_definer_spec.rb'
# Offense count: 1
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 26
# Offense count: 196
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 189
# Offense count: 1
Naming/MemoizedInstanceVariableName:
Exclude:
- 'spec/support/macros/define_constant.rb'
# Offense count: 1
# Cop supports --auto-correct.
Performance/RegexpMatch:
Exclude:
- 'lib/factory_bot/aliases.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect.
Performance/TimesMap:
Exclude:
- 'lib/factory_bot/strategy_syntax_method_registrar.rb'
- 'spec/acceptance/initialize_with_spec.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
# FunctionalMethods: let, let!, subject, watch
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'spec/acceptance/modify_factories_spec.rb'
- 'spec/factory_bot/attribute_list_spec.rb'
- 'spec/factory_bot/attribute_spec.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: braces, no_braces, context_dependent
Style/BracesAroundHashParameters:
Exclude:
- 'spec/factory_bot/definition_proxy_spec.rb'
- 'spec/support/shared_examples/strategy.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: PreferredMethods.
Style/CollectionMethods:
Exclude:
- 'lib/factory_bot/attribute_assigner.rb'
- 'lib/factory_bot/declaration_list.rb'
- 'spec/support/macros/define_constant.rb'
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, expanded
Style/EmptyMethod:
Exclude:
- 'lib/factory_bot/strategy/null.rb'
- 'spec/acceptance/attribute_existing_on_object_spec.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/ExpandPathArguments:
Exclude:
- 'factory_bot.gemspec'
# Offense count: 1
# Configuration parameters: .
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
EnforcedStyle: unannotated
# Offense count: 24
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
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'
# Offense count: 4
Style/MethodMissing:
Exclude:
- 'lib/factory_bot/decorator.rb'
- 'lib/factory_bot/decorator/invocation_tracker.rb'
- 'lib/factory_bot/definition_proxy.rb'
- 'lib/factory_bot/evaluator.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/MutableConstant:
Exclude:
- 'lib/factory_bot/definition_proxy.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantBegin:
Exclude:
- 'lib/factory_bot/linter.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/RedundantSelf:
Exclude:
- 'lib/factory_bot/factory.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: implicit, explicit
Style/RescueStandardError:
Exclude:
- 'lib/factory_bot/linter.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, Whitelist.
# Whitelist: present?, blank?, presence, try
Style/SafeNavigation:
Exclude:
- 'spec/acceptance/overrides_spec.rb'
# Offense count: 308
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiteralsInInterpolation:
Exclude:
- 'lib/factory_bot/strategy/stub.rb'
- 'spec/acceptance/transient_attributes_spec.rb'
# Offense count: 21
# Cop supports --auto-correct.
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Style/SymbolProc:
Exclude:
- 'lib/factory_bot/configuration.rb'
- 'spec/acceptance/create_spec.rb'
# Offense count: 5
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArguments:
Exclude:
- 'features/support/factories.rb'
- 'lib/factory_bot/attribute_assigner.rb'
- 'spec/factory_bot/evaluator_class_definer_spec.rb'
- 'spec/support/macros/define_constant.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInArrayLiteral:
Exclude:
- 'lib/factory_bot/aliases.rb'
- 'spec/support/matchers/declaration.rb'
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForMultiline.
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
Style/TrailingCommaInHashLiteral:
Exclude:
- 'lib/factory_bot/factory_runner.rb'
# Offense count: 196
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 189

15
.rubocop_todo.yml Normal file
View file

@ -0,0 +1,15 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-09-18 22:46:18 -0400 using RuboCop version 0.54.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: space

View file

@ -6,3 +6,5 @@ gem 'activerecord-jdbcsqlite3-adapter', platforms: :jruby
gem 'jdbc-sqlite3', platforms: :jruby
gem 'sqlite3', '~> 1.3.10', platforms: :ruby
gem 'rubocop', '0.54', require: false

View file

@ -30,6 +30,7 @@ GEM
ffi (~> 1.9.10)
rspec-expectations (>= 2.99)
thor (~> 0.19)
ast (2.4.0)
builder (3.2.3)
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
@ -52,6 +53,11 @@ GEM
minitest (5.11.3)
multi_json (1.13.1)
multi_test (0.1.2)
parallel (1.12.1)
parser (2.5.1.2)
ast (~> 2.4.0)
powerpack (0.1.2)
rainbow (3.0.0)
rake (12.3.1)
rspec (3.8.0)
rspec-core (~> 3.8.0)
@ -69,6 +75,14 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.54.0)
parallel (~> 1.10)
parser (>= 2.5)
powerpack (~> 0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (~> 1.0, >= 1.0.1)
ruby-progressbar (1.10.0)
simplecov (0.16.1)
docile (~> 1.1)
json (>= 1.8, < 3)
@ -80,6 +94,7 @@ GEM
timecop (0.9.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.4.0)
yard (0.9.16)
PLATFORMS
@ -95,6 +110,7 @@ DEPENDENCIES
jdbc-sqlite3
rspec (~> 3.0)
rspec-its (~> 1.0)
rubocop (= 0.54)
simplecov
sqlite3 (~> 1.3.10)
timecop

View file

@ -260,7 +260,7 @@ describe FactoryBot::Factory, "running a factory" do
it "calls the block and returns the result" do
block_run = nil
block = ->(result) { block_run = "changed" }
subject.run(FactoryBot::Strategy::Build, { }, &block)
subject.run(FactoryBot::Strategy::Build, {}, &block)
expect(block_run).to eq "changed"
end
end