From e9272a5ffe10374da90a17554f595a75f25490f0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Jul 2024 13:59:40 -0700 Subject: [PATCH 01/14] [Refactor] prefer non-iterator-protocol iteration when possible --- lib/rules/no-invalid-html-attribute.js | 26 ++++++++++++-------------- lib/rules/no-unused-state.js | 12 ++++++------ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/rules/no-invalid-html-attribute.js b/lib/rules/no-invalid-html-attribute.js index 6e46f3bd4c..0f018f8080 100644 --- a/lib/rules/no-invalid-html-attribute.js +++ b/lib/rules/no-invalid-html-attribute.js @@ -289,7 +289,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN } const singleAttributeParts = splitIntoRangedParts(node, /(\S+)/g); - for (const singlePart of singleAttributeParts) { + singleAttributeParts.forEach((singlePart) => { const allowedTags = VALID_VALUES.get(attributeName).get(singlePart.value); const reportingValue = singlePart.reportingValue; @@ -329,15 +329,13 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN suggest, }); } - } + }); const allowedPairsForAttribute = VALID_PAIR_VALUES.get(attributeName); if (allowedPairsForAttribute) { const pairAttributeParts = splitIntoRangedParts(node, /(?=(\b\S+\s*\S+))/g); - for (const pairPart of pairAttributeParts) { - for (const allowedPair of allowedPairsForAttribute) { - const pairing = allowedPair[0]; - const siblings = allowedPair[1]; + pairAttributeParts.forEach((pairPart) => { + allowedPairsForAttribute.forEach((siblings, pairing) => { const attributes = pairPart.reportingValue.split('\u0020'); const firstValue = attributes[0]; const secondValue = attributes[1]; @@ -357,12 +355,12 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN }); } } - } - } + }); + }); } const whitespaceParts = splitIntoRangedParts(node, /(\s+)/g); - for (const whitespacePart of whitespaceParts) { + whitespaceParts.forEach((whitespacePart) => { const data = { attributeName }; if (whitespacePart.range[0] === (node.range[0] + 1) || whitespacePart.range[1] === (node.range[1] - 1)) { @@ -386,7 +384,7 @@ function checkLiteralValueNode(context, attributeName, node, parentNode, parentN }], }); } - } + }); } const DEFAULT_ATTRIBUTES = ['rel']; @@ -579,9 +577,9 @@ function checkCreateProps(context, node, attribute) { } if (prop.value.type === 'ArrayExpression') { - for (const value of prop.value.elements) { + prop.value.elements.forEach((value) => { checkPropValidValue(context, node, value, attribute); - } + }); // eslint-disable-next-line no-continue continue; @@ -646,9 +644,9 @@ module.exports = { const attributes = new Set(context.options[0] || DEFAULT_ATTRIBUTES); - for (const attribute of attributes) { + attributes.forEach((attribute) => { checkCreateProps(context, node, attribute); - } + }); }, }; }, diff --git a/lib/rules/no-unused-state.js b/lib/rules/no-unused-state.js index 0ed480694d..e3b1d37c4b 100644 --- a/lib/rules/no-unused-state.js +++ b/lib/rules/no-unused-state.js @@ -174,7 +174,7 @@ module.exports = { // Records used state fields and new aliases for an ObjectPattern which // destructures `this.state`. function handleStateDestructuring(node) { - for (const prop of node.properties) { + node.properties.forEach((prop) => { if (prop.type === 'Property') { addUsedStateField(prop.key); } else if ( @@ -183,7 +183,7 @@ module.exports = { ) { classInfo.aliases.add(getName(prop.argument)); } - } + }); } // Used to record used state fields and new aliases for both @@ -201,7 +201,7 @@ module.exports = { if (isStateReference(unwrappedRight)) { handleStateDestructuring(left); } else if (isThisExpression(unwrappedRight) && classInfo.aliases) { - for (const prop of left.properties) { + left.properties.forEach((prop) => { if (prop.type === 'Property' && getName(prop.key) === 'state') { const name = getName(prop.value); if (name) { @@ -210,7 +210,7 @@ module.exports = { handleStateDestructuring(prop.value); } } - } + }); } break; default: @@ -220,7 +220,7 @@ module.exports = { function reportUnusedFields() { // Report all unused state fields. - for (const node of classInfo.stateFields) { + classInfo.stateFields.forEach((node) => { const name = getName(node.key); if (!classInfo.usedStateFields.has(name)) { report(context, messages.unusedStateField, 'unusedStateField', { @@ -230,7 +230,7 @@ module.exports = { }, }); } - } + }); } function handleES6ComponentEnter(node) { From a90aa6a139a733823b5add828731211f5dd88416 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Jul 2024 15:30:36 -0700 Subject: [PATCH 02/14] [Refactor] `jsx-no-literals`: avoid unnecessary `arguments` usage --- lib/rules/jsx-no-literals.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/rules/jsx-no-literals.js b/lib/rules/jsx-no-literals.js index d7f43ab05c..8280eade5b 100644 --- a/lib/rules/jsx-no-literals.js +++ b/lib/rules/jsx-no-literals.js @@ -74,8 +74,7 @@ module.exports = { const config = Object.assign({}, defaults, context.options[0] || {}); config.allowedStrings = new Set(map(iterFrom(config.allowedStrings), trimIfString)); - function defaultMessageId() { - const ancestorIsJSXElement = arguments.length >= 1 && arguments[0]; + function defaultMessageId(ancestorIsJSXElement) { if (config.noAttributeStrings && !ancestorIsJSXElement) { return 'noStringsInAttributes'; } From 6421386be00081941e4d6d6afe28cb2bfb85dd6a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Jul 2024 15:33:26 -0700 Subject: [PATCH 03/14] [Refactor] use `!!` over `Boolean()` --- lib/rules/no-direct-mutation-state.js | 2 +- lib/rules/no-set-state.js | 2 +- lib/rules/no-unused-prop-types.js | 5 +---- lib/rules/require-optimization.js | 9 +++------ lib/rules/sort-prop-types.js | 7 +++++-- lib/util/propTypes.js | 2 +- lib/util/propTypesSort.js | 7 +++++-- tests/index.js | 6 +++--- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/rules/no-direct-mutation-state.js b/lib/rules/no-direct-mutation-state.js index 3df0998c6e..ef9cba77f0 100644 --- a/lib/rules/no-direct-mutation-state.js +++ b/lib/rules/no-direct-mutation-state.js @@ -41,7 +41,7 @@ module.exports = { * @returns {Boolean} True if the component is valid, false if not. */ function isValid(component) { - return Boolean(component && !component.mutateSetState); + return !!component && !component.mutateSetState; } /** diff --git a/lib/rules/no-set-state.js b/lib/rules/no-set-state.js index 199e922b75..78244c38d8 100644 --- a/lib/rules/no-set-state.js +++ b/lib/rules/no-set-state.js @@ -41,7 +41,7 @@ module.exports = { * @returns {Boolean} True if the component is valid, false if not. */ function isValid(component) { - return Boolean(component && !component.useSetState); + return !!component && !component.useSetState; } /** diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index f72188201a..6da1b3d68f 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -77,10 +77,7 @@ module.exports = { * @returns {Boolean} True if the component must be validated, false if not. */ function mustBeValidated(component) { - return Boolean( - component - && !component.ignoreUnusedPropTypesValidation - ); + return !!component && !component.ignoreUnusedPropTypesValidation; } /** diff --git a/lib/rules/require-optimization.js b/lib/rules/require-optimization.js index dc0b60f73a..a58c47a191 100644 --- a/lib/rules/require-optimization.js +++ b/lib/rules/require-optimization.js @@ -104,10 +104,7 @@ module.exports = { * @returns {Boolean} True if we are declaring a shouldComponentUpdate method, false if not. */ function isSCUDeclared(node) { - return Boolean( - node - && node.name === 'shouldComponentUpdate' - ); + return !!node && node.name === 'shouldComponentUpdate'; } /** @@ -126,8 +123,8 @@ module.exports = { } } - return Boolean( - node + return ( + !!node && node.key.name === 'mixins' && hasPR ); diff --git a/lib/rules/sort-prop-types.js b/lib/rules/sort-prop-types.js index b0087e59c2..a522d37f61 100644 --- a/lib/rules/sort-prop-types.js +++ b/lib/rules/sort-prop-types.js @@ -48,8 +48,11 @@ function isRequiredProp(node) { } function isShapeProp(node) { - return Boolean( - node && node.callee && node.callee.property && node.callee.property.name === 'shape' + return !!( + node + && node.callee + && node.callee.property + && node.callee.property.name === 'shape' ); } diff --git a/lib/util/propTypes.js b/lib/util/propTypes.js index 9450f9222f..9525989bd8 100644 --- a/lib/util/propTypes.js +++ b/lib/util/propTypes.js @@ -172,7 +172,7 @@ module.exports = function propTypesInstructions(context, components, utils) { ObjectTypeAnnotation(annotation, parentName, seen) { let containsUnresolvedObjectTypeSpread = false; let containsSpread = false; - const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length); + const containsIndexers = !!annotation.indexers && annotation.indexers.length > 0; const shapeTypeDefinition = { type: 'shape', children: {}, diff --git a/lib/util/propTypesSort.js b/lib/util/propTypesSort.js index bffcfb1073..ef5dd67f41 100644 --- a/lib/util/propTypesSort.js +++ b/lib/util/propTypesSort.js @@ -49,8 +49,11 @@ function isCallbackPropName(propName) { * @returns {Boolean} true if the prop is PropTypes.shape. */ function isShapeProp(node) { - return Boolean( - node && node.callee && node.callee.property && node.callee.property.name === 'shape' + return !!( + node + && node.callee + && node.callee.property + && node.callee.property.name === 'shape' ); } diff --git a/tests/index.js b/tests/index.js index 258429517b..9f7a052943 100644 --- a/tests/index.js +++ b/tests/index.js @@ -34,7 +34,7 @@ describe('all rule files should be exported by the plugin', () => { describe('deprecated rules', () => { it('marks all deprecated rules as deprecated', () => { ruleFiles.forEach((ruleName) => { - const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]); + const inDeprecatedRules = !!plugin.deprecatedRules[ruleName]; const isDeprecated = plugin.rules[ruleName].meta.deprecated; if (inDeprecatedRules) { assert(isDeprecated, `${ruleName} metadata should mark it as deprecated`); @@ -77,7 +77,7 @@ describe('configurations', () => { }); ruleFiles.forEach((ruleName) => { - const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]); + const inDeprecatedRules = !!plugin.deprecatedRules[ruleName]; const inConfig = typeof plugin.configs[configName].rules[`react/${ruleName}`] !== 'undefined'; assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise }); @@ -91,7 +91,7 @@ describe('configurations', () => { assert.ok(ruleName.startsWith('react/')); assert.equal(plugin.configs[configName].rules[ruleName], 0); - const inDeprecatedRules = Boolean(plugin.deprecatedRules[ruleName]); + const inDeprecatedRules = !!plugin.deprecatedRules[ruleName]; const inConfig = typeof plugin.configs[configName].rules[ruleName] !== 'undefined'; assert(inDeprecatedRules ^ inConfig); // eslint-disable-line no-bitwise }); From 1b4037f9078fe27bf752cf13d2295404212bd4b9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 22 Jul 2024 15:35:53 -0700 Subject: [PATCH 04/14] [Refactor] `jsx-sort-props`, `sort-prop-types`: consolidate helpers: `isShapeProp`, `isCallbackPropName`, `isRequiredProp` --- lib/rules/jsx-sort-props.js | 13 +++++------- lib/rules/sort-prop-types.js | 39 +++++++----------------------------- lib/util/propTypesSort.js | 3 +++ 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js index f811e16cf7..4c138e9f69 100644 --- a/lib/rules/jsx-sort-props.js +++ b/lib/rules/jsx-sort-props.js @@ -12,6 +12,7 @@ const toSorted = require('array.prototype.tosorted'); const docsUrl = require('../util/docsUrl'); const jsxUtil = require('../util/jsx'); const report = require('../util/report'); +const propTypesSortUtil = require('../util/propTypesSort'); const eslintUtil = require('../util/eslint'); const getText = eslintUtil.getText; @@ -21,10 +22,6 @@ const getSourceCode = eslintUtil.getSourceCode; // Rule Definition // ------------------------------------------------------------------------------ -function isCallbackPropName(name) { - return /^on[A-Z]/.test(name); -} - function isMultilineProp(node) { return node.loc.start.line !== node.loc.end.line; } @@ -85,8 +82,8 @@ function contextCompare(a, b, options) { } if (options.callbacksLast) { - const aIsCallback = isCallbackPropName(aProp); - const bIsCallback = isCallbackPropName(bProp); + const aIsCallback = propTypesSortUtil.isCallbackPropName(aProp); + const bIsCallback = propTypesSortUtil.isCallbackPropName(bProp); if (aIsCallback && !bIsCallback) { return 1; } @@ -425,8 +422,8 @@ module.exports = { let currentPropName = propName(decl); const previousValue = memo.value; const currentValue = decl.value; - const previousIsCallback = isCallbackPropName(previousPropName); - const currentIsCallback = isCallbackPropName(currentPropName); + const previousIsCallback = propTypesSortUtil.isCallbackPropName(previousPropName); + const currentIsCallback = propTypesSortUtil.isCallbackPropName(currentPropName); if (ignoreCase) { previousPropName = previousPropName.toLowerCase(); diff --git a/lib/rules/sort-prop-types.js b/lib/rules/sort-prop-types.js index a522d37f61..b7f3ec4ff5 100644 --- a/lib/rules/sort-prop-types.js +++ b/lib/rules/sort-prop-types.js @@ -35,31 +35,6 @@ function getKey(context, node) { return getText(context, node.key || node.argument); } -function getValueName(node) { - return node.type === 'Property' && node.value.property && node.value.property.name; -} - -function isCallbackPropName(propName) { - return /^on[A-Z]/.test(propName); -} - -function isRequiredProp(node) { - return getValueName(node) === 'isRequired'; -} - -function isShapeProp(node) { - return !!( - node - && node.callee - && node.callee.property - && node.callee.property.name === 'shape' - ); -} - -function toLowerCase(item) { - return String(item).toLowerCase(); -} - /** @type {import('eslint').Rule.RuleModule} */ module.exports = { meta: { @@ -148,14 +123,14 @@ module.exports = { let prevPropName = getKey(context, prev); let currentPropName = getKey(context, curr); - const previousIsRequired = isRequiredProp(prev); - const currentIsRequired = isRequiredProp(curr); - const previousIsCallback = isCallbackPropName(prevPropName); - const currentIsCallback = isCallbackPropName(currentPropName); + const previousIsRequired = propTypesSortUtil.isRequiredProp(prev); + const currentIsRequired = propTypesSortUtil.isRequiredProp(curr); + const previousIsCallback = propTypesSortUtil.isCallbackPropName(prevPropName); + const currentIsCallback = propTypesSortUtil.isCallbackPropName(currentPropName); if (ignoreCase) { - prevPropName = toLowerCase(prevPropName); - currentPropName = toLowerCase(currentPropName); + prevPropName = String(prevPropName).toLowerCase(); + currentPropName = String(currentPropName).toLowerCase(); } if (requiredFirst) { @@ -263,7 +238,7 @@ module.exports = { return Object.assign({ CallExpression(node) { - if (!sortShapeProp || !isShapeProp(node) || !(node.arguments && node.arguments[0])) { + if (!sortShapeProp || !propTypesSortUtil.isShapeProp(node) || !(node.arguments && node.arguments[0])) { return; } diff --git a/lib/util/propTypesSort.js b/lib/util/propTypesSort.js index ef5dd67f41..21898a490c 100644 --- a/lib/util/propTypesSort.js +++ b/lib/util/propTypesSort.js @@ -223,4 +223,7 @@ function fixPropTypesSort( module.exports = { fixPropTypesSort, + isCallbackPropName, + isRequiredProp, + isShapeProp, }; From 983b88dd3cb5e07919517d3fde4085f60883ded7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 24 Jul 2024 15:26:33 -0700 Subject: [PATCH 05/14] [Tests] `no-array-index-key`: actually run valid tests --- tests/lib/rules/no-array-index-key.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tests/lib/rules/no-array-index-key.js b/tests/lib/rules/no-array-index-key.js index 5c2974f182..2269e208ca 100644 --- a/tests/lib/rules/no-array-index-key.js +++ b/tests/lib/rules/no-array-index-key.js @@ -27,7 +27,7 @@ const parserOptions = { const ruleTester = new RuleTester({ parserOptions }); ruleTester.run('no-array-index-key', rule, { - valid: parsers.all( + valid: parsers.all([ { code: ';' }, { code: ';' }, { code: ';' }, @@ -96,9 +96,6 @@ ruleTester.run('no-array-index-key', rule, { { code: 'foo.flatMap((a) => )', }, - { - code: 'foo.reduce((a, b) => a.concat(), [])', - }, { code: 'foo.reduce((a, b, i) => a.concat(), [])', }, @@ -139,8 +136,8 @@ ruleTester.run('no-array-index-key', rule, { { code: 'foo?.map(child => )', features: ['optional chaining'], - } - ), + }, + ]), invalid: parsers.all([].concat( { From 4d99f6ede46509daac13cefe8d271635fbc15690 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 29 Jul 2024 15:49:11 -0700 Subject: [PATCH 06/14] [Refactor] `display-name`: use `unwrapTSAsExpression` also add `isTSAsExpression` AST util --- lib/rules/display-name.js | 2 +- lib/util/ast.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/rules/display-name.js b/lib/rules/display-name.js index b4de069542..7108367ec2 100644 --- a/lib/rules/display-name.js +++ b/lib/rules/display-name.js @@ -198,7 +198,7 @@ module.exports = { if (!component) { return; } - markDisplayNameAsDeclared(component.node.type === 'TSAsExpression' ? component.node.expression : component.node); + markDisplayNameAsDeclared(astUtil.unwrapTSAsExpression(component.node)); }, 'FunctionExpression, FunctionDeclaration, ArrowFunctionExpression'(node) { diff --git a/lib/util/ast.js b/lib/util/ast.js index 5664dcb512..8d0ec3cad8 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -339,6 +339,10 @@ function isAssignmentLHS(node) { ); } +function isTSAsExpression(node) { + return node && node.type === 'TSAsExpression'; +} + /** * Extracts the expression node that is wrapped inside a TS type assertion * @@ -346,8 +350,7 @@ function isAssignmentLHS(node) { * @returns {ASTNode} - unwrapped expression node */ function unwrapTSAsExpression(node) { - if (node && node.type === 'TSAsExpression') return node.expression; - return node; + return isTSAsExpression(node) ? node.expression : node; } function isTSTypeReference(node) { @@ -450,6 +453,7 @@ module.exports = { isFunctionLike, inConstructor, isNodeFirstInLine, + isTSAsExpression, unwrapTSAsExpression, traverseReturns, isTSTypeReference, From e3927a30e14ea4c1591790da791d12e8e28e3880 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 29 Jul 2024 15:52:59 -0700 Subject: [PATCH 07/14] [Refactor] clean up some of the jsdocs --- lib/rules/boolean-prop-naming.js | 6 +-- lib/rules/display-name.js | 4 +- lib/rules/jsx-closing-bracket-location.js | 16 ++++---- lib/rules/jsx-indent-props.js | 8 ++-- lib/rules/jsx-indent.js | 24 +++++------ lib/rules/jsx-no-target-blank.js | 2 +- lib/rules/jsx-sort-default-props.js | 4 +- lib/rules/jsx-sort-props.js | 4 +- lib/rules/no-children-prop.js | 2 +- lib/rules/no-danger-with-children.js | 2 +- lib/rules/no-danger.js | 2 +- lib/rules/no-direct-mutation-state.js | 4 +- lib/rules/no-multi-comp.js | 2 +- .../no-redundant-should-component-update.js | 4 +- lib/rules/no-set-state.js | 2 +- lib/rules/no-string-refs.js | 8 ++-- lib/rules/no-unknown-property.js | 22 +++++----- lib/rules/no-unstable-nested-components.js | 40 +++++++++---------- lib/rules/no-unused-prop-types.js | 8 ++-- lib/rules/prefer-stateless-function.js | 2 +- lib/rules/prop-types.js | 12 +++--- lib/rules/require-optimization.js | 8 ++-- lib/rules/sort-comp.js | 2 +- lib/rules/sort-default-props.js | 4 +- lib/rules/static-property-placement.js | 2 +- lib/util/Components.js | 6 +-- lib/util/annotations.js | 2 +- lib/util/ast.js | 14 +++---- lib/util/error.js | 2 +- lib/util/isCreateContext.js | 2 +- lib/util/isFirstLetterCapitalized.js | 4 +- lib/util/jsx.js | 8 ++-- lib/util/log.js | 2 +- lib/util/propTypes.js | 18 ++++----- lib/util/propTypesSort.js | 32 +++++++-------- lib/util/props.js | 14 +++---- lib/util/usedPropTypes.js | 10 ++--- lib/util/variable.js | 2 +- 38 files changed, 155 insertions(+), 155 deletions(-) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index e6ea400025..fe55d52065 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -128,7 +128,7 @@ module.exports = { /** * Checks if prop is declared in flow way * @param {Object} prop Property object, single prop type declaration - * @returns {Boolean} + * @returns {boolean} */ function flowCheck(prop) { return ( @@ -141,7 +141,7 @@ module.exports = { /** * Checks if prop is declared in regular way * @param {Object} prop Property object, single prop type declaration - * @returns {Boolean} + * @returns {boolean} */ function regularCheck(prop) { const propKey = getPropKey(prop); @@ -165,7 +165,7 @@ module.exports = { /** * Checks if prop is nested * @param {Object} prop Property object, single prop type declaration - * @returns {Boolean} + * @returns {boolean} */ function nestedPropTypes(prop) { return ( diff --git a/lib/rules/display-name.js b/lib/rules/display-name.js index 7108367ec2..5e5b8b6980 100644 --- a/lib/rules/display-name.js +++ b/lib/rules/display-name.js @@ -73,7 +73,7 @@ module.exports = { /** * Checks if React.forwardRef is nested inside React.memo * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if React.forwardRef is nested inside React.memo, false if not. + * @returns {boolean} True if React.forwardRef is nested inside React.memo, false if not. */ function isNestedMemo(node) { const argumentIsCallExpression = node.arguments && node.arguments[0] && node.arguments[0].type === 'CallExpression'; @@ -111,7 +111,7 @@ module.exports = { /** * Checks if the component have a name set by the transpiler * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if component has a name, false if not. + * @returns {boolean} True if component has a name, false if not. */ function hasTranspilerName(node) { const namedObjectAssignment = ( diff --git a/lib/rules/jsx-closing-bracket-location.js b/lib/rules/jsx-closing-bracket-location.js index 21f99ffc9c..f3286826b3 100644 --- a/lib/rules/jsx-closing-bracket-location.js +++ b/lib/rules/jsx-closing-bracket-location.js @@ -100,7 +100,7 @@ module.exports = { /** * Get expected location for the closing bracket * @param {Object} tokens Locations of the opening bracket, closing bracket and last prop - * @return {String} Expected location for the closing bracket + * @return {string} Expected location for the closing bracket */ function getExpectedLocation(tokens) { let location; @@ -121,7 +121,7 @@ module.exports = { * Get the correct 0-indexed column for the closing bracket, given the * expected location. * @param {Object} tokens Locations of the opening bracket, closing bracket and last prop - * @param {String} expectedLocation Expected location for the closing bracket + * @param {string} expectedLocation Expected location for the closing bracket * @return {?Number} The correct column for the closing bracket, or null */ function getCorrectColumn(tokens, expectedLocation) { @@ -140,8 +140,8 @@ module.exports = { /** * Check if the closing bracket is correctly located * @param {Object} tokens Locations of the opening bracket, closing bracket and last prop - * @param {String} expectedLocation Expected location for the closing bracket - * @return {Boolean} True if the closing bracket is correctly located, false if not + * @param {string} expectedLocation Expected location for the closing bracket + * @return {boolean} True if the closing bracket is correctly located, false if not */ function hasCorrectLocation(tokens, expectedLocation) { switch (expectedLocation) { @@ -163,9 +163,9 @@ module.exports = { /** * Get the characters used for indentation on the line to be matched * @param {Object} tokens Locations of the opening bracket, closing bracket and last prop - * @param {String} expectedLocation Expected location for the closing bracket - * @param {Number} [correctColumn] Expected column for the closing bracket. Default to 0 - * @return {String} The characters used for indentation + * @param {string} expectedLocation Expected location for the closing bracket + * @param {number} [correctColumn] Expected column for the closing bracket. Default to 0 + * @return {string} The characters used for indentation */ function getIndentation(tokens, expectedLocation, correctColumn) { const newColumn = correctColumn || 0; @@ -235,7 +235,7 @@ module.exports = { * Get an unique ID for a given JSXOpeningElement * * @param {ASTNode} node The AST node being checked. - * @returns {String} Unique ID (based on its range) + * @returns {string} Unique ID (based on its range) */ function getOpeningElementId(node) { return node.range.join(':'); diff --git a/lib/rules/jsx-indent-props.js b/lib/rules/jsx-indent-props.js index 10adb1b8d9..4e7c048511 100644 --- a/lib/rules/jsx-indent-props.js +++ b/lib/rules/jsx-indent-props.js @@ -116,8 +116,8 @@ module.exports = { /** * Reports a given indent violation and properly pluralizes the message * @param {ASTNode} node Node violating the indent rule - * @param {Number} needed Expected indentation character count - * @param {Number} gotten Indentation character count in the actual node/code + * @param {number} needed Expected indentation character count + * @param {number} gotten Indentation character count in the actual node/code */ function report(node, needed, gotten) { const msgContext = { @@ -141,7 +141,7 @@ module.exports = { /** * Get node indent * @param {ASTNode} node Node to examine - * @return {Number} Indent + * @return {number} Indent */ function getNodeIndent(node) { let src = getText(context, node, node.loc.start.column + extraColumnStart); @@ -173,7 +173,7 @@ module.exports = { /** * Check indent for nodes list * @param {ASTNode[]} nodes list of node objects - * @param {Number} indent needed indent + * @param {number} indent needed indent */ function checkNodesIndent(nodes, indent) { let nestedIndent = indent; diff --git a/lib/rules/jsx-indent.js b/lib/rules/jsx-indent.js index 0bfd0507dd..243a17b485 100644 --- a/lib/rules/jsx-indent.js +++ b/lib/rules/jsx-indent.js @@ -105,7 +105,7 @@ module.exports = { /** * Responsible for fixing the indentation issue fix * @param {ASTNode} node Node violating the indent rule - * @param {Number} needed Expected indentation character count + * @param {number} needed Expected indentation character count * @returns {Function} function to be executed by the fixer * @private */ @@ -146,8 +146,8 @@ module.exports = { /** * Reports a given indent violation and properly pluralizes the message * @param {ASTNode} node Node violating the indent rule - * @param {Number} needed Expected indentation character count - * @param {Number} gotten Indentation character count in the actual node/code + * @param {number} needed Expected indentation character count + * @param {number} gotten Indentation character count in the actual node/code * @param {Object} [loc] Error line and column location */ function report(node, needed, gotten, loc) { @@ -168,9 +168,9 @@ module.exports = { /** * Get node indent * @param {ASTNode} node Node to examine - * @param {Boolean} [byLastLine] get indent of node's last line - * @param {Boolean} [excludeCommas] skip comma on start of line - * @return {Number} Indent + * @param {boolean} [byLastLine] get indent of node's last line + * @param {boolean} [excludeCommas] skip comma on start of line + * @return {number} Indent */ function getNodeIndent(node, byLastLine, excludeCommas) { let src = getText(context, node, node.loc.start.column + extraColumnStart); @@ -197,7 +197,7 @@ module.exports = { /** * Check if the node is the right member of a logical expression * @param {ASTNode} node The node to check - * @return {Boolean} true if its the case, false if not + * @return {boolean} true if its the case, false if not */ function isRightInLogicalExp(node) { return ( @@ -212,7 +212,7 @@ module.exports = { /** * Check if the node is the alternate member of a conditional expression * @param {ASTNode} node The node to check - * @return {Boolean} true if its the case, false if not + * @return {boolean} true if its the case, false if not */ function isAlternateInConditionalExp(node) { return ( @@ -227,7 +227,7 @@ module.exports = { /** * Check if the node is within a DoExpression block but not the first expression (which need to be indented) * @param {ASTNode} node The node to check - * @return {Boolean} true if its the case, false if not + * @return {boolean} true if its the case, false if not */ function isSecondOrSubsequentExpWithinDoExp(node) { /* @@ -298,8 +298,8 @@ module.exports = { /** * Check indent for nodes list * @param {ASTNode} node The node to check - * @param {Number} indent needed indent - * @param {Boolean} [excludeCommas] skip comma on start of line + * @param {number} indent needed indent + * @param {boolean} [excludeCommas] skip comma on start of line */ function checkNodesIndent(node, indent, excludeCommas) { const nodeIndent = getNodeIndent(node, false, excludeCommas); @@ -318,7 +318,7 @@ module.exports = { /** * Check indent for Literal Node or JSXText Node * @param {ASTNode} node The node to check - * @param {Number} indent needed indent + * @param {number} indent needed indent */ function checkLiteralNodeIndent(node, indent) { const value = node.value; diff --git a/lib/rules/jsx-no-target-blank.js b/lib/rules/jsx-no-target-blank.js index 4ad12a464f..9f5d239d6c 100644 --- a/lib/rules/jsx-no-target-blank.js +++ b/lib/rules/jsx-no-target-blank.js @@ -70,7 +70,7 @@ function hasDynamicLink(node, linkAttributes) { * Get the string(s) from a value * @param {ASTNode} value The AST node being checked. * @param {ASTNode} targetValue The AST node being checked. - * @returns {String | String[] | null} The string value, or null if not a string. + * @returns {string | string[] | null} The string value, or null if not a string. */ function getStringFromValue(value, targetValue) { if (value) { diff --git a/lib/rules/jsx-sort-default-props.js b/lib/rules/jsx-sort-default-props.js index 379d80677c..0de8f221c3 100644 --- a/lib/rules/jsx-sort-default-props.js +++ b/lib/rules/jsx-sort-default-props.js @@ -57,7 +57,7 @@ module.exports = { /** * Get properties name * @param {Object} node - Property. - * @returns {String} Property name. + * @returns {string} Property name. */ function getPropertyName(node) { if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) { @@ -78,7 +78,7 @@ module.exports = { /** * Checks if the Identifier node passed in looks like a defaultProps declaration. * @param {ASTNode} node The node to check. Must be an Identifier node. - * @returns {Boolean} `true` if the node is a defaultProps declaration, `false` if not + * @returns {boolean} `true` if the node is a defaultProps declaration, `false` if not */ function isDefaultPropsDeclaration(node) { const propName = getPropertyName(node); diff --git a/lib/rules/jsx-sort-props.js b/lib/rules/jsx-sort-props.js index 4c138e9f69..ec9d869b74 100644 --- a/lib/rules/jsx-sort-props.js +++ b/lib/rules/jsx-sort-props.js @@ -276,8 +276,8 @@ function generateFixerFunction(node, context, reservedList) { /** * Checks if the `reservedFirst` option is valid * @param {Object} context The context of the rule - * @param {Boolean|Array} reservedFirst The `reservedFirst` option - * @return {Function|undefined} If an error is detected, a function to generate the error message, otherwise, `undefined` + * @param {boolean | string[]} reservedFirst The `reservedFirst` option + * @return {Function | undefined} If an error is detected, a function to generate the error message, otherwise, `undefined` */ // eslint-disable-next-line consistent-return function validateReservedFirstConfig(context, reservedFirst) { diff --git a/lib/rules/no-children-prop.js b/lib/rules/no-children-prop.js index 508488e4d9..3ccaf53729 100644 --- a/lib/rules/no-children-prop.js +++ b/lib/rules/no-children-prop.js @@ -17,7 +17,7 @@ const report = require('../util/report'); * Checks if the node is a createElement call with a props literal. * @param {ASTNode} node - The AST node being checked. * @param {Context} context - The AST node being checked. - * @returns {Boolean} - True if node is a createElement call with a props + * @returns {boolean} - True if node is a createElement call with a props * object literal, False if not. */ function isCreateElementWithProps(node, context) { diff --git a/lib/rules/no-danger-with-children.js b/lib/rules/no-danger-with-children.js index 9f07d0c535..edf5073a71 100644 --- a/lib/rules/no-danger-with-children.js +++ b/lib/rules/no-danger-with-children.js @@ -85,7 +85,7 @@ module.exports = { /** * Checks to see if a node is a line break * @param {ASTNode} node The AST node being checked - * @returns {Boolean} True if node is a line break, false if not + * @returns {boolean} True if node is a line break, false if not */ function isLineBreak(node) { const isLiteral = node.type === 'Literal' || node.type === 'JSXText'; diff --git a/lib/rules/no-danger.js b/lib/rules/no-danger.js index be5c961e61..fb70263208 100644 --- a/lib/rules/no-danger.js +++ b/lib/rules/no-danger.js @@ -29,7 +29,7 @@ const DANGEROUS_PROPERTIES = fromEntries(DANGEROUS_PROPERTY_NAMES.map((prop) => /** * Checks if a JSX attribute is dangerous. - * @param {String} name - Name of the attribute to check. + * @param {string} name - Name of the attribute to check. * @returns {boolean} Whether or not the attribute is dangerous. */ function isDangerous(name) { diff --git a/lib/rules/no-direct-mutation-state.js b/lib/rules/no-direct-mutation-state.js index ef9cba77f0..761151fbb8 100644 --- a/lib/rules/no-direct-mutation-state.js +++ b/lib/rules/no-direct-mutation-state.js @@ -38,7 +38,7 @@ module.exports = { /** * Checks if the component is valid * @param {Object} component The component to process - * @returns {Boolean} True if the component is valid, false if not. + * @returns {boolean} True if the component is valid, false if not. */ function isValid(component) { return !!component && !component.mutateSetState; @@ -73,7 +73,7 @@ module.exports = { /** * Determine if we should currently ignore assignments in this component. * @param {?Object} component The component to process - * @returns {Boolean} True if we should skip assignment checks. + * @returns {boolean} True if we should skip assignment checks. */ function shouldIgnoreComponent(component) { return !component || (component.inConstructor && !component.inCallExpression); diff --git a/lib/rules/no-multi-comp.js b/lib/rules/no-multi-comp.js index 76b3fa0af7..8cf73c90bc 100644 --- a/lib/rules/no-multi-comp.js +++ b/lib/rules/no-multi-comp.js @@ -50,7 +50,7 @@ module.exports = { /** * Checks if the component is ignored * @param {Object} component The component being checked. - * @returns {Boolean} True if the component is ignored, false if not. + * @returns {boolean} True if the component is ignored, false if not. */ function isIgnored(component) { return ( diff --git a/lib/rules/no-redundant-should-component-update.js b/lib/rules/no-redundant-should-component-update.js index 849191d176..e7a439d8e8 100644 --- a/lib/rules/no-redundant-should-component-update.js +++ b/lib/rules/no-redundant-should-component-update.js @@ -36,7 +36,7 @@ module.exports = { /** * Checks for shouldComponentUpdate property * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} Whether or not the property exists. + * @returns {boolean} Whether or not the property exists. */ function hasShouldComponentUpdate(node) { const properties = astUtil.getComponentProperties(node); @@ -49,7 +49,7 @@ module.exports = { /** * Get name of node if available * @param {ASTNode} node The AST node being checked. - * @return {String} The name of the node + * @return {string} The name of the node */ function getNodeName(node) { if (node.id) { diff --git a/lib/rules/no-set-state.js b/lib/rules/no-set-state.js index 78244c38d8..0866552141 100644 --- a/lib/rules/no-set-state.js +++ b/lib/rules/no-set-state.js @@ -38,7 +38,7 @@ module.exports = { /** * Checks if the component is valid * @param {Object} component The component to process - * @returns {Boolean} True if the component is valid, false if not. + * @returns {boolean} True if the component is valid, false if not. */ function isValid(component) { return !!component && !component.useSetState; diff --git a/lib/rules/no-string-refs.js b/lib/rules/no-string-refs.js index 09ce286685..c5c3b29166 100644 --- a/lib/rules/no-string-refs.js +++ b/lib/rules/no-string-refs.js @@ -46,7 +46,7 @@ module.exports = { /** * Checks if we are using refs * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if we are using refs, false if not. + * @returns {boolean} True if we are using refs, false if not. */ function isRefsUsage(node) { return !!( @@ -59,7 +59,7 @@ module.exports = { /** * Checks if we are using a ref attribute * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if we are using a ref attribute, false if not. + * @returns {boolean} True if we are using a ref attribute, false if not. */ function isRefAttribute(node) { return !!( @@ -72,7 +72,7 @@ module.exports = { /** * Checks if a node contains a string value * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if the node contains a string value, false if not. + * @returns {boolean} True if the node contains a string value, false if not. */ function containsStringLiteral(node) { return !!( @@ -85,7 +85,7 @@ module.exports = { /** * Checks if a node contains a string value within a jsx expression * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if the node contains a string value within a jsx expression, false if not. + * @returns {boolean} True if the node contains a string value within a jsx expression, false if not. */ function containsStringExpressionContainer(node) { return !!( diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 674e93071f..61ca8ad809 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -415,8 +415,8 @@ function isValidHTMLTagInJSX(childNode) { * * Note - these exclusions are not made by React core team, but `eslint-plugin-react` community. * - * @param {String} name - Attribute name to be normalized - * @returns {String} Result + * @param {string} name - Attribute name to be normalized + * @returns {string} Result */ function normalizeAttributeCase(name) { return DOM_PROPERTIES_IGNORE_CASE.find((element) => element.toLowerCase() === name.toLowerCase()) || name; @@ -428,7 +428,7 @@ function normalizeAttributeCase(name) { * not start with any casing of "xml", and separated by hyphens (-) (which is also called "kebab case" or "dash case"), * then the attribute is a valid data attribute. * - * @param {String} name - Attribute name to be tested + * @param {string} name - Attribute name to be tested * @returns {boolean} Result */ function isValidDataAttribute(name) { @@ -438,7 +438,7 @@ function isValidDataAttribute(name) { /** * Checks if an attribute name has at least one uppercase characters * - * @param {String} name + * @param {string} name * @returns {boolean} Result */ function hasUpperCaseCharacter(name) { @@ -449,8 +449,8 @@ function hasUpperCaseCharacter(name) { * Checks if an attribute name is a standard aria attribute by compering it to a list * of standard aria property names * - * @param {String} name - Attribute name to be tested - * @returns {Boolean} Result + * @param {string} name - Attribute name to be tested + * @returns {boolean} Result */ function isValidAriaAttribute(name) { @@ -460,7 +460,7 @@ function isValidAriaAttribute(name) { /** * Extracts the tag name for the JSXAttribute * @param {JSXAttribute} node - JSXAttribute being tested. - * @returns {String|null} tag name + * @returns {string | null} tag name */ function getTagName(node) { if (node && node.parent && node.parent.name && node.parent.name) { @@ -473,7 +473,7 @@ function getTagName(node) { * Test wether the tag name for the JSXAttribute is * something like * @param {JSXAttribute} node - JSXAttribute being tested. - * @returns {Boolean} result + * @returns {boolean} result */ function tagNameHasDot(node) { return !!( @@ -485,9 +485,9 @@ function tagNameHasDot(node) { /** * Get the standard name of the attribute. - * @param {String} name - Name of the attribute. - * @param {String} context - eslint context - * @returns {String | undefined} The standard name of the attribute, or undefined if no standard name was found. + * @param {string} name - Name of the attribute. + * @param {string} context - eslint context + * @returns {string | undefined} The standard name of the attribute, or undefined if no standard name was found. */ function getStandardName(name, context) { if (has(DOM_ATTRIBUTE_NAMES, name)) { diff --git a/lib/rules/no-unstable-nested-components.js b/lib/rules/no-unstable-nested-components.js index c1dd606b6a..909d8110e7 100644 --- a/lib/rules/no-unstable-nested-components.js +++ b/lib/rules/no-unstable-nested-components.js @@ -23,8 +23,8 @@ const HOOK_REGEXP = /^use[A-Z0-9].*$/; /** * Generate error message with given parent component name - * @param {String} parentName Name of the parent component, if known - * @returns {String} Error message with parent component name + * @param {string} parentName Name of the parent component, if known + * @returns {string} Error message with parent component name */ function generateErrorMessageWithParentName(parentName) { return `Do not define components during render. React will see a new component type on every render and destroy the entire subtree’s DOM nodes and state (https://reactjs.org/docs/reconciliation.html#elements-of-different-types). Instead, move this component definition out of the parent component${parentName ? ` “${parentName}” ` : ' '}and pass data as props.`; @@ -32,8 +32,8 @@ function generateErrorMessageWithParentName(parentName) { /** * Check whether given text starts with `render`. Comparison is case-sensitive. - * @param {String} text Text to validate - * @returns {Boolean} + * @param {string} text Text to validate + * @returns {boolean} */ function startsWithRender(text) { return (text || '').startsWith('render'); @@ -62,7 +62,7 @@ function getClosestMatchingParent(node, context, matcher) { * Matcher used to check whether given node is a `createElement` call * @param {ASTNode} node The AST node * @param {Context} context eslint context - * @returns {Boolean} True if node is a `createElement` call, false if not + * @returns {boolean} True if node is a `createElement` call, false if not */ function isCreateElementMatcher(node, context) { return ( @@ -75,7 +75,7 @@ function isCreateElementMatcher(node, context) { /** * Matcher used to check whether given node is a `ObjectExpression` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is a `ObjectExpression`, false if not + * @returns {boolean} True if node is a `ObjectExpression`, false if not */ function isObjectExpressionMatcher(node) { return node && node.type === 'ObjectExpression'; @@ -84,7 +84,7 @@ function isObjectExpressionMatcher(node) { /** * Matcher used to check whether given node is a `JSXExpressionContainer` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is a `JSXExpressionContainer`, false if not + * @returns {boolean} True if node is a `JSXExpressionContainer`, false if not */ function isJSXExpressionContainerMatcher(node) { return node && node.type === 'JSXExpressionContainer'; @@ -93,7 +93,7 @@ function isJSXExpressionContainerMatcher(node) { /** * Matcher used to check whether given node is a `JSXAttribute` of `JSXExpressionContainer` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is a `JSXAttribute` of `JSXExpressionContainer`, false if not + * @returns {boolean} True if node is a `JSXAttribute` of `JSXExpressionContainer`, false if not */ function isJSXAttributeOfExpressionContainerMatcher(node) { return ( @@ -107,7 +107,7 @@ function isJSXAttributeOfExpressionContainerMatcher(node) { /** * Matcher used to check whether given node is an object `Property` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is a `Property`, false if not + * @returns {boolean} True if node is a `Property`, false if not */ function isPropertyOfObjectExpressionMatcher(node) { return ( @@ -120,7 +120,7 @@ function isPropertyOfObjectExpressionMatcher(node) { /** * Matcher used to check whether given node is a `CallExpression` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is a `CallExpression`, false if not + * @returns {boolean} True if node is a `CallExpression`, false if not */ function isCallExpressionMatcher(node) { return node && node.type === 'CallExpression'; @@ -132,7 +132,7 @@ function isCallExpressionMatcher(node) { * {items.map(item =>
  • )} * ``` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is directly inside `map` call, false if not + * @returns {boolean} True if node is directly inside `map` call, false if not */ function isMapCall(node) { return ( @@ -147,7 +147,7 @@ function isMapCall(node) { * Check whether given node is `ReturnStatement` of a React hook * @param {ASTNode} node The AST node * @param {Context} context eslint context - * @returns {Boolean} True if node is a `ReturnStatement` of a React hook, false if not + * @returns {boolean} True if node is a `ReturnStatement` of a React hook, false if not */ function isReturnStatementOfHook(node, context) { if ( @@ -174,7 +174,7 @@ function isReturnStatementOfHook(node, context) { * ``` * @param {ASTNode} node The AST node * @param {Context} context eslint context - * @returns {Boolean} True if component is declared inside a render prop, false if not + * @returns {boolean} True if component is declared inside a render prop, false if not */ function isComponentInRenderProp(node, context) { if ( @@ -231,7 +231,7 @@ function isComponentInRenderProp(node, context) { *
    }] } /> * ``` * @param {ASTNode} node The AST node - * @returns {Boolean} True if component is declared inside a render property, false if not + * @returns {boolean} True if component is declared inside a render property, false if not */ function isDirectValueOfRenderProperty(node) { return ( @@ -247,7 +247,7 @@ function isDirectValueOfRenderProperty(node) { /** * Resolve the component name of given node * @param {ASTNode} node The AST node of the component - * @returns {String} Name of the component, if any + * @returns {string} Name of the component, if any */ function resolveComponentName(node) { const parentName = node.id && node.id.name; @@ -303,7 +303,7 @@ module.exports = { * ... * ``` * @param {ASTNode} node The AST node being checked - * @returns {Boolean} True if node is inside class component's render block, false if not + * @returns {boolean} True if node is inside class component's render block, false if not */ function isInsideRenderMethod(node) { const parentComponent = utils.getParentComponent(node); @@ -331,7 +331,7 @@ module.exports = { * ... * ``` * @param {ASTNode} node The AST node being checked - * @returns {Boolean} True if given node a function component declared inside class component, false if not + * @returns {boolean} True if given node a function component declared inside class component, false if not */ function isFunctionComponentInsideClassComponent(node) { const parentComponent = utils.getParentComponent(node); @@ -354,7 +354,7 @@ module.exports = { * }) * ``` * @param {ASTNode} node The AST node - * @returns {Boolean} True if node is declare inside `createElement` call's props, false if not + * @returns {boolean} True if node is declare inside `createElement` call's props, false if not */ function isComponentInsideCreateElementsProp(node) { if (!components.get(node)) { @@ -377,7 +377,7 @@ module.exports = { * { footer: () =>
    } * ``` * @param {ASTNode} node The AST node being checked - * @returns {Boolean} True if node is a component declared inside prop, false if not + * @returns {boolean} True if node is a component declared inside prop, false if not */ function isComponentInProp(node) { if (isPropertyOfObjectExpressionMatcher(node)) { @@ -399,7 +399,7 @@ module.exports = { * {{ a: () => null }} * ``` * @param {ASTNode} node The AST node being checked - * @returns {Boolean} True if node is a stateless component returning non-JSX, false if not + * @returns {boolean} True if node is a stateless component returning non-JSX, false if not */ function isStatelessComponentReturningNull(node) { const component = utils.getStatelessComponent(node); diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index 6da1b3d68f..55a21881ff 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -64,8 +64,8 @@ module.exports = { /** * Checks if the prop is ignored - * @param {String} name Name of the prop to check. - * @returns {Boolean} True if the prop is ignored, false if not. + * @param {string} name Name of the prop to check. + * @returns {boolean} True if the prop is ignored, false if not. */ function isIgnored(name) { return configuration.ignore.indexOf(name) !== -1; @@ -74,7 +74,7 @@ module.exports = { /** * Checks if the component must be validated * @param {Object} component The component to process - * @returns {Boolean} True if the component must be validated, false if not. + * @returns {boolean} True if the component must be validated, false if not. */ function mustBeValidated(component) { return !!component && !component.ignoreUnusedPropTypesValidation; @@ -84,7 +84,7 @@ module.exports = { * Checks if a prop is used * @param {ASTNode} node The AST node being checked. * @param {Object} prop Declared prop object - * @returns {Boolean} True if the prop is used, false if not. + * @returns {boolean} True if the prop is used, false if not. */ function isPropUsed(node, prop) { const usedPropTypes = node.usedPropTypes || []; diff --git a/lib/rules/prefer-stateless-function.js b/lib/rules/prefer-stateless-function.js index bfbabe76be..8ba33a1a97 100644 --- a/lib/rules/prefer-stateless-function.js +++ b/lib/rules/prefer-stateless-function.js @@ -191,7 +191,7 @@ module.exports = { /** * Check if a given AST node have any other properties the ones available in stateless components * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if the node has at least one other property, false if not. + * @returns {boolean} True if the node has at least one other property, false if not. */ function hasOtherProperties(node) { const properties = astUtil.getComponentProperties(node); diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index eb6bab1c09..dabe5b0e7b 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -64,8 +64,8 @@ module.exports = { /** * Checks if the prop is ignored - * @param {String} name Name of the prop to check. - * @returns {Boolean} True if the prop is ignored, false if not. + * @param {string} name Name of the prop to check. + * @returns {boolean} True if the prop is ignored, false if not. */ function isIgnored(name) { return ignored.indexOf(name) !== -1; @@ -89,7 +89,7 @@ module.exports = { /** * Internal: Checks if the prop is declared * @param {Object} declaredPropTypes Description of propTypes declared in the current component - * @param {String[]} keyList Dot separated name of the prop to check. + * @param {string[]} keyList Dot separated name of the prop to check. * @returns {boolean} True if the prop is declared, false if not. */ function internalIsDeclaredInComponent(declaredPropTypes, keyList) { @@ -148,8 +148,8 @@ module.exports = { /** * Checks if the prop is declared * @param {ASTNode} node The AST node being checked. - * @param {String[]} names List of names of the prop to check. - * @returns {Boolean} True if the prop is declared, false if not. + * @param {string[]} names List of names of the prop to check. + * @returns {boolean} True if the prop is declared, false if not. */ function isDeclaredInComponent(node, names) { while (node) { @@ -190,7 +190,7 @@ module.exports = { /** * @param {Object} component The current component to process * @param {Array} list The all components to process - * @returns {Boolean} True if the component is nested False if not. + * @returns {boolean} True if the component is nested False if not. */ function checkNestedComponent(component, list) { const componentIsMemo = component.node.callee && component.node.callee.name === 'memo'; diff --git a/lib/rules/require-optimization.js b/lib/rules/require-optimization.js index a58c47a191..da6a7e0830 100644 --- a/lib/rules/require-optimization.js +++ b/lib/rules/require-optimization.js @@ -50,7 +50,7 @@ module.exports = { /** * Checks to see if our component is decorated by PureRenderMixin via reactMixin * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if node is decorated with a PureRenderMixin, false if not. + * @returns {boolean} True if node is decorated with a PureRenderMixin, false if not. */ function hasPureRenderDecorator(node) { if (node.decorators && node.decorators.length) { @@ -77,7 +77,7 @@ module.exports = { /** * Checks to see if our component is custom decorated * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if node is decorated name with a custom decorated, false if not. + * @returns {boolean} True if node is decorated name with a custom decorated, false if not. */ function hasCustomDecorator(node) { const allowLength = allowDecorators.length; @@ -101,7 +101,7 @@ module.exports = { /** * Checks if we are declaring a shouldComponentUpdate method * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if we are declaring a shouldComponentUpdate method, false if not. + * @returns {boolean} True if we are declaring a shouldComponentUpdate method, false if not. */ function isSCUDeclared(node) { return !!node && node.name === 'shouldComponentUpdate'; @@ -110,7 +110,7 @@ module.exports = { /** * Checks if we are declaring a PureRenderMixin mixin * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if we are declaring a PureRenderMixin method, false if not. + * @returns {boolean} True if we are declaring a PureRenderMixin method, false if not. */ function isPureRenderDeclared(node) { let hasPR = false; diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index e35574a682..ee409b780d 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -234,7 +234,7 @@ module.exports = { /** * Get properties name * @param {Object} node - Property. - * @returns {String} Property name. + * @returns {string} Property name. */ function getPropertyName(node) { if (node.kind === 'get') { diff --git a/lib/rules/sort-default-props.js b/lib/rules/sort-default-props.js index 2101307e00..50bd7ed53c 100644 --- a/lib/rules/sort-default-props.js +++ b/lib/rules/sort-default-props.js @@ -52,7 +52,7 @@ module.exports = { /** * Get properties name * @param {Object} node - Property. - * @returns {String} Property name. + * @returns {string} Property name. */ function getPropertyName(node) { if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) { @@ -73,7 +73,7 @@ module.exports = { /** * Checks if the Identifier node passed in looks like a defaultProps declaration. * @param {ASTNode} node The node to check. Must be an Identifier node. - * @returns {Boolean} `true` if the node is a defaultProps declaration, `false` if not + * @returns {boolean} `true` if the node is a defaultProps declaration, `false` if not */ function isDefaultPropsDeclaration(node) { const propName = getPropertyName(node); diff --git a/lib/rules/static-property-placement.js b/lib/rules/static-property-placement.js index 7baf2faeb4..ce38a8e42e 100644 --- a/lib/rules/static-property-placement.js +++ b/lib/rules/static-property-placement.js @@ -99,7 +99,7 @@ module.exports = { /** * Checks if we are declaring context in class * @param {ASTNode} node - * @returns {Boolean} True if we are declaring context in class, false if not. + * @returns {boolean} True if we are declaring context in class, false if not. */ function isContextInClass(node) { let blockNode; diff --git a/lib/util/Components.js b/lib/util/Components.js index 0ef615a133..6d9d9e5a9b 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -70,7 +70,7 @@ class Components { * Add a node to the components list, or update it if it's already in the list * * @param {ASTNode} node The AST node being added. - * @param {Number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes) + * @param {number} confidence Confidence in the component detection (0=banned, 1=maybe, 2=yes) * @returns {Object} Added component object */ add(node, confidence) { @@ -183,7 +183,7 @@ class Components { * Return the length of the components list * Components for which we are not confident are not counted * - * @returns {Number} Components list length + * @returns {number} Components list length */ length() { const list = Lists.get(this); @@ -751,7 +751,7 @@ function componentRule(rule, context) { * * @param {ASTNode} node The AST node being searched. (expects CallExpression) * @param {('useCallback'|'useContext'|'useDebugValue'|'useEffect'|'useImperativeHandle'|'useLayoutEffect'|'useMemo'|'useReducer'|'useRef'|'useState')[]} [expectedHookNames] React hook names to which search is limited. - * @returns {Boolean} True if the node is a call to a React hook + * @returns {boolean} True if the node is a call to a React hook */ isReactHookCall(node, expectedHookNames) { if (node.type !== 'CallExpression') { diff --git a/lib/util/annotations.js b/lib/util/annotations.js index 24b18074c0..2bc1437ff1 100644 --- a/lib/util/annotations.js +++ b/lib/util/annotations.js @@ -12,7 +12,7 @@ const getFirstTokens = require('./eslint').getFirstTokens; * Checks if we are declaring a `props` argument with a flow type annotation. * @param {ASTNode} node The AST node being checked. * @param {Object} context - * @returns {Boolean} True if the node is a type annotated props declaration, false if not. + * @returns {boolean} True if the node is a type annotated props declaration, false if not. */ function isAnnotatedFunctionPropsDeclaration(node, context) { if (!node || !node.params || !node.params.length) { diff --git a/lib/util/ast.js b/lib/util/ast.js index 8d0ec3cad8..9a11b7532f 100644 --- a/lib/util/ast.js +++ b/lib/util/ast.js @@ -160,7 +160,7 @@ function getPropertyNameNode(node) { /** * Get properties name * @param {Object} node - Property. - * @returns {String} Property name. + * @returns {string} Property name. */ function getPropertyName(node) { const nameNode = getPropertyNameNode(node); @@ -210,7 +210,7 @@ function getFirstNodeInLine(context, node) { * Checks if the node is the first in its line, excluding whitespace. * @param {Object} context The node to check * @param {ASTNode} node The node to check - * @return {Boolean} true if it's the first node in its line + * @return {boolean} true if it's the first node in its line */ function isNodeFirstInLine(context, node) { const token = getFirstNodeInLine(context, node); @@ -222,7 +222,7 @@ function isNodeFirstInLine(context, node) { /** * Checks if the node is a function or arrow function expression. * @param {ASTNode} node The node to check - * @return {Boolean} true if it's a function-like expression + * @return {boolean} true if it's a function-like expression */ function isFunctionLikeExpression(node) { return node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression'; @@ -231,7 +231,7 @@ function isFunctionLikeExpression(node) { /** * Checks if the node is a function. * @param {ASTNode} node The node to check - * @return {Boolean} true if it's a function + * @return {boolean} true if it's a function */ function isFunction(node) { return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration'; @@ -240,7 +240,7 @@ function isFunction(node) { /** * Checks if node is a function declaration or expression or arrow function. * @param {ASTNode} node The node to check - * @return {Boolean} true if it's a function-like + * @return {boolean} true if it's a function-like */ function isFunctionLike(node) { return node.type === 'FunctionDeclaration' || isFunctionLikeExpression(node); @@ -249,7 +249,7 @@ function isFunctionLike(node) { /** * Checks if the node is a class. * @param {ASTNode} node The node to check - * @return {Boolean} true if it's a class + * @return {boolean} true if it's a class */ function isClass(node) { return node.type === 'ClassDeclaration' || node.type === 'ClassExpression'; @@ -329,7 +329,7 @@ function isParenthesized(context, node) { /** * Checks if a node is being assigned a value: props.bar = 'bar' * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} + * @returns {boolean} */ function isAssignmentLHS(node) { return ( diff --git a/lib/util/error.js b/lib/util/error.js index bbfc3d6f09..cca6e6c13f 100644 --- a/lib/util/error.js +++ b/lib/util/error.js @@ -2,7 +2,7 @@ /** * Logs out a message if there is no format option set. - * @param {String} message - Message to log. + * @param {string} message - Message to log. */ function error(message) { if (!/=-(f|-format)=/.test(process.argv.join('='))) { diff --git a/lib/util/isCreateContext.js b/lib/util/isCreateContext.js index d5fdfe4551..858f463ccb 100644 --- a/lib/util/isCreateContext.js +++ b/lib/util/isCreateContext.js @@ -3,7 +3,7 @@ /** * Checks if the node is a React.createContext call * @param {ASTNode} node - The AST node being checked. - * @returns {Boolean} - True if node is a React.createContext call, false if not. + * @returns {boolean} - True if node is a React.createContext call, false if not. */ module.exports = function isCreateContext(node) { if ( diff --git a/lib/util/isFirstLetterCapitalized.js b/lib/util/isFirstLetterCapitalized.js index bc55a1970b..9bbce69c66 100644 --- a/lib/util/isFirstLetterCapitalized.js +++ b/lib/util/isFirstLetterCapitalized.js @@ -2,8 +2,8 @@ /** * Check if the first letter of a string is capitalized. - * @param {String} word String to check - * @returns {Boolean} True if first letter is capitalized. + * @param {string} word String to check + * @returns {boolean} True if first letter is capitalized. */ function isFirstLetterCapitalized(word) { if (!word) { diff --git a/lib/util/jsx.js b/lib/util/jsx.js index 07a09a8022..477dd36f5e 100644 --- a/lib/util/jsx.js +++ b/lib/util/jsx.js @@ -88,9 +88,9 @@ function isWhiteSpaces(value) { * * @param {Context} context The context of `ASTNode`. * @param {ASTNode} ASTnode The AST node being checked - * @param {Boolean} [strict] If true, in a ternary condition the node must return JSX in both cases - * @param {Boolean} [ignoreNull] If true, null return values will be ignored - * @returns {Boolean} True if the node is returning JSX or null, false if not + * @param {boolean} [strict] If true, in a ternary condition the node must return JSX in both cases + * @param {boolean} [ignoreNull] If true, null return values will be ignored + * @returns {boolean} True if the node is returning JSX or null, false if not */ function isReturningJSX(context, ASTnode, strict, ignoreNull) { const isJSXValue = (node) => { @@ -145,7 +145,7 @@ function isReturningJSX(context, ASTnode, strict, ignoreNull) { * * @param {ASTNode} ASTnode The AST node being checked * @param {Context} context The context of `ASTNode`. - * @returns {Boolean} True if the node is returning only null values + * @returns {boolean} True if the node is returning only null values */ function isReturningOnlyNull(ASTnode, context) { let found = false; diff --git a/lib/util/log.js b/lib/util/log.js index 9782b21990..55271e15f2 100644 --- a/lib/util/log.js +++ b/lib/util/log.js @@ -2,7 +2,7 @@ /** * Logs out a message if there is no format option set. - * @param {String} message - Message to log. + * @param {string} message - Message to log. */ function log(message) { if (!/=-(f|-format)=/.test(process.argv.join('='))) { diff --git a/lib/util/propTypes.js b/lib/util/propTypes.js index 9525989bd8..8322aab1ce 100644 --- a/lib/util/propTypes.js +++ b/lib/util/propTypes.js @@ -23,7 +23,7 @@ const getText = eslintUtil.getText; /** * Check if node is function type. * @param {ASTNode} node - * @returns {Boolean} + * @returns {boolean} */ function isFunctionType(node) { if (!node) return false; @@ -37,7 +37,7 @@ function isFunctionType(node) { * Checks if we are declaring a props as a generic type in a flow-annotated class. * * @param {ASTNode} node the AST node being checked. - * @returns {Boolean} True if the node is a class with generic prop types, false if not. + * @returns {boolean} True if the node is a class with generic prop types, false if not. */ function isSuperTypeParameterPropsDeclaration(node) { if (node && (node.type === 'ClassDeclaration' || node.type === 'ClassExpression')) { @@ -77,7 +77,7 @@ function iterateProperties(context, properties, fn, handleSpreadFn) { * Checks if a node is inside a class body. * * @param {ASTNode} node the AST node being checked. - * @returns {Boolean} True if the node has a ClassBody ancestor, false if not. + * @returns {boolean} True if the node has a ClassBody ancestor, false if not. */ function isInsideClassBody(node) { let parent = node.parent; @@ -152,8 +152,8 @@ module.exports = function propTypesInstructions(context, components, utils) { /** * Checks if prop should be validated by plugin-react-proptypes - * @param {String} validator Name of validator to check. - * @returns {Boolean} True if validator should be checked by custom validator. + * @param {string} validator Name of validator to check. + * @returns {boolean} True if validator should be checked by custom validator. */ function hasCustomValidator(validator) { return customValidators.indexOf(validator) !== -1; @@ -267,7 +267,7 @@ module.exports = function propTypesInstructions(context, components, utils) { * Creates the representation of the React props type annotation for the component. * The representation is used to verify nested used properties. * @param {ASTNode} annotation Type annotation for the props class property. - * @param {String} parentName + * @param {string} parentName * @param {Set} [seen] * @return {Object} The representation of the declaration, empty object means * the property is declared without the need for further analysis. @@ -296,7 +296,7 @@ module.exports = function propTypesInstructions(context, components, utils) { * Modifies the declaredProperties object * @param {ASTNode} propTypes * @param {Object} declaredPropTypes - * @returns {Boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported) + * @returns {boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported) */ function declarePropTypesForObjectTypeAnnotation(propTypes, declaredPropTypes) { let ignorePropsValidation = false; @@ -334,7 +334,7 @@ module.exports = function propTypesInstructions(context, components, utils) { * Modifies the declaredPropTypes object * @param {ASTNode} propTypes * @param {Object} declaredPropTypes - * @returns {Boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported) + * @returns {boolean} True if propTypes should be ignored (e.g. when a type can't be resolved, when it is imported) */ function declarePropTypesForIntersectionTypeAnnotation(propTypes, declaredPropTypes) { return propTypes.types.some((annotation) => { @@ -1135,7 +1135,7 @@ module.exports = function propTypesInstructions(context, components, utils) { /** * Checks if we are declaring a `props` class property with a flow type annotation. * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if the node is a type annotated props declaration, false if not. + * @returns {boolean} True if the node is a type annotated props declaration, false if not. */ function isAnnotatedClassPropsDeclaration(node) { if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) { diff --git a/lib/util/propTypesSort.js b/lib/util/propTypesSort.js index 21898a490c..a6bb2124b3 100644 --- a/lib/util/propTypesSort.js +++ b/lib/util/propTypesSort.js @@ -16,7 +16,7 @@ const getText = eslintUtil.getText; * Returns the value name of a node. * * @param {ASTNode} node the node to check. - * @returns {String} The name of the node. + * @returns {string} The name of the node. */ function getValueName(node) { return node.type === 'Property' && node.value.property && node.value.property.name; @@ -26,7 +26,7 @@ function getValueName(node) { * Checks if the prop is required or not. * * @param {ASTNode} node the prop to check. - * @returns {Boolean} true if the prop is required. + * @returns {boolean} true if the prop is required. */ function isRequiredProp(node) { return getValueName(node) === 'isRequired'; @@ -35,8 +35,8 @@ function isRequiredProp(node) { /** * Checks if the proptype is a callback by checking if it starts with 'on'. * - * @param {String} propName the name of the proptype to check. - * @returns {Boolean} true if the proptype is a callback. + * @param {string} propName the name of the proptype to check. + * @returns {boolean} true if the proptype is a callback. */ function isCallbackPropName(propName) { return /^on[A-Z]/.test(propName); @@ -46,7 +46,7 @@ function isCallbackPropName(propName) { * Checks if the prop is PropTypes.shape. * * @param {ASTNode} node the prop to check. - * @returns {Boolean} true if the prop is PropTypes.shape. + * @returns {boolean} true if the prop is PropTypes.shape. */ function isShapeProp(node) { return !!( @@ -73,11 +73,11 @@ function getShapeProperties(node) { * @param {ASTNode} a the first element to compare. * @param {ASTNode} b the second element to compare. * @param {Context} context The context of the two nodes. - * @param {Boolean=} ignoreCase whether or not to ignore case when comparing the two elements. - * @param {Boolean=} requiredFirst whether or not to sort required elements first. - * @param {Boolean=} callbacksLast whether or not to sort callbacks after everything else. - * @param {Boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements. - * @returns {Number} the sort order of the two elements. + * @param {boolean=} ignoreCase whether or not to ignore case when comparing the two elements. + * @param {boolean=} requiredFirst whether or not to sort required elements first. + * @param {boolean=} callbacksLast whether or not to sort callbacks after everything else. + * @param {boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements. + * @returns {number} the sort order of the two elements. */ function sorter(a, b, context, ignoreCase, requiredFirst, callbacksLast, noSortAlphabetically) { const aKey = String(astUtil.getKeyValue(context, a)); @@ -124,12 +124,12 @@ const commentnodeMap = new WeakMap(); // all nodes reference WeakMap for start a * @param {Context} context the second element to compare. * @param {Fixer} fixer the first element to compare. * @param {Array} declarations The context of the two nodes. - * @param {Boolean=} ignoreCase whether or not to ignore case when comparing the two elements. - * @param {Boolean=} requiredFirst whether or not to sort required elements first. - * @param {Boolean=} callbacksLast whether or not to sort callbacks after everything else. - * @param {Boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements. - * @param {Boolean=} sortShapeProp whether or not to sort propTypes defined in PropTypes.shape. - * @param {Boolean=} checkTypes whether or not sorting of prop type definitions are checked. + * @param {boolean=} ignoreCase whether or not to ignore case when comparing the two elements. + * @param {boolean=} requiredFirst whether or not to sort required elements first. + * @param {boolean=} callbacksLast whether or not to sort callbacks after everything else. + * @param {boolean=} noSortAlphabetically whether or not to disable alphabetical sorting of the elements. + * @param {boolean=} sortShapeProp whether or not to sort propTypes defined in PropTypes.shape. + * @param {boolean=} checkTypes whether or not sorting of prop type definitions are checked. * @returns {Object|*|{range, text}} the sort order of the two elements. */ function fixPropTypesSort( diff --git a/lib/util/props.js b/lib/util/props.js index 4cd89584e5..b5c992890b 100644 --- a/lib/util/props.js +++ b/lib/util/props.js @@ -9,7 +9,7 @@ const astUtil = require('./ast'); /** * Checks if the Identifier node passed in looks like a propTypes declaration. * @param {ASTNode} node The node to check. Must be an Identifier node. - * @returns {Boolean} `true` if the node is a propTypes declaration, `false` if not + * @returns {boolean} `true` if the node is a propTypes declaration, `false` if not */ function isPropTypesDeclaration(node) { if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) { @@ -24,7 +24,7 @@ function isPropTypesDeclaration(node) { /** * Checks if the node passed in looks like a contextTypes declaration. * @param {ASTNode} node The node to check. - * @returns {Boolean} `true` if the node is a contextTypes declaration, `false` if not + * @returns {boolean} `true` if the node is a contextTypes declaration, `false` if not */ function isContextTypesDeclaration(node) { if (node && (node.type === 'ClassProperty' || node.type === 'PropertyDefinition')) { @@ -39,7 +39,7 @@ function isContextTypesDeclaration(node) { /** * Checks if the node passed in looks like a contextType declaration. * @param {ASTNode} node The node to check. - * @returns {Boolean} `true` if the node is a contextType declaration, `false` if not + * @returns {boolean} `true` if the node is a contextType declaration, `false` if not */ function isContextTypeDeclaration(node) { return astUtil.getPropertyName(node) === 'contextType'; @@ -48,7 +48,7 @@ function isContextTypeDeclaration(node) { /** * Checks if the node passed in looks like a childContextTypes declaration. * @param {ASTNode} node The node to check. - * @returns {Boolean} `true` if the node is a childContextTypes declaration, `false` if not + * @returns {boolean} `true` if the node is a childContextTypes declaration, `false` if not */ function isChildContextTypesDeclaration(node) { return astUtil.getPropertyName(node) === 'childContextTypes'; @@ -57,7 +57,7 @@ function isChildContextTypesDeclaration(node) { /** * Checks if the Identifier node passed in looks like a defaultProps declaration. * @param {ASTNode} node The node to check. Must be an Identifier node. - * @returns {Boolean} `true` if the node is a defaultProps declaration, `false` if not + * @returns {boolean} `true` if the node is a defaultProps declaration, `false` if not */ function isDefaultPropsDeclaration(node) { const propName = astUtil.getPropertyName(node); @@ -67,7 +67,7 @@ function isDefaultPropsDeclaration(node) { /** * Checks if we are declaring a display name * @param {ASTNode} node The AST node being checked. - * @returns {Boolean} True if we are declaring a display name, false if not. + * @returns {boolean} True if we are declaring a display name, false if not. */ function isDisplayNameDeclaration(node) { switch (node.type) { @@ -86,7 +86,7 @@ function isDisplayNameDeclaration(node) { /** * Checks if the PropTypes MemberExpression node passed in declares a required propType. * @param {ASTNode} propTypeExpression node to check. Must be a `PropTypes` MemberExpression. - * @returns {Boolean} `true` if this PropType is required, `false` if not. + * @returns {boolean} `true` if this PropType is required, `false` if not. */ function isRequiredPropType(propTypeExpression) { return propTypeExpression.type === 'MemberExpression' && propTypeExpression.property.name === 'isRequired'; diff --git a/lib/util/usedPropTypes.js b/lib/util/usedPropTypes.js index 9ecef0af37..52d0a2bb66 100644 --- a/lib/util/usedPropTypes.js +++ b/lib/util/usedPropTypes.js @@ -66,7 +66,7 @@ function createPropVariables() { /** * Checks if the string is one of `props`, `nextProps`, or `prevProps` * @param {string} name The AST node being checked. - * @returns {Boolean} True if the prop name matches + * @returns {boolean} True if the prop name matches */ function isCommonVariableNameForProps(name) { return name === 'props' || name === 'nextProps' || name === 'prevProps'; @@ -75,7 +75,7 @@ function isCommonVariableNameForProps(name) { /** * Checks if the component must be validated * @param {Object} component The component to process - * @returns {Boolean} True if the component must be validated, false if not. + * @returns {boolean} True if the component must be validated, false if not. */ function mustBeValidated(component) { return !!(component && !component.ignorePropsValidation); @@ -110,7 +110,7 @@ function inLifeCycleMethod(context, node, checkAsyncSafeLifeCycles) { * Returns true if the given node is a React Component lifecycle method * @param {ASTNode} node The AST node being checked. * @param {boolean} checkAsyncSafeLifeCycles - * @return {Boolean} True if the node is a lifecycle method + * @return {boolean} True if the node is a lifecycle method */ function isNodeALifeCycleMethod(node, checkAsyncSafeLifeCycles) { const nodeKeyName = (node.key || /** @type {ASTNode} */ ({})).name; @@ -133,7 +133,7 @@ function isNodeALifeCycleMethod(node, checkAsyncSafeLifeCycles) { * method. * @param {ASTNode} node The AST node being checked. * @param {boolean} checkAsyncSafeLifeCycles - * @return {Boolean} True if the node is inside a lifecycle method + * @return {boolean} True if the node is inside a lifecycle method */ function isInLifeCycleMethod(node, checkAsyncSafeLifeCycles) { if ((node.type === 'MethodDefinition' || node.type === 'Property') && isNodeALifeCycleMethod(node, checkAsyncSafeLifeCycles)) { @@ -214,7 +214,7 @@ function isThisDotProps(node) { * Checks if the prop has spread operator. * @param {object} context * @param {ASTNode} node The AST node being marked. - * @returns {Boolean} True if the prop has spread operator, false if not. + * @returns {boolean} True if the prop has spread operator, false if not. */ function hasSpreadOperator(context, node) { const tokens = getSourceCode(context).getTokens(node); diff --git a/lib/util/variable.js b/lib/util/variable.js index c0017533be..a92a20930f 100644 --- a/lib/util/variable.js +++ b/lib/util/variable.js @@ -11,7 +11,7 @@ const getScope = require('./eslint').getScope; * Search a particular variable in a list * @param {Array} variables The variables list. * @param {string} name The name of the variable to search. - * @returns {Boolean} True if the variable was found, false if not. + * @returns {boolean} True if the variable was found, false if not. */ function findVariable(variables, name) { return variables.some((variable) => variable.name === name); From 8dc0215fdc907d931de3eb78e97d94d35fa12078 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 29 Jul 2024 21:57:26 -0700 Subject: [PATCH 08/14] [Refactor] hoist functions to module level --- lib/rules/boolean-prop-naming.js | 24 +-- lib/rules/jsx-curly-brace-presence.js | 203 +++++++++++++------------- lib/rules/no-unused-prop-types.js | 18 +-- lib/rules/self-closing-comp.js | 50 +++---- 4 files changed, 148 insertions(+), 147 deletions(-) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index fe55d52065..e856a17967 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -18,6 +18,18 @@ const eslintUtil = require('../util/eslint'); const getSourceCode = eslintUtil.getSourceCode; const getText = eslintUtil.getText; +/** + * Checks if prop is nested + * @param {Object} prop Property object, single prop type declaration + * @returns {boolean} + */ +function nestedPropTypes(prop) { + return ( + prop.type === 'Property' + && prop.value.type === 'CallExpression' + ); +} + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -162,18 +174,6 @@ module.exports = { ); } - /** - * Checks if prop is nested - * @param {Object} prop Property object, single prop type declaration - * @returns {boolean} - */ - function nestedPropTypes(prop) { - return ( - prop.type === 'Property' - && prop.value.type === 'CallExpression' - ); - } - /** * Runs recursive check on all proptypes * @param {Array} proptypes A list of Property object (for each proptype defined) diff --git a/lib/rules/jsx-curly-brace-presence.js b/lib/rules/jsx-curly-brace-presence.js index 083a60a0e3..213e0ce3ca 100755 --- a/lib/rules/jsx-curly-brace-presence.js +++ b/lib/rules/jsx-curly-brace-presence.js @@ -31,6 +31,108 @@ const OPTION_VALUES = [ ]; const DEFAULT_CONFIG = { props: OPTION_NEVER, children: OPTION_NEVER, propElementValues: OPTION_IGNORE }; +const HTML_ENTITY_REGEX = () => /&[A-Za-z\d#]+;/g; + +function containsLineTerminators(rawStringValue) { + return /[\n\r\u2028\u2029]/.test(rawStringValue); +} + +function containsBackslash(rawStringValue) { + return arrayIncludes(rawStringValue, '\\'); +} + +function containsHTMLEntity(rawStringValue) { + return HTML_ENTITY_REGEX().test(rawStringValue); +} + +function containsOnlyHtmlEntities(rawStringValue) { + return rawStringValue.replace(HTML_ENTITY_REGEX(), '').trim() === ''; +} + +function containsDisallowedJSXTextChars(rawStringValue) { + return /[{<>}]/.test(rawStringValue); +} + +function containsQuoteCharacters(value) { + return /['"]/.test(value); +} + +function containsMultilineComment(value) { + return /\/\*/.test(value); +} + +function escapeDoubleQuotes(rawStringValue) { + return rawStringValue.replace(/\\"/g, '"').replace(/"/g, '\\"'); +} + +function escapeBackslashes(rawStringValue) { + return rawStringValue.replace(/\\/g, '\\\\'); +} + +function needToEscapeCharacterForJSX(raw, node) { + return ( + containsBackslash(raw) + || containsHTMLEntity(raw) + || (node.parent.type !== 'JSXAttribute' && containsDisallowedJSXTextChars(raw)) + ); +} + +function containsWhitespaceExpression(child) { + if (child.type === 'JSXExpressionContainer') { + const value = child.expression.value; + return value ? jsxUtil.isWhiteSpaces(value) : false; + } + return false; +} + +function isLineBreak(text) { + return containsLineTerminators(text) && text.trim() === ''; +} + +function wrapNonHTMLEntities(text) { + const HTML_ENTITY = ''; + const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => ( + word === '' ? '' : `{${JSON.stringify(word)}}` + )).join(HTML_ENTITY); + + const htmlEntities = text.match(HTML_ENTITY_REGEX()); + return htmlEntities.reduce((acc, htmlEntity) => ( + acc.replace(HTML_ENTITY, htmlEntity) + ), withCurlyBraces); +} + +function wrapWithCurlyBraces(rawText) { + if (!containsLineTerminators(rawText)) { + return `{${JSON.stringify(rawText)}}`; + } + + return rawText.split('\n').map((line) => { + if (line.trim() === '') { + return line; + } + const firstCharIndex = line.search(/[^\s]/); + const leftWhitespace = line.slice(0, firstCharIndex); + const text = line.slice(firstCharIndex); + + if (containsHTMLEntity(line)) { + return `${leftWhitespace}${wrapNonHTMLEntities(text)}`; + } + return `${leftWhitespace}{${JSON.stringify(text)}}`; + }).join('\n'); +} + +function isWhiteSpaceLiteral(node) { + return node.type && node.type === 'Literal' && node.value && jsxUtil.isWhiteSpaces(node.value); +} + +function isStringWithTrailingWhiteSpaces(value) { + return /^\s|\s$/.test(value); +} + +function isLiteralWithTrailingWhiteSpaces(node) { + return node.type && node.type === 'Literal' && node.value && isStringWithTrailingWhiteSpaces(node.value); +} + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -74,100 +176,11 @@ module.exports = { }, create(context) { - const HTML_ENTITY_REGEX = () => /&[A-Za-z\d#]+;/g; const ruleOptions = context.options[0]; const userConfig = typeof ruleOptions === 'string' ? { props: ruleOptions, children: ruleOptions, propElementValues: OPTION_IGNORE } : Object.assign({}, DEFAULT_CONFIG, ruleOptions); - function containsLineTerminators(rawStringValue) { - return /[\n\r\u2028\u2029]/.test(rawStringValue); - } - - function containsBackslash(rawStringValue) { - return arrayIncludes(rawStringValue, '\\'); - } - - function containsHTMLEntity(rawStringValue) { - return HTML_ENTITY_REGEX().test(rawStringValue); - } - - function containsOnlyHtmlEntities(rawStringValue) { - return rawStringValue.replace(HTML_ENTITY_REGEX(), '').trim() === ''; - } - - function containsDisallowedJSXTextChars(rawStringValue) { - return /[{<>}]/.test(rawStringValue); - } - - function containsQuoteCharacters(value) { - return /['"]/.test(value); - } - - function containsMultilineComment(value) { - return /\/\*/.test(value); - } - - function escapeDoubleQuotes(rawStringValue) { - return rawStringValue.replace(/\\"/g, '"').replace(/"/g, '\\"'); - } - - function escapeBackslashes(rawStringValue) { - return rawStringValue.replace(/\\/g, '\\\\'); - } - - function needToEscapeCharacterForJSX(raw, node) { - return ( - containsBackslash(raw) - || containsHTMLEntity(raw) - || (node.parent.type !== 'JSXAttribute' && containsDisallowedJSXTextChars(raw)) - ); - } - - function containsWhitespaceExpression(child) { - if (child.type === 'JSXExpressionContainer') { - const value = child.expression.value; - return value ? jsxUtil.isWhiteSpaces(value) : false; - } - return false; - } - - function isLineBreak(text) { - return containsLineTerminators(text) && text.trim() === ''; - } - - function wrapNonHTMLEntities(text) { - const HTML_ENTITY = ''; - const withCurlyBraces = text.split(HTML_ENTITY_REGEX()).map((word) => ( - word === '' ? '' : `{${JSON.stringify(word)}}` - )).join(HTML_ENTITY); - - const htmlEntities = text.match(HTML_ENTITY_REGEX()); - return htmlEntities.reduce((acc, htmlEntity) => ( - acc.replace(HTML_ENTITY, htmlEntity) - ), withCurlyBraces); - } - - function wrapWithCurlyBraces(rawText) { - if (!containsLineTerminators(rawText)) { - return `{${JSON.stringify(rawText)}}`; - } - - return rawText.split('\n').map((line) => { - if (line.trim() === '') { - return line; - } - const firstCharIndex = line.search(/[^\s]/); - const leftWhitespace = line.slice(0, firstCharIndex); - const text = line.slice(firstCharIndex); - - if (containsHTMLEntity(line)) { - return `${leftWhitespace}${wrapNonHTMLEntities(text)}`; - } - return `${leftWhitespace}{${JSON.stringify(text)}}`; - }).join('\n'); - } - /** * Report and fix an unnecessary curly brace violation on a node * @param {ASTNode} JSXExpressionNode - The AST node with an unnecessary JSX expression @@ -233,18 +246,6 @@ module.exports = { }); } - function isWhiteSpaceLiteral(node) { - return node.type && node.type === 'Literal' && node.value && jsxUtil.isWhiteSpaces(node.value); - } - - function isStringWithTrailingWhiteSpaces(value) { - return /^\s|\s$/.test(value); - } - - function isLiteralWithTrailingWhiteSpaces(node) { - return node.type && node.type === 'Literal' && node.value && isStringWithTrailingWhiteSpaces(node.value); - } - // Bail out if there is any character that needs to be escaped in JSX // because escaping decreases readability and the original code may be more // readable anyway or intentional for other specific reasons diff --git a/lib/rules/no-unused-prop-types.js b/lib/rules/no-unused-prop-types.js index 55a21881ff..09dcfb5b58 100644 --- a/lib/rules/no-unused-prop-types.js +++ b/lib/rules/no-unused-prop-types.js @@ -14,6 +14,15 @@ const Components = require('../util/Components'); const docsUrl = require('../util/docsUrl'); const report = require('../util/report'); +/** + * Checks if the component must be validated + * @param {Object} component The component to process + * @returns {boolean} True if the component must be validated, false if not. + */ +function mustBeValidated(component) { + return !!component && !component.ignoreUnusedPropTypesValidation; +} + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ @@ -71,15 +80,6 @@ module.exports = { return configuration.ignore.indexOf(name) !== -1; } - /** - * Checks if the component must be validated - * @param {Object} component The component to process - * @returns {boolean} True if the component must be validated, false if not. - */ - function mustBeValidated(component) { - return !!component && !component.ignoreUnusedPropTypesValidation; - } - /** * Checks if a prop is used * @param {ASTNode} node The AST node being checked. diff --git a/lib/rules/self-closing-comp.js b/lib/rules/self-closing-comp.js index fe5fda4d49..23e168605f 100644 --- a/lib/rules/self-closing-comp.js +++ b/lib/rules/self-closing-comp.js @@ -9,12 +9,35 @@ const docsUrl = require('../util/docsUrl'); const jsxUtil = require('../util/jsx'); const report = require('../util/report'); +const optionDefaults = { component: true, html: true }; + +function isComponent(node) { + return ( + node.name + && (node.name.type === 'JSXIdentifier' || node.name.type === 'JSXMemberExpression') + && !jsxUtil.isDOMComponent(node) + ); +} + +function childrenIsEmpty(node) { + return node.parent.children.length === 0; +} + +function childrenIsMultilineSpaces(node) { + const childrens = node.parent.children; + + return ( + childrens.length === 1 + && (childrens[0].type === 'Literal' || childrens[0].type === 'JSXText') + && childrens[0].value.indexOf('\n') !== -1 + && childrens[0].value.replace(/(?!\xA0)\s/g, '') === '' + ); +} + // ------------------------------------------------------------------------------ // Rule Definition // ------------------------------------------------------------------------------ -const optionDefaults = { component: true, html: true }; - const messages = { notSelfClosing: 'Empty components are self-closing', }; @@ -49,29 +72,6 @@ module.exports = { }, create(context) { - function isComponent(node) { - return ( - node.name - && (node.name.type === 'JSXIdentifier' || node.name.type === 'JSXMemberExpression') - && !jsxUtil.isDOMComponent(node) - ); - } - - function childrenIsEmpty(node) { - return node.parent.children.length === 0; - } - - function childrenIsMultilineSpaces(node) { - const childrens = node.parent.children; - - return ( - childrens.length === 1 - && (childrens[0].type === 'Literal' || childrens[0].type === 'JSXText') - && childrens[0].value.indexOf('\n') !== -1 - && childrens[0].value.replace(/(?!\xA0)\s/g, '') === '' - ); - } - function isShouldBeSelfClosed(node) { const configuration = Object.assign({}, optionDefaults, context.options[0]); return ( From 3b6bacc18344204bd587f721fcf4ba71e41d530b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 29 Jul 2024 22:26:08 -0700 Subject: [PATCH 09/14] [Refactor] general cleanup --- lib/rules/boolean-prop-naming.js | 20 ++-- lib/rules/display-name.js | 8 +- lib/rules/forbid-prop-types.js | 36 +++--- lib/rules/jsx-no-bind.js | 8 +- lib/rules/no-array-index-key.js | 32 +++--- lib/rules/no-find-dom-node.js | 7 +- lib/rules/no-set-state.js | 3 +- lib/rules/no-string-refs.js | 21 ++-- lib/rules/no-typos.js | 3 +- lib/rules/no-unknown-property.js | 10 +- lib/rules/no-unsafe.js | 9 +- lib/rules/no-unstable-nested-components.js | 2 +- lib/rules/no-unused-state.js | 22 ++-- lib/rules/prefer-stateless-function.js | 4 +- lib/rules/require-optimization.js | 5 +- lib/rules/sort-prop-types.js | 32 +++--- lib/util/Components.js | 45 +++++--- lib/util/ast.js | 128 +++++++++++---------- lib/util/componentUtil.js | 4 +- lib/util/isCreateContext.js | 51 ++++---- lib/util/isCreateElement.js | 11 +- lib/util/isDestructuredFromPragmaImport.js | 22 ++-- lib/util/isFirstLetterCapitalized.js | 6 +- lib/util/jsx.js | 2 +- lib/util/propTypes.js | 23 +++- lib/util/propTypesSort.js | 8 +- lib/util/props.js | 3 +- lib/util/usedPropTypes.js | 30 +++-- 28 files changed, 300 insertions(+), 255 deletions(-) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index e856a17967..2c48b5a7bd 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -180,15 +180,17 @@ module.exports = { * @param {Function} addInvalidProp callback to run for each error */ function runCheck(proptypes, addInvalidProp) { - (proptypes || []).forEach((prop) => { - if (config.validateNested && nestedPropTypes(prop)) { - runCheck(prop.value.arguments[0].properties, addInvalidProp); - return; - } - if (flowCheck(prop) || regularCheck(prop) || tsCheck(prop)) { - addInvalidProp(prop); - } - }); + if (proptypes) { + proptypes.forEach((prop) => { + if (config.validateNested && nestedPropTypes(prop)) { + runCheck(prop.value.arguments[0].properties, addInvalidProp); + return; + } + if (flowCheck(prop) || regularCheck(prop) || tsCheck(prop)) { + addInvalidProp(prop); + } + }); + } } /** diff --git a/lib/rules/display-name.js b/lib/rules/display-name.js index 5e5b8b6980..027882a461 100644 --- a/lib/rules/display-name.js +++ b/lib/rules/display-name.js @@ -76,9 +76,11 @@ module.exports = { * @returns {boolean} True if React.forwardRef is nested inside React.memo, false if not. */ function isNestedMemo(node) { - const argumentIsCallExpression = node.arguments && node.arguments[0] && node.arguments[0].type === 'CallExpression'; - - return node.type === 'CallExpression' && argumentIsCallExpression && utils.isPragmaComponentWrapper(node); + return node.type === 'CallExpression' + && node.arguments + && node.arguments[0] + && node.arguments[0].type === 'CallExpression' + && utils.isPragmaComponentWrapper(node); } /** diff --git a/lib/rules/forbid-prop-types.js b/lib/rules/forbid-prop-types.js index b561b26da1..581c8969b9 100644 --- a/lib/rules/forbid-prop-types.js +++ b/lib/rules/forbid-prop-types.js @@ -158,29 +158,25 @@ module.exports = { } function checkNode(node) { - switch (node && node.type) { - case 'ObjectExpression': - checkProperties(node.properties); - break; - case 'Identifier': { - const propTypesObject = variableUtil.findVariableByName(context, node, node.name); - if (propTypesObject && propTypesObject.properties) { - checkProperties(propTypesObject.properties); - } - break; + if (!node) { + return; + } + + if (node.type === 'ObjectExpression') { + checkProperties(node.properties); + } else if (node.type === 'Identifier') { + const propTypesObject = variableUtil.findVariableByName(context, node, node.name); + if (propTypesObject && propTypesObject.properties) { + checkProperties(propTypesObject.properties); } - case 'CallExpression': { - const innerNode = node.arguments && node.arguments[0]; - if ( - propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee)) + } else if (node.type === 'CallExpression') { + const innerNode = node.arguments && node.arguments[0]; + if ( + propWrapperUtil.isPropWrapperFunction(context, getText(context, node.callee)) && innerNode - ) { - checkNode(innerNode); - } - break; + ) { + checkNode(innerNode); } - default: - break; } } diff --git a/lib/rules/jsx-no-bind.js b/lib/rules/jsx-no-bind.js index 4d6e349d25..588ff0b03f 100644 --- a/lib/rules/jsx-no-bind.js +++ b/lib/rules/jsx-no-bind.js @@ -93,21 +93,21 @@ module.exports = { ) { return 'bindCall'; } - if (nodeType === 'ConditionalExpression') { + if (node.type === 'ConditionalExpression') { return getNodeViolationType(node.test) || getNodeViolationType(node.consequent) || getNodeViolationType(node.alternate); } - if (!configuration.allowArrowFunctions && nodeType === 'ArrowFunctionExpression') { + if (!configuration.allowArrowFunctions && node.type === 'ArrowFunctionExpression') { return 'arrowFunc'; } if ( !configuration.allowFunctions - && (nodeType === 'FunctionExpression' || nodeType === 'FunctionDeclaration') + && (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration') ) { return 'func'; } - if (!configuration.allowBind && nodeType === 'BindExpression') { + if (!configuration.allowBind && node.type === 'BindExpression') { return 'bindExpression'; } diff --git a/lib/rules/no-array-index-key.js b/lib/rules/no-array-index-key.js index 2a0ae41e6f..ffd5c927b4 100644 --- a/lib/rules/no-array-index-key.js +++ b/lib/rules/no-array-index-key.js @@ -189,14 +189,15 @@ module.exports = { return; } - if (node.type === 'CallExpression' - && node.callee - && node.callee.type === 'MemberExpression' - && node.callee.object - && isArrayIndex(node.callee.object) - && node.callee.property - && node.callee.property.type === 'Identifier' - && node.callee.property.name === 'toString' + if ( + node.type === 'CallExpression' + && node.callee + && node.callee.type === 'MemberExpression' + && node.callee.object + && isArrayIndex(node.callee.object) + && node.callee.property + && node.callee.property.type === 'Identifier' + && node.callee.property.name === 'toString' ) { // key={bar.toString()} report(context, messages.noArrayIndex, 'noArrayIndex', { @@ -205,13 +206,14 @@ module.exports = { return; } - if (node.type === 'CallExpression' - && node.callee - && node.callee.type === 'Identifier' - && node.callee.name === 'String' - && Array.isArray(node.arguments) - && node.arguments.length > 0 - && isArrayIndex(node.arguments[0]) + if ( + node.type === 'CallExpression' + && node.callee + && node.callee.type === 'Identifier' + && node.callee.name === 'String' + && Array.isArray(node.arguments) + && node.arguments.length > 0 + && isArrayIndex(node.arguments[0]) ) { // key={String(bar)} report(context, messages.noArrayIndex, 'noArrayIndex', { diff --git a/lib/rules/no-find-dom-node.js b/lib/rules/no-find-dom-node.js index 0dae59da43..3d9ef52ef8 100644 --- a/lib/rules/no-find-dom-node.js +++ b/lib/rules/no-find-dom-node.js @@ -35,8 +35,11 @@ module.exports = { CallExpression(node) { const callee = node.callee; - const isfindDOMNode = (callee.name === 'findDOMNode') - || (callee.property && callee.property.name === 'findDOMNode'); + const isfindDOMNode = callee.name === 'findDOMNode' || ( + callee.property + && callee.property.name === 'findDOMNode' + ); + if (!isfindDOMNode) { return; } diff --git a/lib/rules/no-set-state.js b/lib/rules/no-set-state.js index 0866552141..44967bf03c 100644 --- a/lib/rules/no-set-state.js +++ b/lib/rules/no-set-state.js @@ -49,9 +49,8 @@ module.exports = { * @param {Object} component The component to process */ function reportSetStateUsages(component) { - let setStateUsage; for (let i = 0, j = component.setStateUsages.length; i < j; i++) { - setStateUsage = component.setStateUsages[i]; + const setStateUsage = component.setStateUsages[i]; report(context, messages.noSetState, 'noSetState', { node: setStateUsage, }); diff --git a/lib/rules/no-string-refs.js b/lib/rules/no-string-refs.js index c5c3b29166..bef6440441 100644 --- a/lib/rules/no-string-refs.js +++ b/lib/rules/no-string-refs.js @@ -62,11 +62,9 @@ module.exports = { * @returns {boolean} True if we are using a ref attribute, false if not. */ function isRefAttribute(node) { - return !!( - node.type === 'JSXAttribute' - && node.name - && node.name.name === 'ref' - ); + return node.type === 'JSXAttribute' + && !!node.name + && node.name.name === 'ref'; } /** @@ -75,11 +73,9 @@ module.exports = { * @returns {boolean} True if the node contains a string value, false if not. */ function containsStringLiteral(node) { - return !!( - node.value + return !!node.value && node.value.type === 'Literal' - && typeof node.value.value === 'string' - ); + && typeof node.value.value === 'string'; } /** @@ -88,13 +84,11 @@ module.exports = { * @returns {boolean} True if the node contains a string value within a jsx expression, false if not. */ function containsStringExpressionContainer(node) { - return !!( - node.value + return !!node.value && node.value.type === 'JSXExpressionContainer' && node.value.expression && ((node.value.expression.type === 'Literal' && typeof node.value.expression.value === 'string') - || (node.value.expression.type === 'TemplateLiteral' && detectTemplateLiterals)) - ); + || (node.value.expression.type === 'TemplateLiteral' && detectTemplateLiterals)); } return { @@ -105,6 +99,7 @@ module.exports = { }); } }, + JSXAttribute(node) { if ( isRefAttribute(node) diff --git a/lib/rules/no-typos.js b/lib/rules/no-typos.js index 3d79d40b18..d60d2e7cf2 100644 --- a/lib/rules/no-typos.js +++ b/lib/rules/no-typos.js @@ -194,7 +194,8 @@ module.exports = { } if (node.specifiers.length >= 1) { const propTypesSpecifier = node.specifiers.find((specifier) => ( - specifier.imported && specifier.imported.name === 'PropTypes' + specifier.imported + && specifier.imported.name === 'PropTypes' )); if (propTypesSpecifier) { propTypesPackageName = propTypesSpecifier.local.name; diff --git a/lib/rules/no-unknown-property.js b/lib/rules/no-unknown-property.js index 61ca8ad809..50134264d1 100644 --- a/lib/rules/no-unknown-property.js +++ b/lib/rules/no-unknown-property.js @@ -463,7 +463,11 @@ function isValidAriaAttribute(name) { * @returns {string | null} tag name */ function getTagName(node) { - if (node && node.parent && node.parent.name && node.parent.name) { + if ( + node + && node.parent + && node.parent.name + ) { return node.parent.name.name; } return null; @@ -592,7 +596,9 @@ module.exports = { // Let's dive deeper into tags that are HTML/DOM elements (`