From 5ec7f4a3391505d9e1192e7f4c9a83bdd6e08442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 25 Aug 2022 22:15:53 +0200 Subject: [PATCH] Add and apply FileRead and FileWrite rubocop rules They were added in Rubocop 1.24.0. Even if we were already applying FileRead everywhere, this is something we've manually fixed in the past. Another reason to add it is that these rules are deeply related. --- .rubocop.yml | 6 ++++++ app/models/concerns/json_exporter.rb | 2 +- spec/system/admin/machine_learning_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 94b2b1a4e..d8b0e5bc2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -485,6 +485,12 @@ Style/ClassVars: Style/CollectionMethods: Enabled: true +Style/FileRead: + Enabled: true + +Style/FileWrite: + Enabled: true + Style/HashConversion: Enabled: true diff --git a/app/models/concerns/json_exporter.rb b/app/models/concerns/json_exporter.rb index b06ce42d2..171200fc6 100644 --- a/app/models/concerns/json_exporter.rb +++ b/app/models/concerns/json_exporter.rb @@ -2,7 +2,7 @@ module JsonExporter def to_json_file(filename) data = [] model.find_each { |record| data << json_values(record) } - File.open(filename, "w") { |file| file.write(data.to_json) } + File.write(filename, data.to_json) end private diff --git a/spec/system/admin/machine_learning_spec.rb b/spec/system/admin/machine_learning_spec.rb index 32a59f281..03a476026 100644 --- a/spec/system/admin/machine_learning_spec.rb +++ b/spec/system/admin/machine_learning_spec.rb @@ -216,9 +216,9 @@ describe "Machine learning" do kind: "comments_summary", updated_at: 2.minutes.from_now) comments_file = MachineLearning::DATA_FOLDER.join(MachineLearning.comments_filename) - File.open(comments_file, "w") { |file| file.write([].to_json) } + File.write(comments_file, [].to_json) proposals_comments_summary_file = MachineLearning::DATA_FOLDER.join(MachineLearning.proposals_comments_summary_filename) - File.open(proposals_comments_summary_file, "w") { |file| file.write([].to_json) } + File.write(proposals_comments_summary_file, [].to_json) end visit admin_machine_learning_path