lib/rules/function-calc-no-invalid/index.js
function verifyMathExpressions(expression, node) {
        if (expression.type === "MathExpression") {
          const { operator, left, right } = expression;

          if (operator === "+" || operator === "-") {
            if (
              expression.source.operator.end.index === right.source.start.index
            ) {
              complain(
                messages.expectedSpaceAfterOperator(operator),
                node.sourceIndex + expression.source.operator.end.index
              );
            }

            if (
              expression.source.operator.start.index === left.source.end.index
            ) {
              complain(
                messages.expectedSpaceBeforeOperator(operator),
                node.sourceIndex + expression.source.operator.start.index
              );
            }
          } else if (operator === "/") {
            if (
              (right.type === "Value" && right.value === 0) ||
              (right.type === "MathExpression" && getNumber(right) === 0)
            ) {
              complain(
                messages.rejectedDivisionByZero(),
                node.sourceIndex + expression.source.operator.end.index
              );
            }
          }

          if (getResolvedType(expression) === "invalid") {
            complain(
              messages.expectedValidResolvedType(operator),
              node.sourceIndex + expression.source.operator.start.index
            );
          }

          verifyMathExpressions(expression.left, node);
          verifyMathExpressions(expression.right, node);
        }
      }
function verifyMathExpressions(expression, node) {
        if (expression.type === "MathExpression") {
          const { operator, left, right } = expression;

          if (operator === "+" || operator === "-") {
            if (
              expression.source.operator.end.index === right.source.start.index
            ) {
              complain(
                messages.expectedSpaceAfterOperator(operator),
                node.sourceIndex + expression.source.operator.end.index
              );
            }

            if (
              expression.source.operator.start.index === left.source.end.index
            ) {
              complain(
                messages.expectedSpaceBeforeOperator(operator),
                node.sourceIndex + expression.source.operator.start.index
              );
            }
          } else if (operator === "/") {
            if (
              (right.type === "Value" && right.value === 0) ||
              (right.type === "MathExpression" && getNumber(right) === 0)
            ) {
              complain(
                messages.rejectedDivisionByZero(),
                node.sourceIndex + expression.source.operator.end.index
              );
            }
          }

          if (getResolvedType(expression) === "invalid") {
            complain(
              messages.expectedValidResolvedType(operator),
              node.sourceIndex + expression.source.operator.start.index
            );
          }

          verifyMathExpressions(expression.left, node);
          verifyMathExpressions(expression.right, node);
        }
      }
function verifyMathExpressions ( expression , node ) { if ( expression . type === "MathExpression" ) { const { operator , left , right } = expression ; if ( operator === "+" || operator === "-" ) { if ( expression . source . operator . end . index === right . source . start . index ) { complain ( messages . expectedSpaceAfterOperator ( operator ) , node . sourceIndex + expression . source . operator . end . index ) ; } if ( expression . source . operator . start . index === left . source . end . index ) { complain ( messages . expectedSpaceBeforeOperator ( operator ) , node . sourceIndex + expression . source . operator . start . index ) ; } } else if ( operator === "/" ) { if ( ( right . type === "Value" && right . value === 0 ) || ( right . type === "MathExpression" && getNumber ( right ) === 0 ) ) { complain ( messages . rejectedDivisionByZero ( ) , node . sourceIndex + expression . source . operator . end . index ) ; } } if ( getResolvedType ( expression ) === "invalid" ) { complain ( messages . expectedValidResolvedType ( operator ) , node . sourceIndex + expression . source . operator . start . index ) ; } verifyMathExpressions ( expression . left , node ) ; verifyMathExpressions ( expression . right , node ) ; } }
Verify that each operation expression is valid.
Reports when a invalid operation expression is found.
@param {object} expression expression node.
@param {object} node calc function node.
@returns {void}
Verify that each operation expression is valid . Reports when a invalid operation expression is found .