Skip to content

Commit eb26aff

Browse files
committed
[Fix] sort-prop-types Passed all test cases typo fixed
1 parent 1a5a9e2 commit eb26aff

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

docs/rules/sort-prop-types.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
💼 This rule is enabled in the following [configs](https://github.com/jsx-eslint/eslint-plugin-react#shareable-configurations): `all`.
44

5+
🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line.
6+
57
Some developers prefer to sort prop type declarations alphabetically to be able to find necessary declaration easier at the later time. Others feel that it adds complexity and becomes burden to maintain.
68

79
## Rule Details

lib/rules/sort-prop-types.js

+17-17
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ const variableUtil = require('../util/variable');
88
const propsUtil = require('../util/props');
99
const docsUrl = require('../util/docsUrl');
1010
const propWrapperUtil = require('../util/propWrapper');
11-
// const propTypesSortUtil = require('../util/propTypesSort');
11+
const propTypesSortUtil = require('../util/propTypesSort');
1212
const report = require('../util/report');
1313

1414
// ------------------------------------------------------------------------------
1515
// Rule Definition
1616
// ------------------------------------------------------------------------------
17-
17+
1818
const messages = {
1919
requiredPropsFirst: 'Required prop types must be listed before all other prop types',
2020
callbackPropsLast: 'Callback prop types must be listed after all other prop types',
@@ -29,7 +29,7 @@ module.exports = {
2929
recommended: false,
3030
url: docsUrl('sort-prop-types'),
3131
},
32-
// fixable: 'code',
32+
fixable: 'code',
3333

3434
messages,
3535

@@ -106,17 +106,17 @@ module.exports = {
106106
return;
107107
}
108108

109-
// function fix(fixer) {
110-
// return propTypesSortUtil.fixPropTypesSort(
111-
// fixer,
112-
// context,
113-
// declarations,
114-
// ignoreCase,
115-
// requiredFirst,
116-
// callbacksLast,
117-
// sortShapeProp
118-
// );
119-
// }
109+
function fix(fixer) {
110+
return propTypesSortUtil.fixPropTypesSort(
111+
fixer,
112+
context,
113+
declarations,
114+
ignoreCase,
115+
requiredFirst,
116+
callbacksLast,
117+
sortShapeProp
118+
);
119+
}
120120

121121
const callbackPropsLastSeen = new WeakSet();
122122
const requiredPropsFirstSeen = new WeakSet();
@@ -150,7 +150,7 @@ module.exports = {
150150
requiredPropsFirstSeen.add(curr);
151151
report(context, messages.requiredPropsFirst, 'requiredPropsFirst', {
152152
node: curr,
153-
// fix
153+
fix
154154
});
155155
}
156156
return curr;
@@ -168,7 +168,7 @@ module.exports = {
168168
callbackPropsLastSeen.add(prev);
169169
report(context, messages.callbackPropsLast, 'callbackPropsLast', {
170170
node: prev,
171-
// fix
171+
fix
172172
});
173173
}
174174
return prev;
@@ -180,7 +180,7 @@ module.exports = {
180180
propsNotSortedSeen.add(curr);
181181
report(context, messages.propsNotSorted, 'propsNotSorted', {
182182
node: curr,
183-
// fix
183+
fix
184184
});
185185
}
186186
return prev;

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,6 @@ ruleTester.run('sort-prop-types', rule, {
468468
options: [{ sortShapeProp: true }],
469469
}
470470
)),
471-
//
472-
//
473-
//
474-
//
475-
476471
invalid: parsers.all([].concat(
477472
{
478473
code: `
@@ -1890,6 +1885,6 @@ ruleTester.run('sort-prop-types', rule, {
18901885
line: 4,
18911886
},
18921887
],
1893-
},
1888+
}
18941889
)),
18951890
});

0 commit comments

Comments
 (0)