From 7907b085fd447138291d3915ae06d34a0b569002 Mon Sep 17 00:00:00 2001 From: Alex <6269576+petestreet@users.noreply.github.com> Date: Fri, 28 Sep 2018 21:03:04 -0500 Subject: [PATCH] Address todos generated by rubocop for files in the lib/generators directory (#299) * Address todos generated by rubocop for files in the lib/generators directory. This partially addresses #293. Since rubocop generated quite a few todos, the commits addressing them are split up into a few different PRs that cover different files. * Fix underscore seperator in model_generator.rb, and change memoized instance variable name to @_source_root in lib/generators/factory_bot.rb * get rid of memoized _source_root variable * get rid of extraneous rubocop rules --- .rubocop.yml | 59 ------------------- lib/generators/factory_bot.rb | 4 +- .../factory_bot/model/model_generator.rb | 24 ++++---- 3 files changed, 14 insertions(+), 73 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6cdf86e..d01e468 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,65 +27,6 @@ Layout/IndentHeredoc: - 'features/step_definitions/rails_steps.rb' - 'lib/generators/factory_bot/model/model_generator.rb' -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: Width, IgnoredPatterns. -Layout/IndentationWidth: - Exclude: - - 'lib/generators/factory_bot/model/model_generator.rb' - -# Offense count: 2 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/BlockLength: - Max: 40 - -# Offense count: 1 -Naming/MemoizedInstanceVariableName: - Exclude: - - 'lib/generators/factory_bot.rb' - -# Offense count: 9 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/generators/factory_bot/model/model_generator.rb' - -# Offense count: 84 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiterals: - EnforcedStyle: "double_quotes" - Exclude: - - 'lib/generators/factory_bot.rb' - - 'lib/generators/factory_bot/model/model_generator.rb' - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_quotes, double_quotes -Style/StringLiteralsInInterpolation: - Exclude: - - 'lib/generators/factory_bot/model/model_generator.rb' - -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInArguments: - Exclude: - - 'spec/factory_bot_rails/definition_file_paths_spec.rb' - - 'lib/generators/factory_bot/model/model_generator.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - EnforcedStyle: percent - MinSize: 3 - # Offense count: 11 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/lib/generators/factory_bot.rb b/lib/generators/factory_bot.rb index 963cc36..650e79b 100644 --- a/lib/generators/factory_bot.rb +++ b/lib/generators/factory_bot.rb @@ -1,10 +1,10 @@ -require 'rails/generators/named_base' +require "rails/generators/named_base" module FactoryBot module Generators class Base < Rails::Generators::NamedBase #:nodoc: def self.source_root - @_factory_bot_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'factory_bot', generator_name, 'templates')) + File.expand_path(File.join(File.dirname(__FILE__), "factory_bot", generator_name, "templates")) end def explicit_class_option diff --git a/lib/generators/factory_bot/model/model_generator.rb b/lib/generators/factory_bot/model/model_generator.rb index 7484c93..2e6ed96 100644 --- a/lib/generators/factory_bot/model/model_generator.rb +++ b/lib/generators/factory_bot/model/model_generator.rb @@ -1,5 +1,5 @@ -require 'generators/factory_bot' -require 'factory_bot_rails' +require "generators/factory_bot" +require "factory_bot_rails" module FactoryBot module Generators @@ -8,21 +8,21 @@ module FactoryBot :attributes, type: :array, default: [], - banner: "field:type field:type" + banner: "field:type field:type", ) class_option( :dir, type: :string, default: "test/factories", - desc: "The directory or file root where factories belong" + desc: "The directory or file root where factories belong", ) class_option( :suffix, type: :string, default: nil, - desc: "Suffix to add factory file" + desc: "Suffix to add factory file", ) def create_fixture_file @@ -43,7 +43,7 @@ module FactoryBot insert_into_file( factories_file, factory_definition, - after: "FactoryBot.define do\n" + after: "FactoryBot.define do\n", ) end @@ -53,19 +53,19 @@ module FactoryBot end def factory_definition -<<-RUBY + <<-RUBY factory :#{singular_table_name}#{explicit_class_option} do -#{factory_attributes.gsub(/^/, " ")} +#{factory_attributes.gsub(/^/, ' ')} end -RUBY + RUBY end def single_file_factory_definition -<<-RUBY + <<-RUBY FactoryBot.define do #{factory_definition.chomp} end -RUBY + RUBY end def factory_attributes @@ -78,7 +78,7 @@ RUBY if factory_bot_options[:filename_proc].present? factory_bot_options[:filename_proc].call(table_name) else - [table_name, filename_suffix].compact.join('_') + [table_name, filename_suffix].compact.join("_") end end