From eb26affa8d8171047f14adbb0941ae8a9e9e9545 Mon Sep 17 00:00:00 2001 From: Ross <52366381+ROSSROSALES@users.noreply.github.com> Date: Fri, 7 Oct 2022 02:10:36 +0000 Subject: [PATCH] [Fix] sort-prop-types Passed all test cases typo fixed --- docs/rules/sort-prop-types.md | 2 ++ lib/rules/sort-prop-types.js | 34 +++++++++++++++--------------- tests/lib/rules/sort-prop-types.js | 7 +----- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/rules/sort-prop-types.md b/docs/rules/sort-prop-types.md index 0c0a5da0e1..a23d15c3fc 100644 --- a/docs/rules/sort-prop-types.md +++ b/docs/rules/sort-prop-types.md @@ -2,6 +2,8 @@ 💼 This rule is enabled in the following [configs](https://github.com/jsx-eslint/eslint-plugin-react#shareable-configurations): `all`. +🔧 This rule is automatically fixable using the `--fix` [flag](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) on the command line. + 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. ## Rule Details diff --git a/lib/rules/sort-prop-types.js b/lib/rules/sort-prop-types.js index 977f246432..706b7e170c 100644 --- a/lib/rules/sort-prop-types.js +++ b/lib/rules/sort-prop-types.js @@ -8,13 +8,13 @@ const variableUtil = require('../util/variable'); const propsUtil = require('../util/props'); const docsUrl = require('../util/docsUrl'); const propWrapperUtil = require('../util/propWrapper'); -// const propTypesSortUtil = require('../util/propTypesSort'); +const propTypesSortUtil = require('../util/propTypesSort'); const report = require('../util/report'); // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ - + const messages = { requiredPropsFirst: 'Required prop types must be listed before all other prop types', callbackPropsLast: 'Callback prop types must be listed after all other prop types', @@ -29,7 +29,7 @@ module.exports = { recommended: false, url: docsUrl('sort-prop-types'), }, - // fixable: 'code', + fixable: 'code', messages, @@ -106,17 +106,17 @@ module.exports = { return; } - // function fix(fixer) { - // return propTypesSortUtil.fixPropTypesSort( - // fixer, - // context, - // declarations, - // ignoreCase, - // requiredFirst, - // callbacksLast, - // sortShapeProp - // ); - // } + function fix(fixer) { + return propTypesSortUtil.fixPropTypesSort( + fixer, + context, + declarations, + ignoreCase, + requiredFirst, + callbacksLast, + sortShapeProp + ); + } const callbackPropsLastSeen = new WeakSet(); const requiredPropsFirstSeen = new WeakSet(); @@ -150,7 +150,7 @@ module.exports = { requiredPropsFirstSeen.add(curr); report(context, messages.requiredPropsFirst, 'requiredPropsFirst', { node: curr, - // fix + fix }); } return curr; @@ -168,7 +168,7 @@ module.exports = { callbackPropsLastSeen.add(prev); report(context, messages.callbackPropsLast, 'callbackPropsLast', { node: prev, - // fix + fix }); } return prev; @@ -180,7 +180,7 @@ module.exports = { propsNotSortedSeen.add(curr); report(context, messages.propsNotSorted, 'propsNotSorted', { node: curr, - // fix + fix }); } return prev; diff --git a/tests/lib/rules/sort-prop-types.js b/tests/lib/rules/sort-prop-types.js index 54e8223bb3..762dcdb889 100644 --- a/tests/lib/rules/sort-prop-types.js +++ b/tests/lib/rules/sort-prop-types.js @@ -468,11 +468,6 @@ ruleTester.run('sort-prop-types', rule, { options: [{ sortShapeProp: true }], } )), - // - // - // - // - invalid: parsers.all([].concat( { code: ` @@ -1890,6 +1885,6 @@ ruleTester.run('sort-prop-types', rule, { line: 4, }, ], - }, + } )), });