From 40e8658b41b68bac19f3f9b9e9c63ec3bcf37830 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Sat, 16 Dec 2023 01:33:40 -0800 Subject: [PATCH] Style changes --- configs/recommended.js | 1 - lib/rules/forward-ref-uses-ref.js | 8 +-- tests/lib/rules/forward-ref-uses-ref.js | 86 ++++++++++++------------- 3 files changed, 44 insertions(+), 51 deletions(-) diff --git a/configs/recommended.js b/configs/recommended.js index fb8710bb63..0bba09f7bb 100644 --- a/configs/recommended.js +++ b/configs/recommended.js @@ -6,7 +6,6 @@ module.exports = Object.assign({}, all, { languageOptions: all.languageOptions, rules: { 'react/display-name': 2, - 'react/forward-ref-uses-ref': 2, 'react/jsx-key': 2, 'react/jsx-no-comment-textnodes': 2, 'react/jsx-no-duplicate-props': 2, diff --git a/lib/rules/forward-ref-uses-ref.js b/lib/rules/forward-ref-uses-ref.js index 7aa1d96e5e..87ba5b7350 100644 --- a/lib/rules/forward-ref-uses-ref.js +++ b/lib/rules/forward-ref-uses-ref.js @@ -14,8 +14,7 @@ const getMessageData = require('../util/message'); // ------------------------------------------------------------------------------ const messages = { - missingRefParameter: - 'forwardRef is used with this component but no ref parameter is set', + missingRefParameter: 'forwardRef is used with this component but no ref parameter is set', addRefParameter: 'Add a ref parameter', removeForwardRef: 'Remove forwardRef wrapper', }; @@ -25,7 +24,7 @@ module.exports = { docs: { description: 'Require all forwardRef components include a ref parameter', category: 'Possible Errors', - recommended: true, + recommended: false, url: docsUrl('forward-ref-uses-ref'), }, messages, @@ -52,8 +51,7 @@ module.exports = { return ( node.type === 'CallExpression' && (isForwardRefIdentifier(node.callee) - || (node.callee.type === 'MemberExpression' - && isForwardRefIdentifier(node.callee.property))) + || (node.callee.type === 'MemberExpression' && isForwardRefIdentifier(node.callee.property))) ); } diff --git a/tests/lib/rules/forward-ref-uses-ref.js b/tests/lib/rules/forward-ref-uses-ref.js index 9c144745d4..59cc1b2867 100644 --- a/tests/lib/rules/forward-ref-uses-ref.js +++ b/tests/lib/rules/forward-ref-uses-ref.js @@ -30,68 +30,68 @@ const tests = { code: ` import { forwardRef } from 'react' forwardRef((props, ref) => { - return null - }) + return null; + }); `, }, { code: ` import { forwardRef } from 'react' - forwardRef((props, ref) => null) + forwardRef((props, ref) => null); `, }, { code: ` import { forwardRef } from 'react' forwardRef(function (props, ref) { - return null - }) + return null; + }); `, }, { code: ` import { forwardRef } from 'react' forwardRef(function Component(props, ref) { - return null - }) + return null; + }); `, }, { code: ` import * as React from 'react' React.forwardRef((props, ref) => { - return null - }) + return null; + }); `, }, { code: ` import * as React from 'react' - React.forwardRef((props, ref) => null) + React.forwardRef((props, ref) => null); `, }, { code: ` import * as React from 'react' React.forwardRef(function (props, ref) { - return null - }) + return null; + }); `, }, { code: ` import * as React from 'react' React.forwardRef(function Component(props, ref) { - return null - }) + return null; + }); `, }, { code: ` import * as React from 'react' function Component(props) { - return null - } + return null; + }; `, }, ]), @@ -100,21 +100,20 @@ const tests = { code: ` import { forwardRef } from 'react' forwardRef((props) => { - return null - }) + return null; + }); `, errors: [ { - message: - 'forwardRef is used with this component but no ref parameter is set', + message: 'forwardRef is used with this component but no ref parameter is set', suggestions: [ { messageId: 'addRefParameter', output: ` import { forwardRef } from 'react' forwardRef((props, ref) => { - return null - }) + return null; + }); `, }, { @@ -122,8 +121,8 @@ const tests = { output: ` import { forwardRef } from 'react' (props) => { - return null - } + return null; + }; `, }, ], @@ -133,25 +132,24 @@ const tests = { { code: ` import * as React from 'react' - React.forwardRef((props) => null) + React.forwardRef((props) => null); `, errors: [ { - message: - 'forwardRef is used with this component but no ref parameter is set', + message: 'forwardRef is used with this component but no ref parameter is set', suggestions: [ { messageId: 'addRefParameter', output: ` import * as React from 'react' - React.forwardRef((props, ref) => null) + React.forwardRef((props, ref) => null); `, }, { messageId: 'removeForwardRef', output: ` import * as React from 'react' - (props) => null + (props) => null; `, }, ], @@ -162,21 +160,20 @@ const tests = { code: ` import { forwardRef } from 'react' forwardRef(function (props) { - return null - }) + return null; + }); `, errors: [ { - message: - 'forwardRef is used with this component but no ref parameter is set', + message: 'forwardRef is used with this component but no ref parameter is set', suggestions: [ { messageId: 'addRefParameter', output: ` import { forwardRef } from 'react' forwardRef(function (props, ref) { - return null - }) + return null; + }); `, }, { @@ -184,8 +181,8 @@ const tests = { output: ` import { forwardRef } from 'react' function (props) { - return null - } + return null; + }; `, }, ], @@ -196,21 +193,20 @@ const tests = { code: ` import * as React from 'react' React.forwardRef(function Component(props) { - return null - }) + return null; + }); `, errors: [ { - message: - 'forwardRef is used with this component but no ref parameter is set', + message: 'forwardRef is used with this component but no ref parameter is set', suggestions: [ { messageId: 'addRefParameter', output: ` import * as React from 'react' React.forwardRef(function Component(props, ref) { - return null - }) + return null; + }); `, }, { @@ -218,8 +214,8 @@ const tests = { output: ` import * as React from 'react' function Component(props) { - return null - } + return null; + }; `, }, ],