From a7639eeb54f532b57859a85f6de1e41df66d61cc Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Thu, 16 Feb 2023 16:40:23 -0500 Subject: [PATCH] Bump rubocop up to newer ruby versions (in progress) --- auto/colour_reporter.rb | 2 +- auto/generate_module.rb | 2 +- auto/generate_test_runner.rb | 15 +++++++-------- auto/test_file_filter.rb | 1 + auto/type_sanitizer.rb | 2 +- auto/unity_test_summary.rb | 3 ++- auto/yaml_helper.rb | 7 +++++-- examples/example_3/rakefile_helper.rb | 17 ++++++++--------- test/.rubocop.yml | 8 ++++---- 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/auto/colour_reporter.rb b/auto/colour_reporter.rb index 1c3bc21..b86b76c 100644 --- a/auto/colour_reporter.rb +++ b/auto/colour_reporter.rb @@ -12,7 +12,7 @@ def report(message) if !$colour_output $stdout.puts(message) else - message = message.join('\n') if message.class == Array + message = message.join('\n') if message.instance_of?(Array) message.each_line do |line| line.chomp! colour = case line diff --git a/auto/generate_module.rb b/auto/generate_module.rb index 2f044c4..40586f9 100644 --- a/auto/generate_module.rb +++ b/auto/generate_module.rb @@ -133,7 +133,7 @@ class UnityModuleGenerator # create triad definition prefix = @options[:test_prefix] || 'Test' - triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] }, + triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] }, { ext: '.h', path: @options[:path_inc], prefix: '', template: TEMPLATE_INC, inc: :inc, boilerplate: @options[:boilerplates][:inc] }, { ext: '.c', path: @options[:path_tst], prefix: prefix, template: TEMPLATE_TST, inc: :tst, boilerplate: @options[:boilerplates][:tst], test_define: @options[:test_define] }] diff --git a/auto/generate_test_runner.rb b/auto/generate_test_runner.rb index aa0f351..3d64d48 100755 --- a/auto/generate_test_runner.rb +++ b/auto/generate_test_runner.rb @@ -144,8 +144,8 @@ class UnityTestRunnerGenerator if @options[:use_param_tests] && !arguments.empty? args = [] type_and_args = arguments.split(/TEST_(CASE|RANGE)/) - for i in (1...type_and_args.length).step(2) - if type_and_args[i] == "CASE" + (1...type_and_args.length).step(2).each do |i| + if type_and_args[i] == 'CASE' args << type_and_args[i + 1].sub(/^\s*\(\s*(.*?)\s*\)\s*$/m, '\1') next end @@ -194,12 +194,11 @@ class UnityTestRunnerGenerator source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain) # parse out includes - includes = { - local: source.scan(/^\s*#include\s+\"\s*(.+\.#{@options[:include_extensions]})\s*\"/).flatten, + { + local: source.scan(/^\s*#include\s+"\s*(.+\.#{@options[:include_extensions]})\s*"/).flatten, system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" }, - linkonly: source.scan(/^TEST_FILE\(\s*\"\s*(.+\.#{@options[:source_extensions]})\s*\"/).flatten + linkonly: source.scan(/^TEST_FILE\(\s*"\s*(.+\.#{@options[:source_extensions]})\s*"/).flatten } - includes end def find_mocks(includes) @@ -446,7 +445,7 @@ class UnityTestRunnerGenerator end def create_h_file(output, filename, tests, testfile_includes, used_mocks) - filename = File.basename(filename).gsub(/[-\/\\\.\,\s]/, '_').upcase + filename = File.basename(filename).gsub(/[-\/\\.,\s]/, '_').upcase output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */') output.puts("#ifndef _#{filename}") output.puts("#define _#{filename}\n\n") @@ -485,7 +484,7 @@ if $0 == __FILE__ when /\.*\.ya?ml$/ options = UnityTestRunnerGenerator.grab_config(arg) true - when /--(\w+)=\"?(.*)\"?/ + when /--(\w+)="?(.*)"?/ options[Regexp.last_match(1).to_sym] = Regexp.last_match(2) true when /\.*\.(?:hpp|hh|H|h)$/ diff --git a/auto/test_file_filter.rb b/auto/test_file_filter.rb index 3cc32de..f4834a1 100644 --- a/auto/test_file_filter.rb +++ b/auto/test_file_filter.rb @@ -15,6 +15,7 @@ module RakefileHelpers file = 'test_file_filter.yml' return unless File.exist?(file) + filters = YamlHelper.load_file(file) @all_files = filters[:all_files] @only_files = filters[:only_files] diff --git a/auto/type_sanitizer.rb b/auto/type_sanitizer.rb index dafb882..3d1db09 100644 --- a/auto/type_sanitizer.rb +++ b/auto/type_sanitizer.rb @@ -1,6 +1,6 @@ module TypeSanitizer def self.sanitize_c_identifier(unsanitized) # convert filename to valid C identifier by replacing invalid chars with '_' - unsanitized.gsub(/[-\/\\\.\,\s]/, '_') + unsanitized.gsub(/[-\/\\.,\s]/, '_') end end diff --git a/auto/unity_test_summary.rb b/auto/unity_test_summary.rb index c31b1d5..0253b5d 100644 --- a/auto/unity_test_summary.rb +++ b/auto/unity_test_summary.rb @@ -86,8 +86,9 @@ class UnityTestSummary def get_details(_result_file, lines) results = { failures: [], ignores: [], successes: [] } lines.each do |line| - status_match = line.match(/^[^:]+:[^:]+:\w+(?:\([^\)]*\))?:([^:]+):?/) + status_match = line.match(/^[^:]+:[^:]+:\w+(?:\([^)]*\))?:([^:]+):?/) next unless status_match + status = status_match.captures[0] line_out = (@root && (@root != 0) ? "#{@root}#{line}" : line).gsub(/\//, '\\') diff --git a/auto/yaml_helper.rb b/auto/yaml_helper.rb index e5a0865..3296ba0 100644 --- a/auto/yaml_helper.rb +++ b/auto/yaml_helper.rb @@ -8,8 +8,11 @@ require 'yaml' module YamlHelper def self.load(body) - YAML.respond_to?(:unsafe_load) ? - YAML.unsafe_load(body) : YAML.load(body) + if YAML.respond_to?(:unsafe_load) + YAML.unsafe_load(body) + else + YAML.load(body) + end end def self.load_file(file) diff --git a/examples/example_3/rakefile_helper.rb b/examples/example_3/rakefile_helper.rb index 4906075..d88df58 100644 --- a/examples/example_3/rakefile_helper.rb +++ b/examples/example_3/rakefile_helper.rb @@ -42,7 +42,7 @@ def extract_headers(filename) includes = [] lines = File.readlines(filename) lines.each do |line| - m = line.match(/^\s*#include\s+\"\s*(.+\.[hH])\s*\"/) + m = line.match(/^\s*#include\s+"\s*(.+\.[hH])\s*"/) includes << m[1] unless m.nil? end includes @@ -57,12 +57,11 @@ def find_source_file(header, paths) end def tackit(strings) - result = if strings.is_a?(Array) - "\"#{strings.join}\"" - else - strings - end - result + if strings.is_a?(Array) + "\"#{strings.join}\"" + else + strings + end end def squash(prefix, items) @@ -80,7 +79,7 @@ def build_compiler_fields end options = squash('', $cfg['compiler']['options']) includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) - includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) + includes = includes.gsub(/\\ /, ' ').gsub(/\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) { command: command, defines: defines, options: options, includes: includes } end @@ -105,7 +104,7 @@ def build_linker_fields '' else squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items']) - end.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) + end.gsub(/\\ /, ' ').gsub(/\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) { command: command, options: options, includes: includes } end diff --git a/test/.rubocop.yml b/test/.rubocop.yml index 6c9542f..44b0160 100644 --- a/test/.rubocop.yml +++ b/test/.rubocop.yml @@ -3,7 +3,7 @@ #inherit_from: .rubocop_todo.yml AllCops: - TargetRubyVersion: 2.3 + TargetRubyVersion: 3.0 # These are areas where ThrowTheSwitch's coding style diverges from the Ruby standard Style/SpecialGlobalVars: @@ -36,10 +36,12 @@ Style/FormatStringToken: Enabled: false # This is disabled because it seems to get confused over nested hashes -Layout/AlignHash: +Layout/HashAlignment: Enabled: false EnforcedHashRocketStyle: table EnforcedColonStyle: table +Layout/LineLength: + Enabled: false # We purposefully use these insecure features because they're what makes Ruby awesome Security/Eval: @@ -64,8 +66,6 @@ Metrics/ClassLength: Enabled: false Metrics/CyclomaticComplexity: Enabled: false -Metrics/LineLength: - Enabled: false Metrics/MethodLength: Enabled: false Metrics/ModuleLength: