Fix Rubocop offenses

This commit is contained in:
Sebastian Serth
2023-06-11 20:46:45 +02:00
parent 5a10e04121
commit bcdc71021e
19 changed files with 39 additions and 39 deletions

View File

@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base
MEMBER_ACTIONS = %i[destroy edit show update].freeze
RENDER_HOST = CodeOcean::Config.new(:code_ocean).read[:render_host]
LEGAL_SETTINGS = CodeOcean::Config.new(:code_ocean).read[:legal] || {}
MONITORING_USER_AGENT = Regexp.compile(/updown\.io/).freeze
MONITORING_USER_AGENT = /updown\.io/
before_action :deny_access_from_render_host
after_action :verify_authorized, except: %i[welcome]

View File

@ -67,7 +67,7 @@ module ProformaService
zip_file.map(&:name)
end
filenames.select {|f| f[/\.xml$/] }.any?
filenames.any? {|f| f[/\.xml$/] }
rescue Zip::Error
raise Proforma::InvalidZip
end

View File

@ -4,17 +4,17 @@ class MigrateTestruns < ActiveRecord::Migration[6.1]
# We are not changing any tables but only backfilling data.
disable_ddl_transaction!
SPLIT_OUTPUT = Regexp.compile(/(?<meta>message: (?<message>.*)\n|status: (?<status>.*)\n)? stdout: (?<stdout>.*)\n stderr: ?(?<stderr>.*)/m)
PYTHON_BYTE_OUTPUT = Regexp.compile(/^b'(?<raw_output>.*)'$/)
PYTHON_JSON_OUTPUT = Regexp.compile(/{"cmd":"write","stream":"(?<stream>.*)","data":"(?<data_output>.*)"}/)
RUN_OUTPUT = Regexp.compile(%r{(?<prefix>timeout:)? ?(?>make run\r\n)?(?>python3 /usr/lib/[^\r\n]*\r\n|/usr/bin/python3[^\r\n]*\r\n|ruby [^\r\n]*\r\n)?(?<cleaned_output>[^ "\e][^\e]*?[^#\e])?(?<shell>\r\e.*?)?#?(?<suffix>exit|timeout)?\r?\Z}m)
REAL_EXIT = Regexp.compile(/\A(?>(?<json>(?<json_output>{".*?)?(?>{"cmd":(?> |"write","stream":"stdout","data":)?"#?exit(?>\\[nr])?"})+(?<more_shell_output_after_json>.*))|(?<program_output>.*?)(?>#?exit\s*)+(?<more_shell_output_after_program>.*))\z/m)
STDERR_WRITTEN = Regexp.compile(/^(?:(?<rb_error>\r*[^\n\r]*\.rb:\d+:.*)|(?<other_error>\r*[^\n\r]*\.java:\d+: error.*|\r*Exception in thread.*|\r*There was .*|\r*[^\n\r]*java\.lang\..*|\r*make: \*\*\* \[.*))\z/m)
FIND_JSON = Regexp.compile(/{(?:(?:"(?:\\.|[^\\"])+?"\s*:\s*(?:"(?:\\.|[^\\"])*?"|-?\d++(?:\.\d++)?|\[.*?\]|{.*?}|null))+?\s*,?\s*)+}/)
SPLIT_OUTPUT = /(?<meta>message: (?<message>.*)\n|status: (?<status>.*)\n)? stdout: (?<stdout>.*)\n stderr: ?(?<stderr>.*)/m
PYTHON_BYTE_OUTPUT = /^b'(?<raw_output>.*)'$/
PYTHON_JSON_OUTPUT = /{"cmd":"write","stream":"(?<stream>.*)","data":"(?<data_output>.*)"}/
RUN_OUTPUT = %r{(?<prefix>timeout:)? ?(?>make run\r\n)?(?>python3 /usr/lib/[^\r\n]*\r\n|/usr/bin/python3[^\r\n]*\r\n|ruby [^\r\n]*\r\n)?(?<cleaned_output>[^ "\e][^\e]*?[^#\e])?(?<shell>\r\e.*?)?#?(?<suffix>exit|timeout)?\r?\Z}m
REAL_EXIT = /\A(?>(?<json>(?<json_output>{".*?)?(?>{"cmd":(?> |"write","stream":"stdout","data":)?"#?exit(?>\\[nr])?"})+(?<more_shell_output_after_json>.*))|(?<program_output>.*?)(?>#?exit\s*)+(?<more_shell_output_after_program>.*))\z/m
STDERR_WRITTEN = /^(?:(?<rb_error>\r*[^\n\r]*\.rb:\d+:.*)|(?<other_error>\r*[^\n\r]*\.java:\d+: error.*|\r*Exception in thread.*|\r*There was .*|\r*[^\n\r]*java\.lang\..*|\r*make: \*\*\* \[.*))\z/m
FIND_JSON = /{(?:(?:"(?:\\.|[^\\"])+?"\s*:\s*(?:"(?:\\.|[^\\"])*?"|-?\d++(?:\.\d++)?|\[.*?\]|{.*?}|null))+?\s*,?\s*)+}/
# We identify incomplete Unicode characters. Valid unicode characters are:
# \uXXXX, \u{XXXXX}, \udYXX\udZXX with X = 0-9a-f, Y = 89ab, Z = cdef
# Every incomplete prefix of a valid unicode character is identified
REPLACE_INCOMPLETE_UNICODE = Regexp.compile(/(?:\\?\\u[\da-f]{0,3}|\\?\\ud[89ab][\da-f]{2}\\?(?:\\(?:u(?:d(?:[cdef][\da-f]?)?)?)?)?|\\?\\u\{[\da-f]{0,4})"}\z/)
REPLACE_INCOMPLETE_UNICODE = /(?:\\?\\u[\da-f]{0,3}|\\?\\ud[89ab][\da-f]{2}\\?(?:\\(?:u(?:d(?:[cdef][\da-f]?)?)?)?)?|\\?\\u\{[\da-f]{0,4})"}\z/
# NOTE: `update_columns` won't run validations nor update the `updated_at` timestamp.
# This is what we want here, thus we disable Rubocop for this migration.

View File

@ -6,7 +6,7 @@ class Runner::Connection::Buffer
# substring either in single or double quotes (e.g., within a JSON). Originally, each line break consists of `\r\n`.
# We keep the `\r` at the end of the line (keeping "empty" lines) and replace it after buffering.
# Inspired by https://stackoverflow.com/questions/13040585/split-string-by-spaces-properly-accounting-for-quotes-and-backslashes-ruby
SPLIT_INDIVIDUAL_LINES = Regexp.compile(/(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^\n])+/)
SPLIT_INDIVIDUAL_LINES = /(?:"(?:\\"|[^"])*"|'(?:\\'|[^'])*'|[^\n])+/
def initialize
@global_buffer = +''

View File

@ -6,15 +6,15 @@ module CodeOcean
FactoryBot.define do
factory :file, class: 'CodeOcean::File' do
content { '' }
association :context, factory: :submission
association :file_type, factory: :dot_rb
context factory: :submission
file_type factory: :dot_rb
hidden { false }
name { SecureRandom.hex }
read_only { false }
role { 'main_file' }
trait(:image) do
association :file_type, factory: :dot_png
file_type factory: :dot_png
name { 'poster' }
native_file { Rack::Test::UploadedFile.new(Rails.root.join('db/seeds/audio_video/poster.png'), 'image/png') }
end
@ -22,8 +22,8 @@ module CodeOcean
factory :test_file, class: 'CodeOcean::File' do
content { '' }
association :context, factory: :dummy
association :file_type, factory: :dot_rb
context factory: :dummy
file_type factory: :dot_rb
hidden { true }
name { SecureRandom.hex }
read_only { true }

View File

@ -2,7 +2,7 @@
FactoryBot.define do
factory :codeharbor_link do
user { build(:teacher) }
user factory: :teacher
push_url { 'https://push.url' }
check_uuid_url { 'https://check-uuid.url' }
sequence(:api_key) {|n| "api_key#{n}" }

View File

@ -2,7 +2,7 @@
FactoryBot.define do
factory :error_template do
association :execution_environment, factory: :ruby
execution_environment factory: :ruby
name { 'MyString' }
signature { 'MyString' }
end

View File

@ -2,7 +2,7 @@
FactoryBot.define do
factory :external_user do
association :consumer
consumer
generated_email
external_id { SecureRandom.uuid }
generated_user_name

View File

@ -3,7 +3,7 @@
FactoryBot.define do
factory :admin, class: 'InternalUser' do
activated_user
association :consumer
consumer
email { 'admin@example.org' }
generated_user_name
password { 'admin' }
@ -17,7 +17,7 @@ FactoryBot.define do
factory :teacher, class: 'InternalUser' do
activated_user
association :consumer
consumer
generated_email
generated_user_name
password { 'teacher' }
@ -31,7 +31,7 @@ FactoryBot.define do
factory :learner, class: 'InternalUser' do
activated_user
association :consumer
consumer
generated_email
generated_user_name
password { 'learner' }

View File

@ -8,9 +8,9 @@ FactoryBot.define do
}.freeze
factory :lti_parameter do
association :consumer
association :exercise, factory: :math
association :external_user
consumer
exercise factory: :math
external_user
lti_parameters { lti_params }

View File

@ -2,10 +2,10 @@
FactoryBot.define do
factory :rfc, class: 'RequestForComment' do
association :user, factory: :external_user
association :exercise, factory: :math
user factory: :external_user
exercise factory: :math
submission { association :submission, exercise:, user: }
association :file
file
sequence :question do |n|
"test question #{n}"
end

View File

@ -4,7 +4,7 @@
FactoryBot.define do
factory :runner do
runner_id { SecureRandom.uuid }
association :execution_environment, factory: :ruby
association :user, factory: :external_user
execution_environment factory: :ruby
user factory: :external_user
end
end

View File

@ -3,7 +3,7 @@
FactoryBot.define do
%i[admin external_user teacher].each do |factory_name|
trait :"created_by_#{factory_name}" do
association :user, factory: factory_name
user factory: factory_name
end
end

View File

@ -2,8 +2,8 @@
FactoryBot.define do
factory :structured_error_attribute do
association :structured_error
association :error_template_attribute
structured_error
error_template_attribute
value { 'MyString' }
end
end

View File

@ -2,7 +2,7 @@
FactoryBot.define do
factory :structured_error do
association :error_template
association :submission
error_template
submission
end
end

View File

@ -2,7 +2,7 @@
FactoryBot.define do
factory :study_group, class: 'StudyGroup' do
association :consumer
consumer
sequence :name do |n|
"TestGroup#{n}"
end

View File

@ -4,7 +4,7 @@ FactoryBot.define do
factory :submission do
cause { 'save' }
created_by_external_user
association :exercise, factory: :math
exercise factory: :math
after(:create) do |submission|
submission.exercise.files.editable.visible.each do |file|

View File

@ -4,6 +4,6 @@ FactoryBot.define do
factory :user_exercise_feedback, class: 'UserExerciseFeedback' do
created_by_external_user
feedback_text { 'Most suitable exercise ever' }
association :exercise, factory: :math
exercise factory: :math
end
end

View File

@ -184,7 +184,7 @@ describe RequestForCommentPolicy do
end
it 'does not grant access to authors of another primary study groups' do
rfc_other_study_group.author.update(study_groups: [create(:study_group)])
rfc_other_study_group.author.update(study_groups: create_list(:study_group, 1))
expect(policy).not_to permit(rfc_other_study_group.author, rfc_other_study_group)
end