Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Rubocop/Style 1 #20338

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,66 +393,6 @@ Rails/UniqueValidationWithoutIndex:
- 'app/models/invalid_letter_address_edipi.rb'
- 'modules/va_forms/app/models/va_forms/form.rb'

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: params
Style/CollectionCompact:
Exclude:
- 'lib/saml/user_attributes/ssoe.rb'

# Offense count: 2
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ConcatArrayLiterals:
Exclude:
- 'spec/factories/form526_submissions.rb'

# Offense count: 31
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedVars.
Style/FetchEnvVar:
Exclude:
- 'rakelib/breakers_outage.rake'
- 'rakelib/mvi.rake'
- 'rakelib/vet360.rake'
- 'spec/rails_helper.rb'
- 'spec/support/rswag/text_helpers.rb'

# Offense count: 8
# This cop supports safe autocorrection (--autocorrect).
Style/FileRead:
Exclude:
- 'app/sidekiq/evss/disability_compensation_form/evss_document.rb'
- 'app/sidekiq/evss/disability_compensation_form/submit_form0781.rb'
- 'modules/dhp_connected_devices/app/services/token_storage_service.rb'
- 'modules/mobile/lib/scripts/appointments_list_validation.rb'
- 'modules/vba_documents/spec/lib/multipart_parser_spec.rb'
- 'modules/vba_documents/spec/models/upload_file_spec.rb'
- 'modules/vba_documents/spec/sidekiq/upload_processor_spec.rb'
- 'spec/lib/hca/service_spec.rb'

# Offense count: 12
# This cop supports safe autocorrection (--autocorrect).
Style/FileWrite:
Exclude:
- 'lib/common/file_helpers.rb'
- 'lib/sftp_writer/local.rb'
- 'modules/claims_api/app/models/claims_api/power_of_attorney.rb'
- 'modules/dhp_connected_devices/app/services/token_storage_service.rb'
- 'modules/mobile/app/services/mobile/v0/claims/proxy.rb'
- 'rakelib/mockdata_synchronize.rake'
- 'rakelib/mvi.rake'
- 'spec/lib/tasks/support/schema_camelizer_spec.rb'
- 'spec/rswag_override.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedReceivers.
# AllowedReceivers: Thread.current
Style/HashEachMethods:
Exclude:
- 'lib/common/hash_helpers.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashExcept:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EVSSDocument
# @return [String] the contents of the file
#
def file_body
File.open(@pdf_path).read
File.read(@pdf_path)
end

# @return [EVSSClaimDocument] A new claim document instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def upload_to_vbms(pdf_path, form_id)
raise Common::Exceptions::ValidationErrors, document_data unless document_data.valid?

# thin wrapper to isolate upload for logging
file_body = File.open(pdf_path).read
file_body = File.read(pdf_path)
perform_client_upload(file_body, document_data, form_id)
ensure
# Delete the temporary PDF file
Expand Down
8 changes: 2 additions & 6 deletions lib/common/file_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def random_file_path
def generate_random_file(file_body)
file_path = random_file_path

File.open(file_path, 'wb') do |file|
file.write(file_body)
end
File.binwrite(file_path, file_body)

file_path
end
Expand All @@ -31,9 +29,7 @@ def generate_clamav_temp_file(file_body, file_name = nil)

file_path = "clamav_tmp/#{file_name}"

File.open(file_path, 'wb') do |file|
file.write(file_body)
end
File.binwrite(file_path, file_body)

file_path
end
Expand Down
4 changes: 2 additions & 2 deletions lib/saml/user_attributes/ssoe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def safe_attr(key)

def mhv_iens
mhv_iens = mvi_ids[:mhv_iens] || []
mhv_iens.append(safe_attr('va_eauth_mhvuuid')).reject(&:nil?).uniq
mhv_iens.append(safe_attr('va_eauth_mhvuuid')).compact.uniq
end

def mhv_outbound_redirect(mismatched_ids_error)
Expand Down Expand Up @@ -284,7 +284,7 @@ def sec_id_mismatch?

def attribute_has_multiple_values?(attribute)
var = safe_attr(attribute)&.split(',') || []
var.reject(&:nil?).uniq.size > 1
var.compact.uniq.size > 1
end

def csid
Expand Down
4 changes: 1 addition & 3 deletions lib/sftp_writer/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ def write_path(_filename)
def write(contents, filename)
path = File.join(write_path(filename), filename)
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'wb') do |f|
f.write(contents)
end
File.binwrite(path, contents)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ def signature_image_paths

def create_signature_image(signature_type)
path = "/tmp/#{signature_type}_#{id}_signature.png"
File.open(path, 'wb') do |f|
f.write(Base64.decode64(form_data.dig('signatures', signature_type)))
end
File.binwrite(path, Base64.decode64(form_data.dig('signatures', signature_type)))
signature_image_paths[signature_type] = path
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ def store_locally(current_user, device_key, payload_json)
begin
dirname = File.dirname(token_file_path)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
File.open(token_file_path, 'w+') do |file|
file.write(payload_json)
end
File.write(token_file_path, payload_json)
true
rescue => e
raise TokenStorageError, "Error with storing locally: #{payload_json}, #{e}"
Expand All @@ -187,7 +185,7 @@ def store_locally(current_user, device_key, payload_json)
def get_locally(current_user, device_key)
token_file_path = token_file_path(generate_prefix(current_user, device_key))
begin
token = File.open(token_file_path, 'r').read
token = File.read(token_file_path)
JSON.parse(token).deep_symbolize_keys!
rescue => e
raise TokenRetrievalError, "Error retrieving token locally for icn: #{current_user.icn}, #{e}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
end

it 'returns error when token was not stored locally' do
allow_any_instance_of(File).to receive(:write).with(any_args).and_raise(TokenStorageError)
allow_any_instance_of(File).to receive(:read).with(any_args).and_raise(TokenStorageError)
allow(File).to receive(:write).and_raise(Errno::ENOENT)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File methods don't specifically raise TokenStorageError, so I chose an error it could potentially raise (though it doesn't really matter).


expect { subject.store_tokens(current_user, @device_key, @token_hash) }.to raise_error(TokenStorageError)
end
Expand Down Expand Up @@ -158,12 +157,14 @@
end

it 'returns token when token file is present in tmp folder' do
allow(File).to receive(:open).and_return(@token_as_string_io)
allow(File).to receive(:read).and_return(@token_json_with_payload_key)

expect(subject.get_token(current_user, @device_key)).to eq(@token_hash_with_payload_key)
end

it 'returns TokenRetrievalError when token file is not present' do
allow_any_instance_of(File).to receive(:read).with(any_args).and_raise(TokenRetrievalError)
allow(File).to receive(:read).and_raise(Errno::ENOENT)

expect { subject.get_token(current_user, @device_key) }.to raise_error(TokenRetrievalError)
end
end
Expand Down
2 changes: 1 addition & 1 deletion modules/mobile/app/services/mobile/v0/claims/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def generate_multi_image_pdf(image_list)
FileUtils.mkpath @base_path
Prawn::Document.generate(pdf_path) do |pdf|
image_list.each do |img|
File.open(img_path, 'wb') { |f| f.write Base64.decode64(img) }
File.binwrite(img_path, Base64.decode64(img))
img = MiniMagick::Image.open(img_path)
if img.height > pdf.bounds.top || img.width > pdf.bounds.right
pdf.image img_path, fit: [pdf.bounds.right, pdf.bounds.top]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def read_text_files
files = Dir["#{@path_to_html}/*.txt"]
files.map do |file|
puts "READING FILE: #{file}"
File.open(file).read
File.read(file)
end
end

Expand Down
2 changes: 1 addition & 1 deletion modules/vba_documents/spec/lib/multipart_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class << self

def fetch(fixture, type)
r_val = fixture.path
r_val = StringIO.new File.open(r_val, 'rb').read if type.eql? :stringio
r_val = StringIO.new File.binread(r_val) if type.eql? :stringio
r_val
end
end
Expand Down
2 changes: 1 addition & 1 deletion modules/vba_documents/spec/models/upload_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

it 'can upload and purge from storage' do
upload_model = VBADocuments::UploadFile.new
base_64 = File.open(get_fixture('base_64')).read
base_64 = File.read(get_fixture('base_64'))
upload_model.multipart.attach(io: StringIO.new(base_64), filename: upload_model.guid)
upload_model.save!
upload_model.parse_and_upload!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
pids.each { |pid| Process.waitpid(pid) } # wait for my children to complete
responses = []
temp_files.each do |tf|
responses << File.open(tf.path, &:read)
responses << File.read(tf.path)
end
expect(responses.select { |e| e.eql?('true') }.length).to eq(1)
expect(responses.select { |e| e.eql?('false') }.length).to eq(num_times - 1)
Expand Down
8 changes: 4 additions & 4 deletions rakelib/breakers_outage.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ namespace :breakers do
desc 'Begin a forced outage (requires: service=<service_name>)'
task begin_forced_outage: :environment do
services = Breakers.client.services.map(&:name)
service = ENV['service']
service = ENV.fetch('service', nil)

raise ArgumentError, "[#{service}] is not a valid service in: #{services}" unless services.include?(ENV['service'])

Breakers.client.services.select { |s| s.name == service }.first.begin_forced_outage!

puts "Successfully forced outage of: [#{ENV['service']}]"
puts "Successfully forced outage of: [#{ENV.fetch('service', nil)}]"
end

# e.g. bundle exec rake breakers:end_forced_outage service=EVSS/Documents
desc 'End a forced outage (requires: service=<service_name>)'
task end_forced_outage: :environment do
services = Breakers.client.services.map(&:name)
service = ENV['service']
service = ENV.fetch('service', nil)

raise ArgumentError, "[#{service}] is not a valid service in: #{services}" unless services.include?(ENV['service'])

Breakers.client.services.select { |s| s.name == service }.first.end_forced_outage!

puts "Successfully ended forced outage of: [#{ENV['service']}]"
puts "Successfully ended forced outage of: [#{ENV.fetch('service', nil)}]"
end
end
2 changes: 1 addition & 1 deletion rakelib/mockdata_synchronize.rake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace :mockdata_synchronize do
status: 200
}

File.open(file_path, 'w') { |f| f.write(response.to_yaml) }
File.write(file_path, response.to_yaml)
end

def create_curl(icn)
Expand Down
30 changes: 15 additions & 15 deletions rakelib/mvi.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace :mvi do

identity = UserIdentity.new(
uuid:,
first_name: ENV['first_name'],
middle_name: ENV['middle_name'],
last_name: ENV['last_name'],
birth_date: ENV['birth_date'],
gender: ENV['gender'],
ssn: ENV['ssn'],
first_name: ENV.fetch('first_name', nil),
middle_name: ENV.fetch('middle_name', nil),
last_name: ENV.fetch('last_name', nil),
birth_date: ENV.fetch('birth_date', nil),
gender: ENV.fetch('gender', nil),
ssn: ENV.fetch('ssn', nil),
email: '[email protected]',
loa: {
current: LOA::THREE,
Expand Down Expand Up @@ -125,13 +125,13 @@ namespace :mvi do

desc "Given a ssn update a mocked user's correlation ids"
task update_ids: :environment do
ssn = ENV['ssn']
ssn = ENV.fetch('ssn', nil)
raise ArgumentError, 'ssn is required, usage: `rake mvi:update_ids ssn=111223333 icn=abc123`' unless ssn

ids = {}
ids['icn'] = ENV['icn']
ids['edipi'] = ENV['edipi']
ids['participant_id'] = ENV['participant_id']
ids['icn'] = ENV.fetch('icn', nil)
ids['edipi'] = ENV.fetch('edipi', nil)
ids['participant_id'] = ENV.fetch('participant_id', nil)
ids['mhv_ids'] = ENV['mhv_ids']&.split
ids['vha_facility_ids'] = ENV['vha_facility_ids']&.split
# 5343578988
Expand All @@ -145,7 +145,7 @@ namespace :mvi do
xml = yaml[:body].dup.prepend('<?xml version="1.0" encoding="UTF-8"?>') unless xml.match?(/^<\?xml/)

yaml[:body] = update_ids(xml, ids)
File.open(path, 'w') { |f| f.write(yaml.to_yaml) }
File.write(path, yaml.to_yaml)

puts 'ids updated!'
end
Expand Down Expand Up @@ -242,13 +242,13 @@ def create_cache_from_profile(cache_file, profile, template)
status: 200
}

File.open(cache_file, 'w') { |f| f.write(response.to_yaml) }
File.write(cache_file, response.to_yaml)
end

def valid_user_vars
date_valid = validate_date(ENV['birth_date'])
name_valid = ENV['first_name'] && ENV['middle_name'] && ENV['last_name']
attrs_valid = ENV['gender'] && ENV['ssn']
date_valid = validate_date(ENV.fetch('birth_date', nil))
name_valid = ENV.fetch('first_name', nil) && ENV.fetch('middle_name', nil) && ENV.fetch('last_name', nil)
attrs_valid = ENV.fetch('gender', nil) && ENV.fetch('ssn', nil)
date_valid && name_valid && attrs_valid
end

Expand Down
Loading
Loading