Skip to content

Conversation

tgvrssanthosh
Copy link
Contributor

Summary

Added auto-fixer for no-array-prototype-extensions which replaces any with some.

Description

Recently, the proposal to deprecate array prototype extensions has been approved and got merged. The plan is to add autoFixers to replace ember array prototype extensions with the native array methods. In this PR, an auto fixer has been added which will replace the ember array method any with the native array method some.

Testing

Modified test case to check if the right output is generated after the fix.

@smilland
Copy link
Contributor

smilland commented Oct 6, 2022

Thank you @tgvrssanthosh ! cc: @bmish

url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/no-array-prototype-extensions.md',
},
fixable: null,
fixable: 'code',
Copy link
Contributor

@smilland smilland Oct 6, 2022

Choose a reason for hiding this comment

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

Wondering shall we use suggestions here for all fixers?
Giving: 1. there are multiple ways of fixing the issue 2. some fixers might not work very well (eg. for those who need to use ember getter/setters). Having it as a suggestion would implicitly encourage them to put more thought into whether to accept the suggestion.

Copy link
Member

@bmish bmish Oct 6, 2022

Choose a reason for hiding this comment

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

In this case, I do think we should keep it as an autofixer. Why?

  • any to some is a straightforward conversion where there's only one obvious way of fixing the issue.
  • An autofixer is a lot more useful as it can be used for mass conversion, whereas a suggestion needs to be manually applied for each instance.
  • We already know this rule is not 100% perfect and can experience false positives as described in its rule doc, which is why it's not a recommended rule, but for anyone who still proceeds to enable it, they ideally should be aware of these limitations, and regardless, any resulting fixes still need to go through code review.

I do agree we should consider suggestions for some autofixes, but only under the following circumstances:

  • There are multiple ways of fixing an issue and we don't know which way is appropriate for a given instance. Note that multiple ways of fixing an issue does not automatically preclude an autofix as we can still choose an autofix that we think is most likely to be satisfactory. And there could even be a rule option if the user needs to choose which autofixing strategy to use.
  • We aren't sure if the fix is correct or there's a chance the fix could break the code.

I hope we can eventually autofix many or most cases for this lint rule to increase the chance of successful migrations off these array prototype methods, and only use suggestions where truly needed. If any of the autofixers turn out to be problematic, we can always convert them to suggestions later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As @bmish has called out, this is a known risk as the rule is not 100% perfect. In case there are multiple ways of fixing an issue, we can still apply some default auto fix and a user can change it as needed. wdyt @smilland ?

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good!

@bmish bmish changed the title Added auto-fixer for no-array-prototype-extensions Add some -> any autofixer for no-array-prototype-extensions rule Oct 6, 2022
@bmish bmish changed the title Add some -> any autofixer for no-array-prototype-extensions rule Add any to some autofixer for no-array-prototype-extensions rule Oct 6, 2022
@bmish
Copy link
Member

bmish commented Oct 6, 2022

@tgvrssanthosh can you run the command to update the README rules list?

@tgvrssanthosh
Copy link
Contributor Author

@tgvrssanthosh can you run the command to update the README rules list?

@bmish Ran the script to update the readme file.

@tgvrssanthosh
Copy link
Contributor Author

@bmish If you are fine with the changes, can you please merge the PR so that I can create follow-up PRs?

@bmish bmish merged commit 833c61e into ember-cli:master Oct 6, 2022
@bmish
Copy link
Member

bmish commented Oct 6, 2022

Thanks for getting this autofixer started!

@tgvrssanthosh tgvrssanthosh deleted the autoFix-any branch October 6, 2022 18:35
bmish added a commit that referenced this pull request Oct 7, 2022
…orn-44.0.0

* master:
  Add `compact` to `filter` autofixer for `no-array-prototype-extensions` rule (#1611)
  build(deps-dev): bump release-it from 15.4.2 to 15.5.0 (#1612)
  build(deps-dev): bump @babel/plugin-proposal-decorators from 7.19.1 to 7.19.3 (#1602)
  build(deps-dev): bump @typescript-eslint/parser from 5.38.0 to 5.38.1 (#1604)
  build(deps-dev): bump jsdom from 20.0.0 to 20.0.1 (#1607)
  build(deps-dev): bump sort-package-json from 1.57.0 to 2.0.0 (#1606)
  Add `filterBy` to `filter` autofixer for `no-array-prototype-extensions` rule (#1610)
  Add `any` to `some` autofixer for `no-array-prototype-extensions` rule (#1609)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants