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

feat: add prefer-object-has-own rule #15346

Merged
merged 28 commits into from Dec 11, 2021
Merged

Conversation

snitin315
Copy link
Contributor

@snitin315 snitin315 commented Nov 23, 2021

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[ ] Documentation update
[ ] Bug fix (template)
[x] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add auto fixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Fixes #14939

Resolve #15206

Add a new rule prefer-object-has-own. This rule requires using Object.hasOwn instead of Object.prototype.hasOwnProperty.

Is there anything you'd like reviewers to focus on?

No

Co-authored-by: Gautam Arora <gautamarora6248@gmail.com>
@eslint-github-bot eslint-github-bot bot added the triage An ESLint team member will look at this issue soon label Nov 23, 2021
@snitin315 snitin315 added accepted There is consensus among the team that this change meets the criteria for inclusion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Nov 23, 2021
@snitin315 snitin315 changed the title feat: add prefer-object-has-own rule [WIP]feat: add prefer-object-has-own rule Nov 23, 2021
@eslint-github-bot
Copy link

Hi @snitin315!, thanks for the Pull Request

The pull request title isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.

  • The commit message tag wasn't recognized. Did you mean "docs", "fix", or "feat"?
  • There should be a space following the initial tag and colon, for example 'feat: Message'.
  • The first letter of the tag should be in lowercase

Read more about contributing to ESLint here

@nzakas nzakas changed the title [WIP]feat: add prefer-object-has-own rule feat: add prefer-object-has-own rule Nov 24, 2021
@nzakas
Copy link
Member

nzakas commented Nov 24, 2021

No need to prefix with "[WIP]" (which messes up the commit message check). It's fine to just submit the PR as a draft. That tells us it's not ready for review yet.

@snitin315 snitin315 marked this pull request as ready for review December 2, 2021 13:16
Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

Looks like a good start. The auto fixing is incorrect, I left a comment on one of the invalid tests.

docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
tests/lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
@snitin315 snitin315 force-pushed the feat/prefer-object-has-own-rule branch from e828a2f to a26dd15 Compare December 3, 2021 02:05
@snitin315 snitin315 requested a review from bmish December 6, 2021 09:29
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
@snitin315
Copy link
Contributor Author

@mdjermanovic thanks for the review, I have applied the latest feedback.

lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
tests/lib/rules/prefer-object-has-own.js Outdated Show resolved Hide resolved
tests/lib/rules/prefer-object-has-own.js Show resolved Hide resolved
tests/lib/rules/prefer-object-has-own.js Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
docs/rules/prefer-object-has-own.md Outdated Show resolved Hide resolved
Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@nzakas nzakas merged commit eafaf52 into main Dec 11, 2021
@nzakas nzakas deleted the feat/prefer-object-has-own-rule branch December 11, 2021 01:20
@fisker
Copy link
Contributor

fisker commented Dec 11, 2021

I think the auto-fix will break

return{}.hasOwnProperty.call(object, property)
      ^ no space after `return`.

@snitin315
Copy link
Contributor Author

Hmm, this should we auto fixed to return Object.hasOwn(object, property) instead of returnObject.hasOwn(object, property).

Thanks, I will fix it in a separate PR.

@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Jun 10, 2022
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Jun 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A rule suggesting to replace Object.prototype.hasOwnProperty.call with Object.hasOwn
5 participants