Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a suggestions for safer conversions for `Lint/NonAtomicFileOperat…
…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 ```
- Loading branch information
Showing
3 changed files
with
122 additions
and
38 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
changelog/fix_a_suggestions_for_safer_conversions_non_atomic_file_operation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#10781](https://github.com/rubocop/rubocop/pull/10781): Fix a suggestions for safer conversions for `Lint/NonAtomicFileOperation`. ([@ydah][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters