提交 3e0a7121 编写于 作者: M Mark VanderVoord

Started to flesh out rubocop settings for this project. Added rakefile tasks...

Started to flesh out rubocop settings for this project. Added rakefile tasks to do so. Updated first script to make it compliant.
上级 23f9c16a
...@@ -64,26 +64,40 @@ class UnityModuleGenerator ...@@ -64,26 +64,40 @@ class UnityModuleGenerator
@options[:path_tst] += '/' unless @options[:path_tst][-1] == 47 @options[:path_tst] += '/' unless @options[:path_tst][-1] == 47
# Built in patterns # Built in patterns
@patterns = { 'src' => { '' => { inc: [] } }, @patterns = {
'test' => { '' => { inc: [] } }, 'src' => {
'dh' => { 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h')] }, '' => { inc: [] }
'Hardware' => { inc: [] } }, },
'dih' => { 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h'), create_filename('%1$s', 'Interrupt.h')] }, 'test' => {
'Interrupt' => { inc: [create_filename('%1$s', 'Hardware.h')] }, '' => { inc: [] }
'Hardware' => { inc: [] } }, },
'mch' => { 'Model' => { inc: [] }, 'dh' => {
'Conductor' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'Hardware.h')] }, 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h')] },
'Hardware' => { inc: [] } }, 'Hardware' => { inc: [] }
'mvp' => { 'Model' => { inc: [] }, },
'Presenter' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'View.h')] }, 'dih' => {
'View' => { inc: [] } } } '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 end
############################ ############################
def self.default_options def self.default_options
{ {
pattern: 'src', pattern: 'src',
includes: { includes: {
src: [], src: [],
inc: [], inc: [],
tst: [] tst: []
...@@ -139,10 +153,10 @@ class UnityModuleGenerator ...@@ -139,10 +153,10 @@ class UnityModuleGenerator
template: cfg[:template], template: cfg[:template],
boilerplate: cfg[:boilerplate], boilerplate: cfg[:boilerplate],
includes: case (cfg[:inc]) 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 :inc then (@options[:includes][:inc] || [])
when :tst then (@options[:includes][:tst] || []) | pattern_traits[:inc].map { |f| "#{@options[:mock_prefix]}#{f}" % [module_name] } when :tst then (@options[:includes][:tst] || []) | (pattern_traits[:inc].map { |f| format("#{@options[:mock_prefix]}#{f}", module_name) })
end end
} }
end end
end end
...@@ -194,12 +208,12 @@ class UnityModuleGenerator ...@@ -194,12 +208,12 @@ class UnityModuleGenerator
File.open(file[:path], 'w') do |f| File.open(file[:path], 'w') do |f|
f.write("#{file[:boilerplate]}\n" % [file[:name]]) unless file[:boilerplate].nil? f.write("#{file[:boilerplate]}\n" % [file[:name]]) unless file[:boilerplate].nil?
f.write(file[:template] % [file[:name], 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]) file[:name].upcase])
end end
if @options[:update_svn] if @options[:update_svn]
`svn add \"#{file[:path]}\"` `svn add \"#{file[:path]}\"`
if $CHILD_STATUS.exitstatus == 0 if $!.exitstatus.zero?
puts "File #{file[:path]} created and added to source control" puts "File #{file[:path]} created and added to source control"
else else
puts "File #{file[:path]} created but FAILED adding to source control!" puts "File #{file[:path]} created but FAILED adding to source control!"
...@@ -233,7 +247,7 @@ end ...@@ -233,7 +247,7 @@ end
############################ ############################
# Handle As Command Line If Called That Way # Handle As Command Line If Called That Way
if $PROGRAM_NAME == __FILE__ if $0 == __FILE__
destroy = false destroy = false
options = {} options = {}
module_name = nil module_name = nil
......
...@@ -4,3 +4,51 @@ inherit_from: .rubocop_todo.yml ...@@ -4,3 +4,51 @@ inherit_from: .rubocop_todo.yml
AllCops: AllCops:
TargetRubyVersion: 2.1 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
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config` # `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 # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again. # versions of RuboCop, may require this file to be generated again.
# Offense count: 2
Lint/AmbiguousBlockAssociation:
Exclude:
- '../auto/generate_module.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
Lint/DeprecatedClassMethods: Lint/DeprecatedClassMethods:
Exclude: Exclude:
- 'rakefile_helper.rb' - 'rakefile_helper.rb'
# Offense count: 7 # Offense count: 6
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect. # Configuration parameters: EnforcedStyleAlignWith, SupportedStylesAlignWith, AutoCorrect.
# SupportedStylesAlignWith: keyword, variable, start_of_line # SupportedStylesAlignWith: keyword, variable, start_of_line
...@@ -25,7 +20,6 @@ Lint/EndAlignment: ...@@ -25,7 +20,6 @@ Lint/EndAlignment:
Exclude: Exclude:
- '../auto/colour_prompt.rb' - '../auto/colour_prompt.rb'
- '../auto/colour_reporter.rb' - '../auto/colour_reporter.rb'
- '../auto/generate_module.rb'
- '../auto/parseOutput.rb' - '../auto/parseOutput.rb'
- '../auto/stylize_as_junit.rb' - '../auto/stylize_as_junit.rb'
...@@ -35,10 +29,9 @@ Lint/RescueException: ...@@ -35,10 +29,9 @@ Lint/RescueException:
- '../auto/stylize_as_junit.rb' - '../auto/stylize_as_junit.rb'
- '../auto/unity_test_summary.rb' - '../auto/unity_test_summary.rb'
# Offense count: 2 # Offense count: 1
Lint/ShadowingOuterLocalVariable: Lint/ShadowingOuterLocalVariable:
Exclude: Exclude:
- '../auto/generate_module.rb'
- '../auto/stylize_as_junit.rb' - '../auto/stylize_as_junit.rb'
# Offense count: 3 # Offense count: 3
...@@ -60,56 +53,17 @@ Lint/Void: ...@@ -60,56 +53,17 @@ Lint/Void:
Exclude: Exclude:
- '../auto/parseOutput.rb' - '../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 # Offense count: 3
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ModuleLength: Metrics/ModuleLength:
Max: 204 Max: 204
# Offense count: 13
Metrics/PerceivedComplexity:
Max: 19
# Offense count: 2 # Offense count: 2
# Cop supports --auto-correct. # Cop supports --auto-correct.
Performance/StringReplacement: Performance/StringReplacement:
Exclude: Exclude:
- 'rakefile_helper.rb' - 'rakefile_helper.rb'
# Offense count: 1
# Cop supports --auto-correct.
Security/YAMLLoad:
Exclude:
- 'rakefile_helper.rb'
# Offense count: 10 # Offense count: 10
Style/AccessorMethodName: Style/AccessorMethodName:
Exclude: Exclude:
...@@ -129,27 +83,12 @@ Style/BlockDelimiters: ...@@ -129,27 +83,12 @@ Style/BlockDelimiters:
Exclude: Exclude:
- 'spec/generate_module_existing_file_spec.rb' - 'spec/generate_module_existing_file_spec.rb'
# Offense count: 4 # Offense count: 17
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions. # Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly, IncludeTernaryExpressions.
# SupportedStyles: assign_to_condition, assign_inside_condition # SupportedStyles: assign_to_condition, assign_inside_condition
Style/ConditionalAssignment: Style/ConditionalAssignment:
Exclude: 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' - '../examples/example_3/rakefile_helper.rb'
- '../extras/fixture/rakefile_helper.rb' - '../extras/fixture/rakefile_helper.rb'
- 'rakefile_helper.rb' - 'rakefile_helper.rb'
...@@ -199,13 +138,6 @@ Style/FileName: ...@@ -199,13 +138,6 @@ Style/FileName:
Exclude: Exclude:
- '../auto/parseOutput.rb' - '../auto/parseOutput.rb'
# Offense count: 4
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
Style/FormatString:
Exclude:
- '../auto/generate_module.rb'
# Offense count: 164 # Offense count: 164
# Configuration parameters: AllowedVariables. # Configuration parameters: AllowedVariables.
Style/GlobalVars: Style/GlobalVars:
...@@ -328,7 +260,7 @@ Style/Not: ...@@ -328,7 +260,7 @@ Style/Not:
Exclude: Exclude:
- 'rakefile_helper.rb' - 'rakefile_helper.rb'
# Offense count: 2 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles. # Configuration parameters: AutoCorrect, EnforcedStyle, SupportedStyles.
# SupportedStyles: predicate, comparison # SupportedStyles: predicate, comparison
...@@ -336,7 +268,6 @@ Style/NumericPredicate: ...@@ -336,7 +268,6 @@ Style/NumericPredicate:
Exclude: Exclude:
- 'spec/**/*' - 'spec/**/*'
- '../auto/colour_reporter.rb' - '../auto/colour_reporter.rb'
- '../auto/generate_module.rb'
# Offense count: 17 # Offense count: 17
# Cop supports --auto-correct. # Cop supports --auto-correct.
...@@ -453,13 +384,15 @@ Style/SpaceInsideParens: ...@@ -453,13 +384,15 @@ Style/SpaceInsideParens:
Exclude: Exclude:
- 'tests/test_generate_test_runner.rb' - 'tests/test_generate_test_runner.rb'
# Offense count: 2 # Offense count: 3
# Cop supports --auto-correct. # Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names # SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars: Style/SpecialGlobalVars:
Exclude: Exclude:
- 'rakefile_helper.rb' - '../auto/generate_test_runner.rb'
- '../auto/stylize_as_junit.rb'
- '../auto/unity_test_summary.rb'
# Offense count: 167 # Offense count: 167
# Cop supports --auto-correct. # Cop supports --auto-correct.
......
...@@ -74,19 +74,30 @@ end ...@@ -74,19 +74,30 @@ end
namespace :style do namespace :style do
desc "Check style" desc "Check style"
task :check do task :check do
`rubocop ../` report execute("rubocop ../ --config .rubocop.yml", true)
report "Style Checked." report "Style Checked."
end 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" desc "Attempt to Autocorrect style"
task :auto do task :auto do
`rubocop ../ --auto-correct` File.delete(".rubocop_todo.yml")
execute("rubocop ../ --auto-correct --config .rubocop.yml")
report "Autocorrected What We Could." report "Autocorrected What We Could."
end end
desc "Update style todo list" desc "Update style todo list"
task :todo do 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." report "Updated Style TODO List."
end end
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册