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

Fix false negatives in prefer-result-array-groups rule #356

Merged
merged 2 commits into from
Oct 7, 2021

Conversation

ota-meshi
Copy link
Owner

fixes #355

This PR makes fix some false negatives and improves autofix.

I fixed the false negatives of the source code written in TypeScript.

const match = /(?<foo>foo)/u.exec(str)!
match[1]; // <-

const match2 = /(?<bar>bar)/u.exec(str) as RegExpExecArray
match2[1] // <-

I modified it to handle the TSNonNullExpression and TSAsExpression nodes contained in these codes.

I also found that there were false negatives when using conditional statements, so I fixed these as well.

const match = /(?<foo>foo)/u.exec(str)
if (match) {
    match[1] // <-
}

const match2 = /(?<bar>bar)/u.exec(str)
match2
    ? match2[1] // <-
    : null;

const match3 = /(?<baz>baz)/u.exec(str)
match3 && match3[1] // <-

const match4 = /(?<qux>qux)/u.exec(str)
if (!match4) {
} else {
    match4[1] // <-
}

Finally, fix the problem that the code written in TypeScript cannot be autofixed.

const match = /(?<foo>foo)/u.exec(str)
match?.[1]

This was a problem because the match variable was of type (RegExpExecArray | null), which stopped autofix.
I changed it to autofix even for type (RegExpExecArray | null).

@ota-meshi ota-meshi added the bug Something isn't working label Oct 7, 2021
Copy link
Collaborator

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

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

Awesome work! LGTM;

Feel free to merge this at any time. I leave it at your discretion whether this is to be included in the patch for #354.

@ota-meshi
Copy link
Owner Author

ESLint's Semantic Versioning Policy does not seem to include more reporting fixes in patch releases.
So, I will not include this change in the patch according to it policy.
https://github.com/eslint/eslint#semantic-versioning-policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negatives for ts code in prefer-result-array-groups
2 participants