Function propTypesInstructions
has a Cognitive Complexity of 304 (exceeds 5 allowed). Consider refactoring. Open
module.exports = function propTypesInstructions(context, components, utils) {
// Used to track the type annotations in scope.
// Necessary because babel's scopes do not track type annotations.
let stack = null;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function propTypesInstructions
has 866 lines of code (exceeds 25 allowed). Consider refactoring. Open
module.exports = function propTypesInstructions(context, components, utils) {
// Used to track the type annotations in scope.
// Necessary because babel's scopes do not track type annotations.
let stack = null;
File propTypes.js
has 921 lines of code (exceeds 250 allowed). Consider refactoring. Open
/**
* @fileoverview Common propTypes detection functionality.
*/
'use strict';
Function markPropTypesAsDeclared
has 130 lines of code (exceeds 25 allowed). Consider refactoring. Open
function markPropTypesAsDeclared(node, propTypes) {
let componentNode = node;
while (componentNode && !components.get(componentNode)) {
componentNode = componentNode.parent;
}
Function buildReactDeclarationTypes
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
function buildReactDeclarationTypes(value, parentName) {
if (
value
&& value.callee
&& value.callee.object
Function convertReturnTypeToPropTypes
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
convertReturnTypeToPropTypes(node) {
// ReturnType<T> should always have one parameter
const nodeTypeParams = node.typeParameters;
if (nodeTypeParams) {
if (nodeTypeParams.params.length === 1) {
Function markAnnotatedFunctionArgumentsAsDeclared
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
function markAnnotatedFunctionArgumentsAsDeclared(node) {
if (!node.params || !node.params.length) {
return;
}
Function searchDeclarationByName
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
searchDeclarationByName(node) {
let typeName;
if (astUtil.isTSTypeReference(node)) {
typeName = node.typeName.name;
const leftMostName = getLeftMostTypeName(node.typeName);
Consider simplifying this complex logical expression. Open
if (
node.parent
&& node.parent.callee
&& node.parent.typeParameters
&& node.parent.typeParameters.params
Function ObjectTypeAnnotation
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
ObjectTypeAnnotation(annotation, parentName, seen) {
let containsUnresolvedObjectTypeSpread = false;
let containsSpread = false;
const containsIndexers = Boolean(annotation.indexers && annotation.indexers.length);
const shapeTypeDefinition = {
Consider simplifying this complex logical expression. Open
if (
value
&& value.type === 'CallExpression'
&& value.callee
&& value.callee.property
Avoid deeply nested control flow statements. Open
if (returnTypeFunction.length === 0) {
// Cannot find identifier in current scope. It might be an exported type.
this.shouldIgnorePropTypes = true;
return;
}
Avoid deeply nested control flow statements. Open
if (isFunctionType(func)) {
let res = func.body;
if (res.type === 'BlockStatement') {
res = astUtil.findReturnStatement(func);
if (res) {
Consider simplifying this complex logical expression. Open
if (((n.type === 'AssignmentExpression') && propsUtil.isPropTypesDeclaration(n.left))
|| ((n.type === 'ClassProperty' || n.type === 'PropertyDefinition' || n.type === 'Property') && propsUtil.isPropTypesDeclaration(n))) {
// Found a propType used inside of another propType. This is not considered usage, we'll still validate
// this component.
isUsedInPropTypes = true;
Avoid too many return
statements within this function. Open
return {};
Avoid too many return
statements within this function. Open
return unionTypeDefinition;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
if (!isValidReactGenericTypeAnnotation(annotation)) return;
Avoid too many return
statements within this function. Open
return;
Avoid too many return
statements within this function. Open
return declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
Avoid too many return
statements within this function. Open
return declarePropTypesForObjectTypeAnnotation(typeNode, declaredPropTypes);
Avoid too many return
statements within this function. Open
return {};
Avoid too many return
statements within this function. Open
return {};
Function isSuperTypeParameterPropsDeclaration
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function isSuperTypeParameterPropsDeclaration(node) {
if (node && (node.type === 'ClassDeclaration' || node.type === 'ClassExpression')) {
if (node.superTypeParameters && node.superTypeParameters.params.length > 0) {
return true;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function iterateProperties
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function iterateProperties(context, properties, fn, handleSpreadFn) {
if (properties && properties.length && typeof fn === 'function') {
for (let i = 0, j = properties.length; i < j; i++) {
const node = properties[i];
const key = astUtil.getKeyValue(context, node);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"