Skip to content

fix clippy warnings in pyrefly_config#3194

Open
jorenham wants to merge 2 commits intofacebook:mainfrom
jorenham:pyrefly_config/fix-clippy-warnings
Open

fix clippy warnings in pyrefly_config#3194
jorenham wants to merge 2 commits intofacebook:mainfrom
jorenham:pyrefly_config/fix-clippy-warnings

Conversation

@jorenham
Copy link
Copy Markdown
Contributor

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:

$ 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.

Test Plan

tests still pass

Copy link
Copy Markdown
Contributor

@NathanTempest NathanTempest left a comment

Choose a reason for hiding this comment

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

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.

Comment thread crates/pyrefly_config/src/migration/mypy/regex_converter.rs Outdated

pub(crate) mod active_environment;
pub(crate) mod conda;
#[allow(clippy::module_inception)]
Copy link
Copy Markdown
Contributor

@NathanTempest NathanTempest Apr 22, 2026

Choose a reason for hiding this comment

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

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 = "")]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 🤷

Comment thread crates/pyrefly_config/src/module_wildcard.rs Outdated
@github-actions github-actions Bot added size/xs and removed size/xs labels Apr 22, 2026
Copy link
Copy Markdown
Contributor

@NathanTempest NathanTempest left a comment

Choose a reason for hiding this comment

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

Appreciate the prompt response to the fixes, the changes LGTM

@jorenham
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing :)

@jorenham
Copy link
Copy Markdown
Contributor Author

jorenham commented Apr 23, 2026

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.

@NathanTempest
Copy link
Copy Markdown
Contributor

@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 ?

@jorenham jorenham force-pushed the pyrefly_config/fix-clippy-warnings branch from a46663f to 26f9e14 Compare April 23, 2026 16:02
@github-actions github-actions Bot added size/xs and removed size/xs labels Apr 23, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 23, 2026

@NathanTempest has imported this pull request. If you are a Meta employee, you can view this in D102193286.

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

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

Review automatically exported from Phabricator review in Meta.

meta-codesync Bot pushed a commit that referenced this pull request Apr 25, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants