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 a suggestions for safer conversions for Lint/NonAtomicFileOperation
#10781
Conversation
fd4cb08
to
818944a
Compare
Lint/NonAtomicFileOperation
Lint/NonAtomicFileOperation
fca0be1
to
fd5e30d
Compare
REMOVE_METHODS = %i[remove remove_dir remove_entry remove_entry_secure delete unlink | ||
remove_file rm rm_f rm_r rm_rf rmdir rmtree safe_unlink].freeze | ||
RESTRICT_ON_SEND = (MAKE_METHODS + REMOVE_METHODS).freeze | ||
MSG_REMOVE_FILE_EXIST_CHECK = 'Remove an unnecessary existence checks ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Remove unnecessary existence check"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much. I fixed it.
RESTRICT_ON_SEND = (MAKE_METHODS + REMOVE_METHODS).freeze | ||
MSG_REMOVE_FILE_EXIST_CHECK = 'Remove an unnecessary existence checks ' \ | ||
'`%<receiver>s.%<method_name>s`.' | ||
MSG_CHANGE_FORCE_METHOD = 'Change to a forced file operation method ' \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if most people would understand this. :D I get what you mean, but I had to think for a moment what's "forced file operation" in this context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for sure. I was wondering what to do with this sentence.
How about "Use atomic file operation methods" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much. I changed to "Use atomic file operation methods".
be6b0c6
to
2db1687
Compare
RESTRICT_ON_SEND = (MAKE_METHODS + REMOVE_METHODS).freeze | ||
MSG_REMOVE_FILE_EXIST_CHECK = 'Remove unnecessary existence check ' \ | ||
'`%<receiver>s.%<method_name>s`.' | ||
MSG_CHANGE_FORCE_METHOD = 'Use atomic file operation methods `FileUtils.%<method_name>s`.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
methods -> method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I updated this PR.
…ion` This PR is fix a suggestions for safer conversions for `Lint/NonAtomicFileOperation`. Change the uniform conversion to `rm_rf` or `mkdir_p` to a safe change proposal as follows. For non-recurrent file deletions ```ruby # bad if File.exist?(path) File.remove(path) end # good FileUtils.rm_f(path) ``` For cases that do not require replacement ```ruby # bad if File.exist?(path) FileUtils.makedirs(path) end # good FileUtils.makedirs(path) ``` In addition, when replacing a non-atomic file operation with a forced file creation or deletion, an offense message has been added as follows. ```ruby if FileTest.exist?(path) ^^^^^^^^^^^^^^^^^^^^^^^^ Remove an unnecessary existence checks `FileTest.exist?`. FileUtils.remove(path) ^^^^^^^^^^^^^^^^ Use atomic file operation method `FileUtils.rm_f`. end ```
2db1687
to
c95db16
Compare
Thanks! |
This PR is fix a suggestions for safer conversions for
Lint/NonAtomicFileOperation
.Change the uniform conversion to
rm_rf
ormkdir_p
to a safe change proposal as follows.For non-recurrent file deletions
For cases that do not require replacement
In addition, when replacing a non-atomic file operation with a forced file creation or deletion, an offense message has been added as follows.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.