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

Fixed false negatives around edges and added second phase of reporting #486

Merged
merged 3 commits into from Nov 22, 2022

Conversation

RunDevelopment
Copy link
Collaborator

Fixes #479.

This PR includes 2 changes:

  1. I improved the handling of edges. Previously, all verify function would just immediately return without reporting anything if the next character included the start/end (edge) of the input string. I likely did this because the logic around string edges is a bit more complex.
  2. In order to fully report all useless assertion in the examples here, I had to add assertion reordering. E.g. to detect that the \b in /\b^a/ is useless, \b has to know that there is a ^ after it. The solution here is to (conceptually) reorder the assertions to /^\ba/ which allows \b to "see" ^.
    However, assertion reordering also causes overreporting. E.g. Since both $s in /$$/ can see each other, both will be reported even though only one is actually useless. To fix this, reporting is done in 2 phases. In the first phase, we do everything just like we did before. In the second phase, we reorder while being careful not to reorder already reported assertions.

lib/rules/no-useless-assertions.ts Outdated Show resolved Hide resolved
Copy link
Owner

@ota-meshi ota-meshi left a comment

Choose a reason for hiding this comment

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

Awesome! Thank you!

@ota-meshi ota-meshi merged commit 99367b0 into master Nov 22, 2022
@ota-meshi ota-meshi deleted the issue479 branch November 22, 2022 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

no-useless-assertions false negative around $
2 participants