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

Add suspicious_open_options lint. #11608

Merged
merged 6 commits into from
Jan 16, 2024
Merged

Commits on Jan 15, 2024

  1. Add suspicious_open_options lint.

    Checks for the suspicious use of OpenOptions::create()
    without an explicit OpenOptions::truncate().
    
    create() alone will either create a new file or open an
    existing file. If the file already exists, it will be
    overwritten when written to, but the file will not be
    truncated by default. If less data is written to the file
    than it already contains, the remainder of the file will
    remain unchanged, and the end of the file will contain old
    data.
    In most cases, one should either use `create_new` to ensure
    the file is created from scratch, or ensure `truncate` is
    called so that the truncation behaviour is explicit.
    `truncate(true)` will ensure the file is entirely overwritten
    with new data, whereas `truncate(false)` will explicitely
    keep the default behavior.
    
    ```rust
    use std::fs::OpenOptions;
    
    OpenOptions::new().create(true).truncate(true);
    ```
    atwam committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    6c201db View commit details
    Browse the repository at this point in the history
  2. More helpful text, small style changes.

    atwam committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    6fb471d View commit details
    Browse the repository at this point in the history
  3. PR Fixes

    atwam committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    2ec8729 View commit details
    Browse the repository at this point in the history
  4. Add suggestion/fix to suspicious_open_options

    Also rebase and fix conflicts
    atwam committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    84588a8 View commit details
    Browse the repository at this point in the history
  5. Fix conflicts

    - New ineffective_open_options had to be fixed.
    - Now not raising an issue on missing `truncate` when `append(true)`
      makes the intent clear.
    - Try implementing more advanced tests for non-chained operations. Fail
    atwam committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    515fe65 View commit details
    Browse the repository at this point in the history
  6. fix false positive in suspicious_open_options, make paths work

    y21 authored and atwam committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    f09cd88 View commit details
    Browse the repository at this point in the history