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
feat: no-misleading-character-class
granular errors
#17515
feat: no-misleading-character-class
granular errors
#17515
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
Co-authored-by: Francesco Trotta <github@fasttime.org>
Thanks for this PR @JoshuaKGoldberg! Reconsidering the original intent of the rule I'm not sure if we should try to report the exact position of every invalid/misleading character in all possible situations. The problem is that sometimes there is just no one-to-one correspondence between a positions in the source code and a resulting character in the regex pattern. Even when a correspondence exists, it is not always trivial to calculate just looking at the AST. The following are examples where the reported start or end positions are off somehow in the new implementation (the patterns should be all equivalent IINM, but it doesn't even matter here): To improve this situation I imagine that we could:
Maybe you have an idea that works better. I would also like to hear what @mdjermanovic thinks. |
Also noticed that sometimes the rule suggests to add the |
Good catch! Can you open an issue for this bug? |
I think that reporting exact positions should be limited to cases where it's a simple string/template literal and the raw text is 1-1 with the pattern. The logic could be the same as in #16544 , where we decided to provide suggestions (which need exact positions to fix the code) only in those cases. Here's related discussion on that PR: #16544 (comment). |
Done: #17537 |
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
Ah, I'd been waiting to see conversation resolve and missed that it had - will pick this back up. Thanks! |
@JoshuaKGoldberg just a heads up that there's a merge conflict. |
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
There are merge conflicts in the test file due to 70a686b. |
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
Sorry, we are deep in v9 planning and focusing on things that are blockers for v9. We will get back around to this! In the meantime, can you please rebase to get the latest updates? |
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.
LGTM. Thanks for all your work on this.
Waiting for @mdjermanovic to verify his review comments.
if (kind === "zwj" && locs.length > 1) { | ||
context.report({ | ||
loc: { | ||
start: locs[0].start, | ||
end: locs[1].end | ||
}, | ||
messageId: kind, | ||
suggest | ||
}); |
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 wouldn't show all if there are more of these in the pattern, but we can fix that in a follow-up.
I'll just close-reopen for a moment to see if there's anything that should be updated for CI to pass. |
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.
LGTM, thanks!
* main: chore: Split Docs CI from core CI (eslint#17897) fix: Ensure config keys are printed for config errors (eslint#17980) chore: delete relative-module-resolver.js (eslint#17981) docs: migration guide entry for `no-inner-declarations` (eslint#17977) docs: Update README feat: maintain latest ecma version in ESLint (eslint#17958) feat!: no-inner-declaration new default behaviour and option (eslint#17885) feat: add `no-useless-assignment` rule (eslint#17625) fix: `no-misleading-character-class` edge cases with granular errors (eslint#17970) feat: `no-misleading-character-class` granular errors (eslint#17515) docs: fix number of code-path events on custom rules page (eslint#17969) docs: reorder entries in v9 migration guide (eslint#17967) fix!: handle `--output-file` for empty output when saving to disk (eslint#17957)
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What rule do you want to change?
no-misleading-character-class
What change do you want to make (place an "X" next to just one item)?
[x] Generate more warnings
[ ] Generate fewer warnings
[ ] Implement autofix
[ ] Implement suggestions
How will the change be implemented (place an "X" next to just one item)?
[ ] A new option
[x] A new default behavior
[ ] Other
Please provide some example code that this change will affect:
What does the rule currently do for this code?
Currently it gives one complaint for the two matched surrogate pairs.
What will the rule do after it's changed?
Give one complaint per surrogate pair.
Latest playground of cases
Fixes #16682.