From 3e0a7121fb13ced285c2fbdb3ef2cf1ee5181f99 Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 28 Mar 2017 15:48:28 -0400 Subject: [PATCH] Started to flesh out rubocop settings for this project. Added rakefile tasks to do so. Updated first script to make it compliant. --- auto/generate_module.rb | 54 ++++++++++++++++---------- test/.rubocop.yml | 48 +++++++++++++++++++++++ test/.rubocop_todo.yml | 85 +++++------------------------------------ test/rakefile | 17 +++++++-- 4 files changed, 105 insertions(+), 99 deletions(-) diff --git a/auto/generate_module.rb b/auto/generate_module.rb index 560612b..ade4f1a 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -64,26 +64,40 @@ class UnityModuleGenerator @options[:path_tst] += '/' unless @options[:path_tst][-1] == 47 # Built in patterns - @patterns = { 'src' => { '' => { inc: [] } }, - 'test' => { '' => { inc: [] } }, - 'dh' => { 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h')] }, - 'Hardware' => { inc: [] } }, - 'dih' => { 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h'), create_filename('%1$s', 'Interrupt.h')] }, - 'Interrupt' => { inc: [create_filename('%1$s', 'Hardware.h')] }, - 'Hardware' => { inc: [] } }, - 'mch' => { 'Model' => { inc: [] }, - 'Conductor' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'Hardware.h')] }, - 'Hardware' => { inc: [] } }, - 'mvp' => { 'Model' => { inc: [] }, - 'Presenter' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'View.h')] }, - 'View' => { inc: [] } } } + @patterns = { + 'src' => { + '' => { inc: [] } + }, + 'test' => { + '' => { inc: [] } + }, + 'dh' => { + 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h')] }, + 'Hardware' => { inc: [] } + }, + 'dih' => { + 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h'), create_filename('%1$s', 'Interrupt.h')] }, + 'Interrupt' => { inc: [create_filename('%1$s', 'Hardware.h')] }, + 'Hardware' => { inc: [] } + }, + 'mch' => { + 'Model' => { inc: [] }, + 'Conductor' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'Hardware.h')] }, + 'Hardware' => { inc: [] } + }, + 'mvp' => { + 'Model' => { inc: [] }, + 'Presenter' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'View.h')] }, + 'View' => { inc: [] } + } + } end ############################ def self.default_options { pattern: 'src', - includes: { + includes: { src: [], inc: [], tst: [] @@ -139,10 +153,10 @@ class UnityModuleGenerator template: cfg[:template], boilerplate: cfg[:boilerplate], includes: case (cfg[:inc]) - when :src then (@options[:includes][:src] || []) | pattern_traits[:inc].map { |f| f % [module_name] } + when :src then (@options[:includes][:src] || []) | (pattern_traits[:inc].map { |f| format(f, module_name) }) when :inc then (@options[:includes][:inc] || []) - when :tst then (@options[:includes][:tst] || []) | pattern_traits[:inc].map { |f| "#{@options[:mock_prefix]}#{f}" % [module_name] } - end + when :tst then (@options[:includes][:tst] || []) | (pattern_traits[:inc].map { |f| format("#{@options[:mock_prefix]}#{f}", module_name) }) + end } end end @@ -194,12 +208,12 @@ class UnityModuleGenerator File.open(file[:path], 'w') do |f| f.write("#{file[:boilerplate]}\n" % [file[:name]]) unless file[:boilerplate].nil? f.write(file[:template] % [file[:name], - file[:includes].map { |f| "#include \"#{f}\"\n" }.join, + file[:includes].map { |ff| "#include \"#{ff}\"\n" }.join, file[:name].upcase]) end if @options[:update_svn] `svn add \"#{file[:path]}\"` - if $CHILD_STATUS.exitstatus == 0 + if $!.exitstatus.zero? puts "File #{file[:path]} created and added to source control" else puts "File #{file[:path]} created but FAILED adding to source control!" @@ -233,7 +247,7 @@ end ############################ # Handle As Command Line If Called That Way -if $PROGRAM_NAME == __FILE__ +if $0 == __FILE__ destroy = false options = {} module_name = nil diff --git a/test/.rubocop.yml b/test/.rubocop.yml index f43d36e..e8d89b2 100644 --- a/test/.rubocop.yml +++ b/test/.rubocop.yml @@ -4,3 +4,51 @@ inherit_from: .rubocop_todo.yml AllCops: TargetRubyVersion: 2.1 + +# These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard +# (Maybe we will make these conform over time) +Style/SpecialGlobalVars: + SupportedStyles: + - use_perl_names + - use_english_names + EnforcedStyle: use_perl_names +Style/FormatString: + Enabled: false + +# This is disabled because it seems to get confused over nested hashes +Style/AlignHash: + Enabled: false + EnforcedHashRocketStyle: table + EnforcedColonStyle: table + +# We purposefully use these insecure features because they're what makes Ruby awesome +Security/Eval: + Enabled: false +Security/YAMLLoad: + Enabled: false + +# At this point, we're not ready to enforce inline documentation requirements +Style/Documentation: + Enabled: false +Style/DocumentationMethod: + Enabled: false + +# At this point, we're not ready to enforce any metrics +Metrics/AbcSize: + Enabled: false +Metrics/BlockLength: + Enabled: false +Metrics/BlockNesting: + Enabled: false +Metrics/ClassLength: + Enabled: false +Metrics/CyclomaticComplexity: + Enabled: false +Metrics/LineLength: + Enabled: false +Metrics/MethodLength: + Enabled: false +Metrics/ParameterLists: + Enabled: false +Metrics/PerceivedComplexity: + Enabled: false diff --git a/test/.rubocop_todo.yml b/test/.rubocop_todo.yml index 3292c64..dd4bf87 100644 --- a/test/.rubocop_todo.yml +++ b/test/.rubocop_todo.yml @@ -1,23 +1,18 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-03-28 08:23:05 -0400 using RuboCop version 0.48.0. +# on 2017-03-28 15:45:51 -0400 using RuboCop version 0.48.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: 2 -Lint/AmbiguousBlockAssociation: - Exclude: - - '../auto/generate_module.rb' - # Offense count: 1 # Cop supports --auto-correct. Lint/DeprecatedClassMethods: Exclude: - 'rakefile_helper.rb' -# Offense count: 7 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect. # SupportedStylesAlignWith: keyword, variable, start_of_line @@ -25,7 +20,6 @@ Lint/EndAlignment: Exclude: - '../auto/colour_prompt.rb' - '../auto/colour_reporter.rb' - - '../auto/generate_module.rb' - '../auto/parseOutput.rb' - '../auto/stylize_as_junit.rb' @@ -35,10 +29,9 @@ Lint/RescueException: - '../auto/stylize_as_junit.rb' - '../auto/unity_test_summary.rb' -# Offense count: 2 +# Offense count: 1 Lint/ShadowingOuterLocalVariable: Exclude: - - '../auto/generate_module.rb' - '../auto/stylize_as_junit.rb' # Offense count: 3 @@ -60,56 +53,17 @@ Lint/Void: Exclude: - '../auto/parseOutput.rb' -# Offense count: 45 -Metrics/AbcSize: - Max: 80 - -# Offense count: 6 -# Configuration parameters: CountComments, ExcludedMethods. -Metrics/BlockLength: - Max: 89 - -# Offense count: 4 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 341 - -# Offense count: 14 -Metrics/CyclomaticComplexity: - Max: 17 - -# Offense count: 226 -# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. -# URISchemes: http, https -Metrics/LineLength: - Max: 154 - -# Offense count: 39 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 58 - # Offense count: 3 # Configuration parameters: CountComments. Metrics/ModuleLength: Max: 204 -# Offense count: 13 -Metrics/PerceivedComplexity: - Max: 19 - # Offense count: 2 # Cop supports --auto-correct. Performance/StringReplacement: Exclude: - 'rakefile_helper.rb' -# Offense count: 1 -# Cop supports --auto-correct. -Security/YAMLLoad: - Exclude: - - 'rakefile_helper.rb' - # Offense count: 10 Style/AccessorMethodName: Exclude: @@ -129,27 +83,12 @@ Style/BlockDelimiters: Exclude: - 'spec/generate_module_existing_file_spec.rb' -# Offense count: 4 +# Offense count: 17 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Exclude: - - 'rakefile_helper.rb' - -# Offense count: 12 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - '../auto/colour_prompt.rb' - - '../auto/generate_module.rb' - - '../auto/generate_test_runner.rb' - - '../auto/parseOutput.rb' - - '../auto/stylize_as_junit.rb' - - '../auto/test_file_filter.rb' - - '../auto/type_sanitizer.rb' - - '../auto/unity_test_summary.rb' - '../examples/example_3/rakefile_helper.rb' - '../extras/fixture/rakefile_helper.rb' - 'rakefile_helper.rb' @@ -199,13 +138,6 @@ Style/FileName: Exclude: - '../auto/parseOutput.rb' -# Offense count: 4 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: format, sprintf, percent -Style/FormatString: - Exclude: - - '../auto/generate_module.rb' - # Offense count: 164 # Configuration parameters: AllowedVariables. Style/GlobalVars: @@ -328,7 +260,7 @@ Style/Not: Exclude: - 'rakefile_helper.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles. # SupportedStyles: predicate, comparison @@ -336,7 +268,6 @@ Style/NumericPredicate: Exclude: - 'spec/**/*' - '../auto/colour_reporter.rb' - - '../auto/generate_module.rb' # Offense count: 17 # Cop supports --auto-correct. @@ -453,13 +384,15 @@ Style/SpaceInsideParens: Exclude: - 'tests/test_generate_test_runner.rb' -# Offense count: 2 +# Offense count: 3 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: use_perl_names, use_english_names Style/SpecialGlobalVars: Exclude: - - 'rakefile_helper.rb' + - '../auto/generate_test_runner.rb' + - '../auto/stylize_as_junit.rb' + - '../auto/unity_test_summary.rb' # Offense count: 167 # Cop supports --auto-correct. diff --git a/test/rakefile b/test/rakefile index 55323af..33c36f8 100644 --- a/test/rakefile +++ b/test/rakefile @@ -74,19 +74,30 @@ end namespace :style do desc "Check style" task :check do - `rubocop ../` + report execute("rubocop ../ --config .rubocop.yml", true) report "Style Checked." end + namespace :check do + Dir['../**/*.rb'].each do |f| + task File.basename(f, '.rb').to_sym do + report execute("rubocop #{f} --color --config .rubocop.yml", true) + report "Style Checked." + end + end + end + desc "Attempt to Autocorrect style" task :auto do - `rubocop ../ --auto-correct` + File.delete(".rubocop_todo.yml") + execute("rubocop ../ --auto-correct --config .rubocop.yml") report "Autocorrected What We Could." end desc "Update style todo list" task :todo do - `rubocop ../ --auto-gen-config` + File.delete(".rubocop_todo.yml") + execute("rubocop ../ --auto-gen-config --config .rubocop.yml") report "Updated Style TODO List." end end -- GitLab