-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [unbound-method] support bound builtins #1526
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(eslint-plugin): [unbound-method] support bound builtins #1526
Conversation
This comment has been minimized.
This comment has been minimized.
It took me a minute to figure this out. The import declaration doesn't count as a declaration, because we're inspecting the symbol Soooooooooooooo with that in mind; what's the objective we want here; we want to be able to whitelist certain methods as being always "safe", right? What's our whitelist? Something like this: const validMemberExpressions = [
'JSON.parse',
'JSON.stringify',
Object.keys(console)
.filter(name => !name.startsWith('_'))
.map(name => `console.${name}`),
] First up, let's make an assumption to make things simpler for us - we're not going to support aliases for now (i.e. This then becomes a pretty simple problem to solve:
(1) you can do either via explicitly checking the structure of the AST, or via comparing the source code with whitespace removed. (2) will be something like:
Note - you should also setup a test case which uses valid imports. In // used by unbound-method test case to test imports
export const console = { log() {} }; Then in your tests, make sure you're importing that, not the unknown file
|
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.
rc for last comment
@bradzacher guess who went a little overboard on the whitelist... :D Also, it seems that If that's true, that might be of use elsewhere? |
Hey dude, that's actually awesome. Will save a lot of noise for people! Note (it won't matter for long, as we'll drop node 8 in v3...)
That's interesting. TBH IDK what the difference between |
Yeah, I think the only one I'm missing right now is
I'll just comment it out for now, and we can enable it when we release v3.
Yeah, it was actually confusing the heck out of me at first b/c I thought it was the
Oh, no it's b/c of |
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 few final comments.
Otherwise LGTM.
Thanks for doing this.
Thanks for doing this! |
#1526 Added a whitelist of member expressions which are bound by default . But of the ~100 methods in the list, ~15 aren't actually bound (for whatever reason). This just adds a blacklist alongside the whitelist so we don't false-negative.
No problem! Apologies for not getting back around to it sooner, but cheers for picking it up for the release! :D |
This was suspiciously too easy 🕵
Sadly @bradzacher imports are seemingly not considered decorations - let me know how you'd like to handle that case.
I found that I could compare against
valueDeclaration
, rather than usingsymbol.getDeclarations()
, but it's quite possible that I've not tested it against a complex enough setup for that to fail, so happy to use the original suggested method for tackling this :)closes #1085