![github-actions[bot]](/assets/img/avatar_default.png)
* Create rule S7447 * Update RSPEC --------- Co-authored-by: yassin-kammoun-sonarsource <yassin-kammoun-sonarsource@users.noreply.github.com> Co-authored-by: yassin-kammoun-sonarsource <yassin.kammoun@sonarsource.com>
29 lines
892 B
Plaintext
29 lines
892 B
Plaintext
== Why is this an issue?
|
|
|
|
Using contradictory or nonsensical combinations of file open options, such as `read(true)` with `truncate(true)`, can lead to code that is confusing and harder to read. In some cases, it can result in runtime errors or undefined behavior, potentially causing data corruption or loss.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,rust,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
use std::fs::OpenOptions;
|
|
|
|
OpenOptions::new().read(true).truncate(true); // Noncompliant: Invalid combination of file open options.
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,rust,diff-id=1,diff-type=compliant]
|
|
----
|
|
use std::fs::OpenOptions;
|
|
|
|
OpenOptions::new().write(true).truncate(true); // Compliant: Valid combination of file open options.
|
|
----
|
|
|
|
== Resources
|
|
=== Documentation
|
|
|
|
* Clippy Lints - https://rust-lang.github.io/rust-clippy/master/index.html#nonsensical_open_options
|