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

Avoid usage of unguarded getRangeAt and add eslint rule #16212

Merged
merged 5 commits into from
Jul 29, 2019
Merged

Avoid usage of unguarded getRangeAt and add eslint rule #16212

merged 5 commits into from
Jul 29, 2019

Conversation

bor0
Copy link
Contributor

@bor0 bor0 commented Jun 18, 2019

Description

Closes #15606.

This PR addresses #15606. I ran a grep through all getRangeAt calls and fixed all occurrences. It also adds a new eslint rule.

Types of changes

The PR introduces a Bug fix (non-breaking change which fixes an issue), and also adds a rule
enforcement to avoid similar problems in the future

@gziolo gziolo added Browser Issues Issues or PRs that are related to browser specific problems [Type] Bug An existing feature does not function as intended [Type] Task Issues or PRs that have been broken down into an individual action to take [Package] Components /packages/components First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository and removed [Type] Bug An existing feature does not function as intended labels Jun 20, 2019
Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Thanks for this proposal!

Each custom ESLint rule should have its own documentation:

https://github.com/WordPress/gutenberg/tree/master/packages/eslint-plugin/docs/rules

It should also be included in the "Rules" tab of the README.md file:

https://github.com/WordPress/gutenberg/tree/master/packages/eslint-plugin#rules

It's a fairly targeted rule, which makes me wonder if it's the sort of thing where we could generalize the guarding. That said, it's a pretty specific issue with this one function affecting some browsers and not others. I guess we'd really only care to revise it if there were other range functions which are similarly problematic when unguarded.

packages/eslint-plugin/configs/custom.js Outdated Show resolved Hide resolved
@bor0
Copy link
Contributor Author

bor0 commented Jun 26, 2019

Thanks @aduth, I updated the PR.

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! 👍

@aduth
Copy link
Member

aduth commented Jun 26, 2019

Some last-minute thoughts / feedback:

  • We should include a CHANGELOG entry detailing the rule being added (done in afc18a4).
  • I considered (and pushed in 2bf8129) that we name this as "no-" prefixed, rather than "avoid-", since we already have a fair number of theses "avoidance" rules which are consistently named as such. Let me know if you have any thoughts on this.

I was also wondering about the developer experience for someone who encounters this warning. Will it be obvious what they need to do to resolve the issue, when the message is simply "Avoid unguarded getRangeAt" ? I wonder if we could expand the message and/or implement a fixer (depending on difficulty).

It still looks good in its current form, and we could merge it as-is if you're okay with the proposed changes.

@youknowriad
Copy link
Contributor

Can we unblock this. It it seems readyish. Just need a refresh/rebase.

@bor0
Copy link
Contributor Author

bor0 commented Jul 26, 2019

Conflicts resolved, thanks!

@aduth aduth merged commit d45c8ea into WordPress:master Jul 29, 2019
@github-actions github-actions bot added this to the Gutenberg 6.3 milestone Jul 29, 2019
@bor0 bor0 deleted the fix/avoid-unguarded-getrangeat branch July 29, 2019 18:24
gziolo pushed a commit that referenced this pull request Aug 29, 2019
* Avoid usage of unguarded getRangeAt and add eslint rule

* Address PR comments

* ESLint Plugin: Add CHANGELOG entry for avoid-unguarded-get-range-at

* ESLint Plugin: Rename avoid-unguarded-get-range-at to no-unguarded-get-range-at
gziolo pushed a commit that referenced this pull request Aug 29, 2019
* Avoid usage of unguarded getRangeAt and add eslint rule

* Address PR comments

* ESLint Plugin: Add CHANGELOG entry for avoid-unguarded-get-range-at

* ESLint Plugin: Rename avoid-unguarded-get-range-at to no-unguarded-get-range-at
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Browser Issues Issues or PRs that are related to browser specific problems First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Components /packages/components [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Components: Avoid unguarded getRangeAt (Autocomplete)
4 participants