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

Ignore direct instantiation of EmberArray in no-array-prototype-extensions rule #1749

Conversation

canrozanes
Copy link
Contributor

@canrozanes canrozanes commented Jan 21, 2023

Overview

Partially fixes #1561. Helps reduce false positives.

Direct instantiation of Ember arrays ie:

function myFunction(){
  const array = A([1, 2, 3])
  array.toArray()
}

are not deprecated so they should be allowed by the linter.

@bmish bmish added the Bug label Jan 21, 2023
tests/lib/rules/no-array-prototype-extensions.js Outdated Show resolved Hide resolved
node.type === 'CallExpression' &&
nodeInitializedTo &&
nodeInitializedTo.callee &&
(nodeInitializedTo.callee.name === 'A' || nodeInitializedTo.callee.name === 'EmberArray')
Copy link
Member

Choose a reason for hiding this comment

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

We're going to have to check against the actual names these are imported under, if they're imported at all. See the ImportDeclaration visitor for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the logic to fetch the actual import name and also updated the test cases to include an import statement.

Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

Can you also add a correct code sample in the rule doc showing that this case is allowed?

lib/rules/no-array-prototype-extensions.js Outdated Show resolved Hide resolved
lib/rules/no-array-prototype-extensions.js Outdated Show resolved Hide resolved
lib/rules/no-array-prototype-extensions.js Outdated Show resolved Hide resolved
@bmish bmish changed the title fix: ignore ember array initialized variables in no-array-prototype-extension Ignore direct instantiation of EmberArray in no-array-prototype-extensions rule Jan 23, 2023
@bmish bmish changed the title Ignore direct instantiation of EmberArray in no-array-prototype-extensions rule Ignore variable instantiated to an EmberArray in no-array-prototype-extensions rule Jan 23, 2023
Copy link
Member

@bmish bmish left a comment

Choose a reason for hiding this comment

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

Thanks!

@bmish bmish changed the title Ignore variable instantiated to an EmberArray in no-array-prototype-extensions rule Ignore direct instantiation of EmberArray in no-array-prototype-extensions rule Jan 23, 2023
@bmish bmish merged commit 9ded580 into ember-cli:master Jan 23, 2023
@canrozanes canrozanes deleted the canrozanes/add-condition-to-array-prototype-extension-rule branch January 23, 2023 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Even more false positives with no-array-prototype-extensions rule
2 participants