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

Major clippy overhaul. #2298

Merged
merged 11 commits into from
May 29, 2021
Merged

Major clippy overhaul. #2298

merged 11 commits into from
May 29, 2021

Conversation

jhscheer
Copy link
Contributor

@jhscheer jhscheer commented May 28, 2021

There were severe problems with our clippy linting:

  • clippy suggested newer features than our MSRV
  • clippy did not check all targets, e.g. "tests" were completely unchecked

This PR:

  • adds clippy.toml to be able to set MSRV for clippy. However, this only works if clippy is invoked like this: cargo +nightly clippy.
  • adds --target=${{ matrix.job.target }} to github actions (I hope this is enough, locally I run cargo +nightly clippy --all-targets --all-features
  • fixes all clippy warnings that were exposed with the previous steps

@jhscheer jhscheer marked this pull request as draft May 29, 2021 11:27
jhscheer added 2 commits May 29, 2021 14:21
* add "clippy.toml" in order to set MSRV for clippy linting
    this works only if clippy is invoked with "+nightly"
* add "--target" to clippy in order to also lint tests
@jhscheer jhscheer changed the title fix clippy warnings Major clippy overhaul. May 29, 2021
jhscheer and others added 8 commits May 29, 2021 15:11
Add a test for when the reference file is not found and both `-r` and
`-s` options are given on the command-line.
Remove "read" permissions from the `OpenOptions` when opening a new file
just to truncate it. We will never read from the file, only write to
it. (Specifically, we will only call `File::set_len()`.)
Add a helper function to contain the code for parsing the size and the
modifier symbol, if any. This commit also changes the `TruncateMode`
enum so that the parameter for each "mode" is stored along with the
enumeration value. This is because the parameter has a different meaning
in each mode.
Create a method that computes the final target size in bytes for the
file to truncate, given the reference file size and the parameter to the
`TruncateMode`.
Reorganize the code in `truncate.rs` into three distinct functions
representing the three modes of operation of the `truncate` program. The
three modes are

- `truncate -r RFILE FILE`, which sets the length of `FILE` to match the
  length of `RFILE`,
- `truncate -r RFILE -s NUM FILE`, which sets the length of `FILE`
  relative to the given `RFILE`,
- `truncate -s NUM FILE`, which sets the length of `FILE` either
  absolutely or relative to its curent length.

This organization of the code makes it more concise and easier to
follow.
@jhscheer jhscheer marked this pull request as ready for review May 29, 2021 13:36
@@ -1089,7 +1089,7 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
}

#[cfg(not(windows))]
#[allow(clippy::unnecessary_wraps)] // needed for windows version
#[allow(clippy::unnecessary_unwrap)] // needed for windows version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this allow needed? Also, it seems like we're not handling errors in symlink_file for linux/macos, but always returning Ok(()). Maybe it should be the same as for windows below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't checked yet (it's so cumbersome to boot up a windows VM).
I also noticed errors are not handled in symlink_file, however there's an 'unwrap' which should be enough, i.e. print the error message and then panic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. Which unwrap are you referring to? Any error from the call to std::os::unix::fs::symlink(source, dest).context(context) is not handled, or am I missing something?

Also, you changed this from unnecessary_wraps to unnecessary_unwrap, but... there's no unwrap in here. That's what confused me. Anyways,I'm booting up my windows VM to check :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this allow doesn't make clippy complain on windows (checked in a VM).
However, there are two other warnings:


warning: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
   --> src\uu\du\src/du.rs:150:27
    |
150 | fn get_size_on_disk(path: &PathBuf) -> u64 {
    |                           ^^^^^^^^ help: change this to: `&Path`
    |
    = note: `#[warn(clippy::ptr_arg)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
   --> src\uu\du\src/du.rs:182:24
    |
182 | fn get_file_info(path: &PathBuf) -> Option<FileInfo> {
    |                        ^^^^^^^^ help: change this to: `&Path`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: 2 warnings emitted

With stable there is another one:

warning: name `DWORD` contains a capitalized acronym
   --> src\uu\rm\src/rm.rs:406:14
    |
406 |     pub type DWORD = c_ulong;
    |              ^^^^^ help: consider making the acronym lowercase, except the initial letter: `Dword`
    |
    = note: `#[warn(clippy::upper_case_acronyms)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms

warning: 1 warning emitted

Copy link
Contributor Author

@jhscheer jhscheer May 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. Which unwrap are you referring to? Any error from the call to std::os::unix::fs::symlink(source, dest).context(context) is not handled, or am I missing something?

Oh, I was referring to L539:

pub fn symlink_file(&self, src: &str, dst: &str) {
log_info(
"symlink",
&format!("{},{}", self.plus_as_string(src), self.plus_as_string(dst)),
);
symlink_file(&self.plus(src), &self.plus(dst)).unwrap();
}

Also, you changed this from unnecessary_wraps to unnecessary_unwrap, but... there's no unwrap in here. That's what confused me.

Clippy complained that there's no unnecessary_wraps, I thought it's a typo and followed clippy's suggestion to use unnecessary_unwrap. However, now that you mention it, I checked and unnecessary_wraps does indeed exit. Strange.

@miDeb
Copy link
Contributor

miDeb commented May 29, 2021 via email

@sylvestre sylvestre merged commit 6e1a68c into uutils:master May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants