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 a suggestions for safer conversions for Lint/NonAtomicFileOperation #10781

Merged
merged 1 commit into from Jul 7, 2022

Commits on Jul 7, 2022

  1. 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
    ```
    ydah committed Jul 7, 2022
    Copy the full SHA
    c95db16 View commit details
    Browse the repository at this point in the history