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

treat foo.bind(something).bar() similar to foo.bar() #115

Open
mozfreddyb opened this issue Mar 16, 2020 · 1 comment
Open

treat foo.bind(something).bar() similar to foo.bar() #115

mozfreddyb opened this issue Mar 16, 2020 · 1 comment

Comments

@mozfreddyb
Copy link
Collaborator

We can't do full type detection and it's (hard?) for us to detect stuff like

let hiding = eval
hiding(foo);

in fact, we don't think we ought to do so across the board as we're optimizing for well-intended code that is able to pass code review preferably.

@mozfreddyb
Copy link
Collaborator Author

Strategy:

  • add a test that considers these cases as valid/invalid
  • valid:
    • foo.bind(bar).baz()
    • document.body.insertAdjacentHTML.bind(document.body)("afterend", foo)
  • invalid: document.body.insertAdjacentHTML.bind(document.body)("afterend", foo)

Implementation plan:
When inspecting CallExpressions in https://github.com/mozilla/eslint-plugin-no-unsanitized/blob/master/lib/rules/method.js#L94, we should not just say "it's fine" and break. Instead move the case statement above to those that need closer inspection. If the function being called is bind, we should construct a new "fake" CallExpression node object where the function being bound is called instead and call ruleHelper.checkMethod() on it. Similar, to how we create a "fake" node in the SequenceExpression code (above).

To see how your node objects and the syntax tree looks like, take a glance at https://esprima.org/demo/parse.html?code=document.body.insertAdjacentHTML.bind(document.body)(%22afterend%22%2C%20foo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant