Fix Rubocop offenses after Rubocop was reconfigured

This commit is contained in:
Felix Auringer
2021-05-25 12:45:38 +02:00
committed by Sebastian Serth
parent fc6aa12b0a
commit 63d997a7e3
6 changed files with 29 additions and 27 deletions

View File

@ -49,14 +49,15 @@ module SubmissionScoring
private :execute_test_file
def feedback_message(file, output)
# set_locale
def feedback_message(_file, output)
# TODO: why did we comment out set_locale and render_markdown?
set_locale
if output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_test'
I18n.t('exercises.implement.default_test_feedback')
elsif output[:score] == Assessor::MAXIMUM_SCORE && output[:file_role] == 'teacher_defined_linter'
I18n.t('exercises.implement.default_linter_feedback')
else
# render_markdown(file.feedback_message)
render_markdown(file.feedback_message)
end
end

View File

@ -9,7 +9,7 @@ class SubmissionsController < ApplicationController
include Tubesock::Hijack
before_action :set_submission,
only: %i[download download_file render_file run score extract_errors show statistics test]
only: %i[download download_file render_file run score extract_errors show statistics]
before_action :set_files, only: %i[download download_file render_file show run]
before_action :set_file, only: %i[download_file render_file run]
before_action :set_mime_type, only: %i[download_file render_file]
@ -134,7 +134,7 @@ class SubmissionsController < ApplicationController
def handle_websockets(tubesock, runner, socket)
tubesock.send_data JSON.dump({'cmd' => 'status', 'status' => :container_running})
@output = String.new
@output = +''
socket.on :output do |data|
Rails.logger.info("#{Time.zone.now.getutc}: Container sending: #{data}")
@ -162,14 +162,14 @@ class SubmissionsController < ApplicationController
tubesock.onmessage do |event|
event = JSON.parse(event).deep_symbolize_keys
case event[:cmd].to_sym
when :client_kill
EventMachine.stop_event_loop
kill_socket(tubesock)
Rails.logger.debug('Client exited container.')
when :result
socket.send event[:data]
else
Rails.logger.info("Unknown command from client: #{event[:cmd]}")
when :client_kill
EventMachine.stop_event_loop
kill_socket(tubesock)
Rails.logger.debug('Client exited container.')
when :result
socket.send event[:data]
else
Rails.logger.info("Unknown command from client: #{event[:cmd]}")
end
rescue JSON::ParserError
Rails.logger.debug { "Data received from client is not valid json: #{data}" }
@ -239,9 +239,8 @@ class SubmissionsController < ApplicationController
def score
Thread.new do
hijack do |tubesock|
if @embed_options[:disable_run]
return kill_socket(tubesock)
end
return kill_socket(tubesock) if @embed_options[:disable_run]
tubesock.send_data(@submission.calculate_score)
# To enable hints when scoring a submission, uncomment the next line:
# send_hints(tubesock, StructuredError.where(submission: @submission))
@ -268,7 +267,7 @@ class SubmissionsController < ApplicationController
# private :set_docker_client
def set_file
@file = @files.detect { |file| file.name_with_extension == sanitize_filename }
@file = @files.detect {|file| file.name_with_extension == sanitize_filename }
head :not_found unless @file
end
private :set_file

View File

@ -22,18 +22,18 @@ class Runner < ApplicationRecord
return runner if runner.save
raise(RunnerNotAvailableError, 'No runner available')
raise RunnerNotAvailableError.new('No runner available')
end
def copy_files(files)
url = "#{runner_url}/files"
body = {files: files.map { |filename, content| {filepath: filename, content: content} }}
body = {files: files.map {|filename, content| {filepath: filename, content: content} }}
response = Faraday.patch(url, body.to_json, HEADERS)
return unless response.status == 404
# runner has disappeared for some reason
destroy
raise(RunnerNotAvailableError, 'Runner unavailable')
raise RunnerNotAvailableError.new('Runner unavailable')
end
def execute_command(command)
@ -42,7 +42,7 @@ class Runner < ApplicationRecord
if response.status == 404
# runner has disappeared for some reason
destroy
raise(RunnerNotAvailableError, 'Runner unavailable')
raise RunnerNotAvailableError.new('Runner unavailable')
end
parse response
end

View File

@ -72,7 +72,7 @@ class Submission < ApplicationRecord
# expects the full file path incl. file extension
# Caution: There must be no unnecessary path prefix included.
# Use `file.ext` rather than `./file.ext`
collect_files.detect { |file| file.filepath == file_path }
collect_files.detect {|file| file.filepath == file_path }
end
def normalized_score
@ -165,7 +165,7 @@ class Submission < ApplicationRecord
container_execution_time: execution_time,
status: exit_code.zero? ? :ok : :failed,
stdout: stdout,
stderr: stderr
stderr: stderr,
}
test_result(output, file)
end
@ -202,7 +202,7 @@ class Submission < ApplicationRecord
end
def command_for(template, file)
filepath = collect_files.find { |f| f.name_with_extension == file }.filepath
filepath = collect_files.find {|f| f.name_with_extension == file }.filepath
template % command_substitutions(filepath)
end
@ -210,7 +210,7 @@ class Submission < ApplicationRecord
{
class_name: File.basename(filename, File.extname(filename)).camelize,
filename: filename,
module_name: File.basename(filename, File.extname(filename)).underscore
module_name: File.basename(filename, File.extname(filename)).underscore,
}
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateRunners < ActiveRecord::Migration[6.1]
def change
create_table :runners do |t|

View File

@ -11,10 +11,10 @@ class RunnerConnection
@socket = Faye::WebSocket::Client.new(url, [], ping: 5)
%i[open message error close].each do |event_type|
@socket.on(event_type) { |event| __send__(:"on_#{event_type}", event) }
@socket.on(event_type) {|event| __send__(:"on_#{event_type}", event) }
end
EVENTS.each { |event_type| instance_variable_set(:"@#{event_type}_callback", ->(e) {}) }
EVENTS.each {|event_type| instance_variable_set(:"@#{event_type}_callback", ->(e) {}) }
@start_callback = -> {}
@exit_code = 0
end