Skip to content

[ruff] Implement unnecessary-nested-literal (RUF041)#14323

Merged
MichaReiser merged 5 commits intoastral-sh:mainfrom
sbrugman:unnecessary-nested-literal
Nov 27, 2024
Merged

[ruff] Implement unnecessary-nested-literal (RUF041)#14323
MichaReiser merged 5 commits intoastral-sh:mainfrom
sbrugman:unnecessary-nested-literal

Conversation

@sbrugman
Copy link
Contributor

@sbrugman sbrugman commented Nov 13, 2024

Summary

Implementing unnecessary-nested-literal.

This rule could help simplify other rules' fixes by handling the flattening of Literals here.

See also https://github.com/astral-sh/ruff/pull/14270/files#r1837810594 (unions in a follow-up PR)

Test Plan

cargo test

The ecosystem results are correct.

Some of the nesting emits multiple violations.
I've got a fix for this, but that depends on #14280.
We can go on with merging this PR after review regardless (the violations are not wrong).

@sbrugman sbrugman force-pushed the unnecessary-nested-literal branch 3 times, most recently from ae4a677 to ebbd9f1 Compare November 13, 2024 16:38
@github-actions
Copy link
Contributor

github-actions bot commented Nov 13, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+3 -0 violations, +0 -0 fixes in 2 projects; 53 projects unchanged)

DisnakeDev/disnake (+2 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview

+ tests/test_utils.py:730:18: RUF041 [*] Unnecessary nested `Literal`
+ tests/test_utils.py:758:10: RUF041 [*] Unnecessary nested `Literal`

python/typeshed (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W

+ stdlib/xml/dom/pulldom.pyi:23:131: E501 Line too long (153 > 130)

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
RUF041 2 2 0 0 0
E501 1 1 0 0 0

@MichaReiser MichaReiser added rule Implementing or modifying a lint rule preview Related to preview mode features labels Nov 14, 2024
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

@AlexWaygood would you mind doing a quick glance at the rule definition? I already reviewed the code

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

Similar to #14319 (review), I feel like I'm not sure how much this antipattern really comes up in practice. But, I can see the value if this is a pattern that could be introduced by the fix for other rules we implement!

@MichaReiser
Copy link
Member

Is there any open feedback that needs addressing? I'm otherwise happy to merge this rule.

@AlexWaygood
Copy link
Member

My feedback has been addressed, but it looks like there's quite a few merge conflicts here. The conversations in #14323 (comment) and #14323 (comment) are also not marked as "resolved", and I think you're better placed to judge whether they should be or not ;)

@MichaReiser MichaReiser force-pushed the unnecessary-nested-literal branch from f5c223e to b6b3837 Compare November 27, 2024 09:18
@MichaReiser MichaReiser changed the title [ruff] Implement unnecessary-nested-literal (RUF039) [ruff] Implement unnecessary-nested-literal (RUF041) Nov 27, 2024
@MichaReiser MichaReiser enabled auto-merge (squash) November 27, 2024 09:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants