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

[#73] Account for SpreadElement AST Nodes #76

Merged
merged 1 commit into from
Mar 17, 2019

Conversation

jessebeach
Copy link
Collaborator

Account for array SpreadElement nodes.

<div foo={[...this.props.params, bar]} />

@coveralls
Copy link

Coverage Status

Coverage increased (+0.007%) to 98.851% when pulling f04df70 on jessebeach:fix-SpreadElement into 525da04 on evcohen:master.

it('should evaluate to a correct representation of an array with spread elements', () => {
const prop = extractProp('<div foo={[...this.props.params, bar]} />');

const expected = [undefined, 'bar'];
Copy link
Member

Choose a reason for hiding this comment

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

is there no way to represent this.props.params here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ljharb I honestly can't think of one. The values of the array would be spread in, or no values would be spread in at all. I have to return something that can be evaluated in code. An empty array doesn't make sense, since spreading values into an array wouldn't produce an array (it would produce more values in the containing array). The best I could come up with is undefined. I'm up for alternatives if you have them.

Copy link
Member

Choose a reason for hiding this comment

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

I'm just wondering if maybe a special object indicating what was spread; that way a props-related rule could know that the "params" prop was used here (thinking of how this can be used in eslint-plugin-react)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ljharb I don't think we'll need it in the eslint-plugin-jsx-a11y project. Once we encounter a spread, we can't statically analyze any further.

@jessebeach jessebeach merged commit a9d4159 into jsx-eslint:master Mar 17, 2019
@jessebeach jessebeach deleted the fix-SpreadElement branch March 17, 2019 21:43
jessebeach added a commit to jessebeach/jsx-ast-utils that referenced this pull request Mar 24, 2019
[jsx-eslint#73] Account for SpreadElement AST Nodes

[jsx-eslint#70] Support OptionalMemberExpression AST nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants