Skip to content
Merged
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
13 changes: 12 additions & 1 deletion lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ module.exports = {
return tokens.length && tokens[0].value === '...';
}

/**
* Removes quotes from around an identifier.
* @param {string} the identifier to strip
*/
function stripQuotes(string) {
if (string[0] === '\'' || string[0] === '"' && string[0] === string[string.length - 1]) {
return string.slice(1, string.length - 1);
}
return string;
}

/**
* Retrieve the name of a key node
* @param {ASTNode} node The AST node with the key.
Expand All @@ -310,7 +321,7 @@ module.exports = {
var tokens = context.getFirstTokens(node, 2);
return (tokens[0].value === '+' || tokens[0].value === '-'
? tokens[1].value
: tokens[0].value
: stripQuotes(tokens[0].value)
);
}
var key = node.key || node.argument;
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,16 @@ ruleTester.run('prop-types', rule, {
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'type Props = {',
' \'completed?\': boolean,',
'};',
'const Hello = (props: Props): React.Element => {',
' return <div>{props[\'completed?\']}</div>;',
'}'
].join('\n'),
parser: 'babel-eslint'
}, {
code: [
'Card.propTypes = {',
Expand Down