fix clippy warnings in pyrefly_config#3194
Conversation
There was a problem hiding this comment.
Thanks for cleaning up the clippy warnings, @jorenham! Most of these look good. A couple of notes:
to_strings in regex_converter.rs — consider renaming to into_strings instead
The current fix changes the signature from fn to_strings(self) to fn to_strings(&self), which requires adding .clone() on the Part variant and switching into_iter() to iter() throughout. This introduces unnecessary allocations, the original code intentionally consumed self to move strings without copying.
The Rust convention is:
to_* → borrows &self (may allocate a new value)
into_* → consumes self (zero-copy conversion)
The rest looks great — the collapsible if chains in error.rs are cleaner, and the to_config(&self) change in pyright.rs is a nice improvement since it eliminates the .clone() at the call site in error_codes.rs.
|
|
||
| pub(crate) mod active_environment; | ||
| pub(crate) mod conda; | ||
| #[allow(clippy::module_inception)] |
There was a problem hiding this comment.
I think this might violate the project convention. We usually do not suppress lints with #[allow()]. If one is necessary, always use #[expect()] instead and provide a justified reason: #[expect(lint_name, reason = "")]
There was a problem hiding this comment.
Ah good to know. Maybe it's an idea to turn on the clippy allow_attributes lint then? https://rust-lang.github.io/rust-clippy/master/index.html?search=allow_attributes
There was a problem hiding this comment.
Hmm, when I enable that in pyrefly_config, three more warnings pop up:
warning: #[allow] attribute found
--> crates/pyrefly_config/src/migration/mypy/pyproject.rs:31:3
|
31 | #[allow(dead_code)]
| ^^^^^ help: replace it with: `expect`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes
note: the lint level is defined here
--> crates/pyrefly_config/src/lib.rs:8:9
|
8 | #![warn(clippy::allow_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
warning: #[allow] attribute found
--> crates/pyrefly_config/src/util.rs:16:3
|
16 | #[allow(clippy::trivially_copy_pass_by_ref)]
| ^^^^^ help: replace it with: `expect`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes
warning: #[allow] attribute found
--> crates/pyrefly_config/src/util.rs:22:3
|
22 | #[allow(clippy::trivially_copy_pass_by_ref)]
| ^^^^^ help: replace it with: `expect`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes
warning: `pyrefly_config` (lib) generated 3 warnings (run `cargo clippy --fix --lib -p pyrefly_config` to apply 3 suggestions)
It's probably out-of-scope here, but I figured you might want to know 🤷
NathanTempest
left a comment
There was a problem hiding this comment.
Appreciate the prompt response to the fixes, the changes LGTM
|
Thanks for reviewing :) |
|
I see that the "Facebook Internal - Builds & Tests" check failed, but I can't see any of the errors, so I'm not sure what to do with it. |
|
@jorenham The import failed because the branch is out of date with main. Could you rebase on the latest main, so I can try to import again ? |
Co-authored-by: NathanTempest <[email protected]> Co-authored-by: Copilot <[email protected]>
a46663f to
26f9e14
Compare
|
@NathanTempest has imported this pull request. If you are a Meta employee, you can view this in D102193286. |
kinto0
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary: Suppressing 6 different Clippy warnings as seen in this github PR - #3194 Before - ``` $ python test.py --no-test --no-conformance --no-jsonschema Running formatting... Finished in 1.28 seconds. Running linting... warning: module has the same name as its containing module --> crates/pyrefly_config/src/environment/mod.rs:10:1 | 10 | pub mod environment; | ^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception = note: `#[warn(clippy::module_inception)]` on by default warning: this `if` statement can be collapsed --> crates/pyrefly_config/src/error.rs:41:9 | 41 | / if let Some(parent) = kind.parent_kind() { 42 | | if let Some(&severity) = self.0.get(&parent) { 43 | | return severity; 44 | | } 45 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if = note: `#[warn(clippy::collapsible_if)]` on by default help: collapse nested if block | 41 ~ if let Some(parent) = kind.parent_kind() 42 ~ && let Some(&severity) = self.0.get(&parent) { 43 | return severity; 44 ~ } | warning: this `if` statement can be collapsed --> crates/pyrefly_config/src/error.rs:46:9 | 46 | / if let Some(alias) = kind.deprecated_alias() { 47 | | if let Some(&severity) = self.0.get(&alias) { 48 | | return severity; 49 | | } 50 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if help: collapse nested if block | 46 ~ if let Some(alias) = kind.deprecated_alias() 47 ~ && let Some(&severity) = self.0.get(&alias) { 48 | return severity; 49 ~ } | warning: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference --> crates/pyrefly_config/src/migration/mypy/regex_converter.rs:26:19 | 26 | fn to_strings(self) -> Vec<String> { | ^^^^ | = help: consider choosing a less ambiguous name = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention = note: `#[warn(clippy::wrong_self_convention)]` on by default warning: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference --> crates/pyrefly_config/src/migration/pyright.rs:307:22 | 307 | pub fn to_config(self) -> Option<ErrorDisplayConfig> { | ^^^^ | = help: consider choosing a less ambiguous name = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention warning: variant name ends with the enum's name --> crates/pyrefly_config/src/module_wildcard.rs:35:5 | 35 | NoMatch, | ^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names = note: `#[warn(clippy::enum_variant_names)]` on by default warning: `pyrefly_config` (lib) generated 6 warnings (run `cargo clippy --fix --lib -p pyrefly_config` to apply 2 suggestions) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s Finished in 0.16 seconds. ``` After - ``` $ python test.py --no-test --no-conformance --no-jsonschema Running formatting... Finished in 1.31 seconds. Running linting... Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.12s Finished in 0.17 seconds. ``` Reviewed By: kinto0 Differential Revision: D102193286 fbshipit-source-id: 6a60f0e553df19c644d6a70f38852b2ba25a551f
Summary
I noticed there were some clippy warnings, which I thought was a bit annoying (maybe that's just me though), so I fixed them.
Before:
After:
Test Plan
tests still pass