Skip to content

Commit 5680a2b

Browse files
committed
Fix sort-prop-types string property order
1 parent 95d3c3f commit 5680a2b

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/rules/sort-prop-types.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ module.exports = {
5757
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);
5858

5959
function getKey(node) {
60-
return sourceCode.getText(node.key || node.argument);
60+
const key = sourceCode.getText(node.key || node.argument);
61+
const hasLeadingQuote = /['"]/.test(key[0]);
62+
return hasLeadingQuote ? key.substring(1, key.length - 1) : key;
6163
}
6264

6365
function getValueName(node) {

tests/lib/rules/sort-prop-types.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,5 +1533,39 @@ ruleTester.run('sort-prop-types', rule, {
15331533
' }',
15341534
'});'
15351535
].join('\n')
1536+
}, {
1537+
code: [
1538+
'var First = createReactClass({',
1539+
' propTypes: {',
1540+
' \'data-letter\': PropTypes.string,',
1541+
' a: PropTypes.any,',
1542+
' e: PropTypes.any',
1543+
' },',
1544+
' render: function() {',
1545+
' return <div />;',
1546+
' }',
1547+
'});'
1548+
].join('\n'),
1549+
options: [{
1550+
noSortAlphabetically: false
1551+
}],
1552+
errors: [{
1553+
message: ERROR_MESSAGE,
1554+
line: 4,
1555+
column: 5,
1556+
type: 'Property'
1557+
}],
1558+
output: [
1559+
'var First = createReactClass({',
1560+
' propTypes: {',
1561+
' a: PropTypes.any,',
1562+
' \'data-letter\': PropTypes.string,',
1563+
' e: PropTypes.any',
1564+
' },',
1565+
' render: function() {',
1566+
' return <div />;',
1567+
' }',
1568+
'});'
1569+
].join('\n')
15361570
}]
15371571
});

0 commit comments

Comments
 (0)