Bump rubocop up to newer ruby versions (in progress)

This commit is contained in:
Mark VanderVoord
2023-02-16 16:40:23 -05:00
parent 7a31075b77
commit a7639eeb54
9 changed files with 30 additions and 27 deletions

View File

@ -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

View File

@ -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] }]

View File

@ -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)$/

View File

@ -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]

View File

@ -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

View File

@ -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(/\//, '\\')

View File

@ -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)

View File

@ -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

View File

@ -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: