Update bundle (with newest rubocop version) and fix offenses

This commit is contained in:
Sebastian Serth
2022-01-03 18:11:17 +01:00
parent 57e32611ed
commit ea85519163
93 changed files with 968 additions and 985 deletions

View File

@ -8,7 +8,7 @@ module ActiveModel
def validate(record)
[attributes].flatten.each do |attribute|
value = record.send(:read_attribute_for_validation, attribute)
record.errors.add(attribute, nil, options) unless BOOLEAN_VALUES.include?(value)
record.errors.add(attribute, nil, **options) unless BOOLEAN_VALUES.include?(value)
end
end
end

View File

@ -12,7 +12,7 @@ class Assessor
def calculate_score(test_outcome)
score = 0.0
if test_outcome[:passed].to_d != 0.0.to_d && test_outcome[:count].to_d != 0.0.to_d
if test_outcome[:passed].to_d != BigDecimal('0.0') && test_outcome[:count].to_d != BigDecimal('0.0')
score = (test_outcome[:passed].to_f / test_outcome[:count])
# prevent negative scores
score = [0.0, score].max

View File

@ -9,7 +9,9 @@ module CodeOcean
def read(options = {})
path = Rails.root.join('config', "#{@filename}.yml#{options[:erb] ? '.erb' : ''}")
if ::File.exist?(path)
content = options[:erb] ? YAML.safe_load(ERB.new(::File.new(path, 'r').read).result, aliases: true, permitted_classes: [Range]) : YAML.load_file(path)
yaml_content = ::File.new(path, 'r').read || ''
yaml_content = ERB.new(yaml_content).result if options[:erb]
content = YAML.safe_load(yaml_content, aliases: true, permitted_classes: [Range, Symbol])
content[Rails.env].with_indifferent_access
else
raise Error.new("Configuration file not found: #{path}")

View File

@ -17,7 +17,7 @@ class CppCatch2Adapter < TestingFrameworkAdapter
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
{count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)}
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
end
end
end

View File

@ -315,7 +315,7 @@ container_execution_time: nil}
@tubesock&.send_data JSON.dump({'cmd' => 'timeout'})
if @socket
begin
@socket.send('#timeout')
@socket.send('#timeout') # rubocop:disable Performance/StringIdentifierArgument
# sleep one more second to ensure that the message reaches the submissions_controller.
sleep(1)
@socket.close
@ -434,9 +434,9 @@ container_execution_time: nil}
end
def self.mapped_ports(execution_environment)
execution_environment.exposed_ports.map do |port|
execution_environment.exposed_ports.to_h do |port|
["#{port}/tcp", [{'HostPort' => PortPool.available_port.to_s}]]
end.to_h
end
end
def self.pull(docker_image)

View File

@ -16,7 +16,7 @@ class Junit5Adapter < TestingFrameworkAdapter
{count: count, passed: count}
else
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
{count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)}
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
end
end
end

View File

@ -17,7 +17,7 @@ class JunitAdapter < TestingFrameworkAdapter
count = output[:stdout].scan(COUNT_REGEXP).try(:last).try(:first).try(:to_i) || 0
failed = output[:stdout].scan(FAILURES_REGEXP).try(:last).try(:first).try(:to_i) || 0
error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
{count: count, failed: failed, error_messages: error_matches.flatten.reject(&:blank?)}
{count: count, failed: failed, error_messages: error_matches.flatten.compact_blank}
end
end
end

View File

@ -43,8 +43,8 @@ class PyLintAdapter < TestingFrameworkAdapter
{
count: count,
failed: failed,
error_messages: concatenated_errors.flatten.reject(&:blank?),
detailed_linter_results: assertion_error_matches.flatten.reject(&:blank?),
error_messages: concatenated_errors.flatten.compact_blank,
detailed_linter_results: assertion_error_matches.flatten.compact_blank,
}
end

View File

@ -32,6 +32,6 @@ class PyUnitAdapter < TestingFrameworkAdapter
Sentry.capture_message({stderr: output[:stderr], regex: ASSERTION_ERROR_REGEXP}.to_json)
assertion_error_matches = []
end
{count: count, failed: failed + errors, error_messages: assertion_error_matches.flatten.reject(&:blank?)}
{count: count, failed: failed + errors, error_messages: assertion_error_matches.flatten.compact_blank}
end
end

View File

@ -14,6 +14,6 @@ class RScriptAdapter < TestingFrameworkAdapter
passed = captures.second
failed = count - passed
assertion_error_matches = output[:stdout].scan(ASSERTION_ERROR_REGEXP) || []
{count: count, failed: failed, error_messages: assertion_error_matches.flatten.reject(&:blank?)}
{count: count, failed: failed, error_messages: assertion_error_matches.flatten.compact_blank}
end
end

View File

@ -97,7 +97,7 @@ class Runner::Strategy::DockerContainerPool < Runner::Strategy
FileUtils.cp(file.native_file.path, local_file_path)
else
begin
File.open(local_file_path, 'w') {|f| f.write(file.content) }
File.write(local_file_path, file.content)
rescue IOError => e
raise Runner::Error::WorkspaceError.new("Could not create file #{file.filepath}: #{e.inspect}")
end