-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[eradicate
] ignore # language=
in commented-out-code rule (ERA001)
#14069
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nested quantifier doesn't look so nice:
[a-zA-Z](?: ?[-_.a-zA-Z0-9]+)+
. The optional space at the start of the group leads to multiple ways of matching the same text.I know Rust's regex engine guarantees linear time, but this is nevertheless a bad pattern. Prefer
[a-zA-Z][-_.a-zA-Z0-9]*(?: [-_.a-zA-Z0-9]+)*
instead.Technically, language IDs can be anything, so it's perhaps better to drop the leading character requirement:
[-_.a-zA-Z0-9]+(?: [-_.a-zA-Z0-9]+)*
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just use
language=
? All language identifiers will start with that, and false positives seem somewhat rare / not a huge deal here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@InSyncWithFoo maybe I was extra cautious about false positives.
Good catch! Maybe we can just require a non-space character after the equals sign. This should take care of most false positives anyway, as it's uncommon for Python users to omit spaces around assignment operators.
The only thing that worries me is about detecting a commented-out named parameter on a multi-line method invocation or declaration. But maybe I'm just being overzealous.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick search shows that matching on
language=
alone would lead to many false negatives.Language IDs are also displayed to the user as part of the UI, so I doubt they would contain non-ASCII characters. I would say limiting to
[-_.a-zA-Z0-9]
and spaces is the most balanced heuristic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget keyword arguments, which are recommended to be written with no spaces around the equal sign:
I think both this and the false negative you mention are well within the acceptable error margin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So @InSyncWithFoo , will you write the PR with the new regexp and test cases, or should I?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out language IDs in comments must be normalized.
This is JSON Lines (one value on each line, comments allowed):
This is pure JSON (one single top-level value, comments disallowed):
jsonlines
must be used even though autocompletion popups usejson lines
:Notably, this rule applies to some languages but not others (though Ruff doesn't need to care about this):