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

fix: import/order named not working with spread operator #3146

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,9 @@ module.exports = {
if (node.right.type === 'ObjectExpression') {
for (let i = 0; i < node.right.properties.length; i++) {
if (
node.right.properties[i].key.type !== 'Identifier'
!node.right.properties[i].key
|| node.right.properties[i].key.type !== 'Identifier'
|| !node.right.properties[i].value
|| node.right.properties[i].value.type !== 'Identifier'
) {
return;
Expand Down
9 changes: 9 additions & 0 deletions tests/files/order/spread-export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const test = {
a: 1,
browser: 2,
};

module.exports = {
...test,
platform: 'node',
};
23 changes: 23 additions & 0 deletions tests/src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ const rule = require('rules/order');

ruleTester.run('order', rule, {
valid: [
test({
code: `
import { platform, a, browser } from './order/spread-export';
`,
}),
// Default order using require
test({
code: `
Expand Down Expand Up @@ -3648,6 +3653,24 @@ flowRuleTester.run('order', rule, {
import typeof {foo} from 'common';
import {bar} from 'common';
`,
}),
test({
options: [
{
named: true,
},
],
code: `
const test = {
a: 1,
browser: 2,
};

module.exports = {
...test,
platform: 'node',
};
`,
Comment on lines +3657 to +3673
Copy link
Member

Choose a reason for hiding this comment

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

i'd like to also include a test that demonstrates that we only recognize platform as a named export from this file.

Copy link
Author

Choose a reason for hiding this comment

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

Im not that familiar with this codebase. How could I test this?

Copy link
Member

Choose a reason for hiding this comment

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

you'd want to make a fixture file with this test code in it, and then make two test cases that import this test file - one that imports platform and works, and one that imports a and/or browser and fails.

Copy link
Author

Choose a reason for hiding this comment

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

Im very sorry but can't figure it out. I added the cases but it doesn't fail? I suspect that I'm doing something wrong but cant figure out what.

Copy link
Member

Choose a reason for hiding this comment

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

Can you push up what you have? I'll take a look.

Copy link
Author

Choose a reason for hiding this comment

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

I tried looking at #3032 as it had fixture files I believe

})],
invalid: [
test({
Expand Down
Loading