Skip to content

Commit ce330d8

Browse files
committed
Add additional failure test
1 parent 4ab1b3e commit ce330d8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ module.exports = function(context) {
7777
}
7878
if (!previousIsRequired && currentIsRequired) {
7979
// Encountered a non-required prop after a required prop
80-
context.report(prev, 'Required prop types must be listed before all other prop types');
81-
return prev;
80+
context.report(curr, 'Required prop types must be listed before all other prop types');
81+
return curr;
8282
}
8383
}
8484

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,29 @@ ruleTester.run('jsx-sort-prop-types', rule, {
534534
column: 5,
535535
type: 'Property'
536536
}]
537+
}, {
538+
code: [
539+
'var First = React.createClass({',
540+
' propTypes: {',
541+
' fooRequired: React.PropTypes.string.isRequired,',
542+
' barRequired: React.PropTypes.string.isRequired,',
543+
' a: React.PropTypes.any',
544+
' },',
545+
' render: function() {',
546+
' return <div />;',
547+
' }',
548+
'});'
549+
].join('\n'),
550+
options: [{
551+
requiredFirst: true
552+
}],
553+
parserOptions: parserOptions,
554+
errors: [{
555+
message: ERROR_MESSAGE,
556+
line: 4,
557+
column: 5,
558+
type: 'Property'
559+
}]
537560
}, {
538561
code: [
539562
'var First = React.createClass({',
@@ -553,7 +576,7 @@ ruleTester.run('jsx-sort-prop-types', rule, {
553576
parserOptions: parserOptions,
554577
errors: [{
555578
message: 'Required prop types must be listed before all other prop types',
556-
line: 3,
579+
line: 4,
557580
column: 5,
558581
type: 'Property'
559582
}]

0 commit comments

Comments
 (0)