Skip to content

Conversation

@github-actions
Copy link
Contributor

Rubocop challenge!

Style/FileWrite

Safe autocorrect: Yes
✅ The autocorrect a cop does is safe (equivalent) by design.

Description

Overview

Favor File.(bin)write convenience methods.

NOTE: There are different method signatures between File.write (class method)
and File#write (instance method). The following case will be allowed because
static analysis does not know the contents of the splat argument:

[source,ruby]

File.open(filename, 'w') do |f|
f.write(*objects)
end

Examples

## text mode
# bad
File.open(filename, 'w').write(content)
File.open(filename, 'w') do |f|
  f.write(content)
end

# good
File.write(filename, content)
## binary mode
# bad
File.open(filename, 'wb').write(content)
File.open(filename, 'wb') do |f|
  f.write(content)
end

# good
File.binwrite(filename, content)

Auto generated by rubocop_challenger

@mathieujobin mathieujobin merged commit e13f36e into master Jun 30, 2022
@mathieujobin mathieujobin deleted the rubocop-challenge/20220629233424 branch June 30, 2022 03:42
smshuja pushed a commit to TheTalentEnterprise/webhook_system that referenced this pull request Jan 25, 2024
* 🚓 regenerate rubocop todo

* 🚓 Style/FileWrite

* 🚓 regenerate rubocop todo

Co-authored-by: Rubocop Challenger <rubocop@payrollhero.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants