Skip to content

Commit 8958efe

Browse files
committed
Use the same logic for determinign the key between prop-types and no-unused-prop-types
1 parent 1a36371 commit 8958efe

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/rules/no-unused-prop-types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ module.exports = {
265265
*/
266266
function getKeyValue(node) {
267267
if (node.type === 'ObjectTypeProperty') {
268-
const tokens = context.getFirstTokens(node, {count: 1, filter: tokenNode => tokenNode.type === 'Identifier'});
268+
const tokens = context.getFirstTokens(node, {count: 1, filter: tokenNode => ['Identifier', 'String'].includes(tokenNode.type)});
269269
return tokens[0].value;
270270
}
271271
const key = node.key || node.argument;

lib/rules/prop-types.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,8 @@ module.exports = {
346346
*/
347347
function getKeyValue(node) {
348348
if (node.type === 'ObjectTypeProperty') {
349-
const tokens = context.getFirstTokens(node, 2);
350-
return (tokens[0].value === '+' || tokens[0].value === '-'
351-
? tokens[1].value
352-
: stripQuotes(tokens[0].value)
353-
);
349+
const tokens = context.getFirstTokens(node, {count: 1, filter: tokenNode => ['Identifier', 'String'].includes(tokenNode.type)});
350+
return stripQuotes(tokens[0].value);
354351
}
355352
const key = node.key || node.argument;
356353
return key.type === 'Identifier' ? key.name : key.value;

0 commit comments

Comments
 (0)