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.
This commit is contained in:
Javi Martín
2022-08-25 22:15:53 +02:00
parent f800a02a42
commit 5ec7f4a339
3 changed files with 9 additions and 3 deletions

View File

@@ -485,6 +485,12 @@ Style/ClassVars:
Style/CollectionMethods: Style/CollectionMethods:
Enabled: true Enabled: true
Style/FileRead:
Enabled: true
Style/FileWrite:
Enabled: true
Style/HashConversion: Style/HashConversion:
Enabled: true Enabled: true

View File

@@ -2,7 +2,7 @@ module JsonExporter
def to_json_file(filename) def to_json_file(filename)
data = [] data = []
model.find_each { |record| data << json_values(record) } 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 end
private private

View File

@@ -216,9 +216,9 @@ describe "Machine learning" do
kind: "comments_summary", kind: "comments_summary",
updated_at: 2.minutes.from_now) updated_at: 2.minutes.from_now)
comments_file = MachineLearning::DATA_FOLDER.join(MachineLearning.comments_filename) 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) 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 end
visit admin_machine_learning_path visit admin_machine_learning_path