Skip to content

Commit 243606d

Browse files
Xunnamiusljharb
authored andcommitted
[Fix] order: resolve undefined property access issue when using named ordering
Fixes #3159.
1 parent 4f145a2 commit 243606d

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Diff for: CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1818
- [`no-unused-modules`]: provide more meaningful error message when no .eslintrc is present ([#3116], thanks [@michaelfaith])
1919
- configs: added missing name attribute for eslint config inspector ([#3151], thanks [@NishargShah])
2020
- [`order`]: ensure arcane imports do not cause undefined behavior ([#3128], thanks [@Xunnamius])
21+
- [`order`]: resolve undefined property access issue when using `named` ordering ([#3166], thanks [@Xunnamius])
2122

2223
### Changed
2324
- [Docs] [`extensions`], [`order`]: improve documentation ([#3106], thanks [@Xunnamius])
@@ -1173,6 +1174,7 @@ for info on changes for earlier releases.
11731174

11741175
[`memo-parser`]: ./memo-parser/README.md
11751176

1177+
[#3166]: https://github.com/import-js/eslint-plugin-import/pull/3166
11761178
[#3151]: https://github.com/import-js/eslint-plugin-import/pull/3151
11771179
[#3138]: https://github.com/import-js/eslint-plugin-import/pull/3138
11781180
[#3129]: https://github.com/import-js/eslint-plugin-import/pull/3129

Diff for: src/rules/order.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,9 @@ module.exports = {
12191219
if (node.right.type === 'ObjectExpression') {
12201220
for (let i = 0; i < node.right.properties.length; i++) {
12211221
if (
1222-
node.right.properties[i].key.type !== 'Identifier'
1222+
!node.right.properties[i].key
1223+
|| node.right.properties[i].key.type !== 'Identifier'
1224+
|| !node.right.properties[i].value
12231225
|| node.right.properties[i].value.type !== 'Identifier'
12241226
) {
12251227
return;

Diff for: tests/src/rules/order.js

+12
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,18 @@ context('TypeScript', function () {
39443944
},
39453945
],
39463946
}),
3947+
// Ensure the rule doesn't choke and die when right-hand-side AssignmentExpression properties lack a "key" attribute (e.g. SpreadElement)
3948+
test({
3949+
code: `
3950+
// https://prettier.io/docs/en/options.html
3951+
3952+
module.exports = {
3953+
...require('@xxxx/.prettierrc.js'),
3954+
};
3955+
`,
3956+
...parserConfig,
3957+
options: [{ named: { enabled: true } }],
3958+
}),
39473959
// Option: sortTypesGroup: true and newlines-between-types: 'always-and-inside-groups' and consolidateIslands: 'inside-groups'
39483960
test({
39493961
code: `

0 commit comments

Comments
 (0)