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 rule WPS111 from wemake-python-styleguide #5632

Closed
wants to merge 2 commits into from

Conversation

bo5o
Copy link

@bo5o bo5o commented Jul 9, 2023

Summary

Implements WPS111 from wemake-python-styleguide, as part of #3845.

I started by merging latest upstream changes into an existing PR to revive this implementation. However, after looking at it more closely, I realized that the existing implementation only covers the most basic case of WPS111.
After studying the original code a bit more I updated my implementation to match the original more closely and emit the same behavior. The result is a quite substantial difference compared to the existing PR for this rule, so I decided to make it a separate one, supposed to supersede the previous.

Test Plan

I added a fixture for snapshot testing and copied unit tests from the original logic.

@bo5o bo5o force-pushed the wps111-too_short_name-new branch 20 times, most recently from 3e366fb to bdf992d Compare July 16, 2023 14:43
@bo5o bo5o force-pushed the wps111-too_short_name-new branch from bdf992d to 0212858 Compare July 16, 2023 18:40
@github-actions
Copy link
Contributor

github-actions bot commented Jul 16, 2023

PR Check Results

Ecosystem

✅ ecosystem check detected no linter changes.

✅ ecosystem check detected no format changes.

@bo5o bo5o force-pushed the wps111-too_short_name-new branch from 0212858 to f8e0833 Compare July 16, 2023 23:56
use once_cell::sync::Lazy;
use regex::Regex;

const ALIAS_NAMES_WHITELIST: [&str; 7] = ["np", "pd", "df", "plt", "sns", "tf", "cv"];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ALIAS_NAMES_WHITELIST: [&str; 7] = ["np", "pd", "df", "plt", "sns", "tf", "cv"];
const ALIAS_NAMES_ALLOWLIST: [&str; 7] = ["np", "pd", "df", "plt", "sns", "tf", "cv"];

Or what I like to do (if you don't need to enumerate the values) is to write a match statement instead:

if matches!(x, "np" | "pd" | "df" | ...)

The compiler will generate efficient code for this

Copy link
Author

Choose a reason for hiding this comment

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

I wasn't sure what to do here, because it is a potential conflict with another linter. flake8-import-conventions defines convential import aliases here. Actually I would like to use these as the single source of truth for allowed aliases. This list is also configurable via settings (see here) in which case I would also like to add these to the allowlist.

How should this be done?

Copy link
Member

Choose a reason for hiding this comment

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

@bo5o bo5o force-pushed the wps111-too_short_name-new branch 5 times, most recently from 38e6452 to ba72adb Compare July 24, 2023 21:01
@bo5o bo5o force-pushed the wps111-too_short_name-new branch 4 times, most recently from 14782ad to 0387893 Compare December 13, 2023 10:22
@bo5o bo5o force-pushed the wps111-too_short_name-new branch 6 times, most recently from f930ab7 to f408885 Compare January 18, 2024 22:01
@bo5o bo5o force-pushed the wps111-too_short_name-new branch 3 times, most recently from 152ffd3 to de3e841 Compare January 28, 2024 17:37
@bo5o bo5o force-pushed the wps111-too_short_name-new branch 2 times, most recently from a092918 to 1b291c6 Compare February 5, 2024 00:02
@bo5o bo5o force-pushed the wps111-too_short_name-new branch 2 times, most recently from cba38d9 to a6f80d5 Compare February 12, 2024 10:33
@zanieb zanieb added the incompatibility Incompatibility between different Ruff tools or rules (formatter, isort, linter) label Mar 12, 2024
@bo5o bo5o force-pushed the wps111-too_short_name-new branch from cc90294 to 711c72e Compare March 22, 2024 22:08
@bo5o bo5o force-pushed the wps111-too_short_name-new branch from 711c72e to 2d03f74 Compare March 24, 2024 10:01
@MichaReiser
Copy link
Member

Thank you, @bo5o, for working on this rule and keeping the PR up to date.

We think this is a valuable rule for many but don't feel comfortable merging it today because it is very opinionated, and everyone using --select ALL would opt into the new rule. That's why we only want to add this rule once #1774 is complete: It gives users a better way to opt into the rules they want.

I'm closing this PR for now because I don't want you to spend more time updating the PR, but I hope we can resurrect this PR once #1774 is completed. I'm sorry for the late reply. We should have made this decision sooner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incompatibility Incompatibility between different Ruff tools or rules (formatter, isort, linter) rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants