From f0e2e1e364f27be89e771dda237b6a422c839be6 Mon Sep 17 00:00:00 2001 From: ametreniuc Date: Mon, 10 Sep 2018 19:07:19 +0300 Subject: [PATCH] [Fix] `sort-prop-types`: fix string property order Fixes #1976. , --- lib/rules/sort-prop-types.js | 3 +++ tests/lib/rules/sort-prop-types.js | 34 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/rules/sort-prop-types.js b/lib/rules/sort-prop-types.js index da94a641db..a2e2cf22a5 100644 --- a/lib/rules/sort-prop-types.js +++ b/lib/rules/sort-prop-types.js @@ -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); } diff --git a/tests/lib/rules/sort-prop-types.js b/tests/lib/rules/sort-prop-types.js index e83ccacd34..3f8d184626 100644 --- a/tests/lib/rules/sort-prop-types.js +++ b/tests/lib/rules/sort-prop-types.js @@ -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
;', + ' }', + '});' + ].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
;', + ' }', + '});' + ].join('\n') }] });