-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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(eslint-plugin): [prefer-nullish-coalescing] ensure ternary fix does not remove parens #9380
Conversation
…es not remove parens
Thanks for the PR, @jakebailey! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 6af7a2c. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
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.
The implementation looks great to me! Requesting changes on testing and an import path. Thanks! ✨
isParenthesized, | ||
nullThrows, | ||
NullThrowsReasons, | ||
} from '.'; |
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.
We generally try not to import from '.'
, as that generates a cycle:
} from '.'; | |
} from '../util'; |
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 can do that, though that's still a cycle; those are the same imports, they both point to index.ts
.
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.
Oh, maybe we need to flatten these out...
@@ -333,6 +333,26 @@ x ?? 'foo'; | |||
}, | |||
], | |||
}, | |||
{ | |||
code: code.replace(/y/g, '(z = y)'), |
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.
[Testing] The changed logic includes beforeCount
and afterCount
, but there's only one here. Could you add some tests?
((z = y))
( /* */ ( z = y ) /* */ )
- Maybe, a multiline comment or two?
- ...whatever you think is also a good idea to test
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.
Yeah, I'm afraid it doesn't handle any of those cases. the getTextWithParentheses
function I moved isn't fancy enough to handle that.
Is there a helper that already exists to do this that I'm not aware of? Reprinting a node like this sure seems like a common case.
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.
Maybe getWrappingFixer
? I had looked at that but couldn't reverse engineer how to use it in this application.
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.
That would be the one, yeah. Does its use in strict-boolean-expressions
help?
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.
Tried it out, and it adds parens in places it shouldn't, and doesn't preserve multiple parens. So, I don't think I have a good idea...
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.
Hmm. Well, I guess you're on your own then. Blurgh.
If there's anything that's an existing bug and would be a lot more work to tackle, I think it's fine as a followup issue. I'll just mark this as ✅ for now.
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.
🚀
PR Checklist
Overview
Parens aren't in the AST, and this fixer's text manipulation did not handle that.
I took the time to move a helper out of another lint rule into a common place. I thought I would modify other lint rules to use this code, but not every lint rule has to do this simple manipulation it seems.