Skip to content

Commit 45a09a6

Browse files
authored
Fix: handle spreads in rule meta objects (#100)
1 parent 68059b1 commit 45a09a6

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/utils.js

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ module.exports = {
184184
* @returns {string|null} The key name, or `null` if the name cannot be determined statically.
185185
*/
186186
getKeyName (property) {
187+
if (!property.key) {
188+
// likely a SpreadElement or another non-standard node
189+
return null;
190+
}
187191
if (!property.computed && property.key.type === 'Identifier') {
188192
return property.key.name;
189193
}

tests/lib/rules/require-meta-fixable.js

+13
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,19 @@ ruleTester.run('require-meta-fixable', rule, {
105105
create(context) { context.report(node, message, data, fix); }
106106
};
107107
`,
108+
{
109+
code: `
110+
const meta = {};
111+
module.exports = {
112+
...meta,
113+
meta: {},
114+
create(context) { context.report(node, message, data, fix); }
115+
};
116+
`,
117+
parserOptions: {
118+
ecmaVersion: 9,
119+
},
120+
},
108121
],
109122

110123
invalid: [

tests/lib/utils.js

+11
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,17 @@ describe('utils', () => {
183183
assert.strictEqual(utils.getKeyName(ast.body[0].expression.properties[0]), CASES[objectSource]);
184184
});
185185
});
186+
187+
const CASES_ES9 = {
188+
'({ ...foo })': null,
189+
};
190+
Object.keys(CASES_ES9).forEach(objectSource => {
191+
it(objectSource, () => {
192+
const ast = espree.parse(objectSource, { ecmaVersion: 9 });
193+
194+
assert.strictEqual(utils.getKeyName(ast.body[0].expression.properties[0]), CASES_ES9[objectSource]);
195+
});
196+
});
186197
});
187198

188199
describe('getTestInfo', () => {

0 commit comments

Comments
 (0)