Skip to content

Commit

Permalink
[Fix] sort-prop-types: fix string property order
Browse files Browse the repository at this point in the history
Fixes #1976.

,
  • Loading branch information
metreniuk authored and ljharb committed Sep 10, 2018
1 parent 95d3c3f commit f0e2e1e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/sort-prop-types.js
Expand Up @@ -57,6 +57,9 @@ module.exports = {
const propWrapperFunctions = new Set(context.settings.propWrapperFunctions || []);

function getKey(node) {
if (node.key && node.key.value) {
return node.key.value;
}
return sourceCode.getText(node.key || node.argument);
}

Expand Down
34 changes: 34 additions & 0 deletions tests/lib/rules/sort-prop-types.js
Expand Up @@ -1533,5 +1533,39 @@ ruleTester.run('sort-prop-types', rule, {
' }',
'});'
].join('\n')
}, {
code: [
'var First = createReactClass({',
' propTypes: {',
' \'data-letter\': PropTypes.string,',
' a: PropTypes.any,',
' e: PropTypes.any',
' },',
' render: function() {',
' return <div />;',
' }',
'});'
].join('\n'),
options: [{
noSortAlphabetically: false
}],
errors: [{
message: ERROR_MESSAGE,
line: 4,
column: 5,
type: 'Property'
}],
output: [
'var First = createReactClass({',
' propTypes: {',
' a: PropTypes.any,',
' \'data-letter\': PropTypes.string,',
' e: PropTypes.any',
' },',
' render: function() {',
' return <div />;',
' }',
'});'
].join('\n')
}]
});

0 comments on commit f0e2e1e

Please sign in to comment.