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 new rule to check for useless quote escapes #8630

Merged
merged 9 commits into from Nov 13, 2023

Conversation

ThiefMaster
Copy link
Contributor

@ThiefMaster ThiefMaster commented Nov 12, 2023

When using the autofixer for Q000 it does not remove the backslashes from quotes that no longer need escaping.
This new rule checks for such backslashes (regardless whether they come from the autofixer or not) and can remove them.

I used Q100 to avoid ocnflicts with Q00x rules flake8-quotes might add (even though it's not very actively maintained)

fixes #8617

@ThiefMaster ThiefMaster force-pushed the quotes-remove-backslash branch 3 times, most recently from 637452a to 7f0bf50 Compare November 12, 2023 17:03
Copy link
Contributor

github-actions bot commented Nov 12, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -0 violations, +0 -0 fixes in 41 projects)

sphinx-doc/sphinx (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --preview

+ tests/test_ext_inheritance_diagram.py:219:16: Q004 [*] Unnecessary escape on inner quote character

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
Q004 1 1 0 0 0

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh
Copy link
Member

Haven't reviewed the code yet, but the ecosystem check seems to be flagging some cases like "\\'", in which the backslash escapes are necessary (I think?) to add a backslash literal.

@ThiefMaster
Copy link
Contributor Author

Yeah, just noticed that I'm not checking for escaped backslashes - already on it

@charliermarsh
Copy link
Member

Awesome, thanks @ThiefMaster!

@ThiefMaster ThiefMaster force-pushed the quotes-remove-backslash branch 2 times, most recently from bc64a73 to ac6b617 Compare November 12, 2023 19:09
@ThiefMaster
Copy link
Contributor Author

Ecosystems looks much better now. The one new violation is actually correct since those quotes there should not be escaped.

@ThiefMaster
Copy link
Contributor Author

The mkdocs CI failure seems unrelated (it didn't fail until I rebased to the latest master).

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Nov 13, 2023
@charliermarsh charliermarsh enabled auto-merge (squash) November 13, 2023 21:44
@charliermarsh charliermarsh merged commit 1606067 into astral-sh:main Nov 13, 2023
16 checks passed
@ThiefMaster ThiefMaster deleted the quotes-remove-backslash branch November 13, 2023 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Q000 fixer does not remove obsolete backslash-escape inside string after changing quotes
2 participants