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 eslint no-prototype-builtins issues #1127

Merged
merged 2 commits into from
Nov 20, 2019
Merged

Conversation

simison
Copy link
Contributor

@simison simison commented Nov 15, 2019

This is a smaller iteration step from #1126 where I'm converting eslint config to extend eslint:recommended.

That ruleset includes no-prototype-builtins rule and there were a few warnings so I set to fix those. Instead of using elaborate Object.prototype.hasOwnProperty.call(foo, "bar") I'm just using Lodash's has here instead.

I generally like using vanilla JS over Lodash especially in frontend code but this is all server-side and just feels more readable in these cases. We're also already using Lodash in all these files.

Proposed Changes

  • Use _.has() over hasOwnProperty checks

Testing Instructions

  • Does the app start?
  • Do the tests pass?

@@ -41,14 +41,14 @@ function validateCreate(req) {

// Values of interactions must be boolean
['met', 'hostedMe', 'hostedThem'].forEach(function (interaction) {
if (req.body.interactions && req.body.interactions.hasOwnProperty(interaction) && typeof req.body.interactions[interaction] !== 'boolean') {
if (_.has(req, ['body', 'interactions', interaction]) && typeof req.body.interactions[interaction] !== 'boolean') {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good win especially here since we're checking for a path two levels deep.

@simison simison mentioned this pull request Nov 15, 2019
Copy link
Contributor

@mrkvon mrkvon left a comment

Choose a reason for hiding this comment

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

I've learned some new stuff from this rule. 👍 Replacing the vanilla JS with lodash makes sense here.

Additionally:

  • tests pass
  • linter without errors
  • application starts

@simison simison merged commit 51d4674 into master Nov 20, 2019
@simison simison deleted the update/no-prototype-builtins branch November 20, 2019 08:15
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.

2 participants