How to use the @typescript-eslint/experimental-utils.AST_NODE_TYPES.BlockStatement function in @typescript-eslint/experimental-utils

To help you get started, we’ve selected a few @typescript-eslint/experimental-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github typescript-eslint / typescript-eslint / packages / parser / src / analyze-scope.ts View on Github external
node,
                i,
                info.rest,
              ),
            );
            this.referencingDefaultValue(pattern, info.assignments, null, true);
          }
        },
      );
    }

    // Process the return type.
    this.visit(returnType);

    // Process the body.
    if (body && body.type === AST_NODE_TYPES.BlockStatement) {
      this.visitChildren(body);
    } else {
      this.visit(body);
    }

    // Close the function scope.
    this.close(node);
  }
github jest-community / eslint-plugin-jest / src / rules / valid-expect-in-promise.ts View on Github external
(node.parent && node.parent.type === AST_NODE_TYPES.AwaitExpression)
        ) {
          return;
        }
        const testFunction = findTestFunction(node);
        if (testFunction && !isHavingAsyncCallBackParam(testFunction)) {
          const { body } = testFunction;

          /* istanbul ignore if https://github.com/typescript-eslint/typescript-eslint/issues/734 */
          if (!body) {
            throw new Error(
              `Unexpected null when attempting to fix ${context.getFilename()} - please file a github issue at https://github.com/jest-community/eslint-plugin-jest`,
            );
          }

          if (body.type !== AST_NODE_TYPES.BlockStatement) {
            return;
          }

          const testFunctionBody = body.body;
          const [fulfillmentCallback, rejectionCallback] = node.arguments;

          // then block can have two args, fulfillment & rejection
          // then block can have one args, fulfillment
          // catch block can have one args, rejection
          // ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
          verifyExpectWithReturn(
            [fulfillmentCallback, rejectionCallback],
            node.callee,
            context,
            testFunctionBody,
          );
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / explicit-function-return-type.ts View on Github external
function doesImmediatelyReturnFunctionExpression({
      body,
    }:
      | TSESTree.ArrowFunctionExpression
      | TSESTree.FunctionDeclaration
      | TSESTree.FunctionExpression): boolean {
      // Should always have a body; really checking just in case
      /* istanbul ignore if */ if (!body) {
        return false;
      }

      // Check if body is a block with a single statement
      if (
        body.type === AST_NODE_TYPES.BlockStatement &&
        body.body.length === 1
      ) {
        const [statement] = body.body;

        // Check if that statement is a return statement with an argument
        if (
          statement.type === AST_NODE_TYPES.ReturnStatement &&
          !!statement.argument
        ) {
          // If so, check that returned argument as body
          body = statement.argument;
        }
      }

      // Check if the body being returned is a function expression
      return (
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
const GLOBAL_LINEBREAK_REGEX = /\r\n|[\r\n\u2028\u2029]/gu;
const WHITESPACE_REGEX = /\s*$/u;

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

const KNOWN_NODES = new Set([
  AST_NODE_TYPES.AssignmentExpression,
  AST_NODE_TYPES.AssignmentPattern,
  AST_NODE_TYPES.ArrayExpression,
  AST_NODE_TYPES.ArrayPattern,
  AST_NODE_TYPES.ArrowFunctionExpression,
  AST_NODE_TYPES.AwaitExpression,
  AST_NODE_TYPES.BlockStatement,
  AST_NODE_TYPES.BinaryExpression,
  AST_NODE_TYPES.BreakStatement,
  AST_NODE_TYPES.CallExpression,
  AST_NODE_TYPES.CatchClause,
  AST_NODE_TYPES.ClassBody,
  AST_NODE_TYPES.ClassDeclaration,
  AST_NODE_TYPES.ClassExpression,
  AST_NODE_TYPES.ConditionalExpression,
  AST_NODE_TYPES.ContinueStatement,
  AST_NODE_TYPES.DoWhileStatement,
  AST_NODE_TYPES.DebuggerStatement,
  AST_NODE_TYPES.EmptyStatement,
  AST_NODE_TYPES.ExpressionStatement,
  AST_NODE_TYPES.ForStatement,
  AST_NODE_TYPES.ForInStatement,
  AST_NODE_TYPES.ForOfStatement,
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent.ts View on Github external
TSModuleBlock(node: TSESTree.TSModuleBlock) {
        // transform it to a BlockStatement
        return rules['BlockStatement, ClassBody']({
          type: AST_NODE_TYPES.BlockStatement,
          body: node.body,

          // location data
          parent: node.parent,
          range: node.range,
          loc: node.loc,
        });
      },
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / require-await.ts View on Github external
'ArrowFunctionExpression[async = true]'(
        node: TSESTree.ArrowFunctionExpression,
      ): void {
        // If body type is not BlockStatment, we need to check the return type here
        if (node.body.type !== AST_NODE_TYPES.BlockStatement) {
          const expression = parserServices.esTreeNodeToTSNodeMap.get(
            node.body,
          );
          if (expression && isThenableType(expression)) {
            // tell the base rule to mark the scope as having an await so it ignores it
            rules.AwaitExpression();
          }
        }
      },
      'FunctionDeclaration:exit': rules['FunctionDeclaration:exit'],
github jest-community / eslint-plugin-jest / src / rules / valid-expect-in-promise.ts View on Github external
const isExpectCallPresentInFunction = (body: TSESTree.Node) => {
  if (body.type === AST_NODE_TYPES.BlockStatement) {
    return body.body.find(line => {
      if (line.type === AST_NODE_TYPES.ExpressionStatement) {
        return isFullExpectCall(line.expression);
      }
      if (line.type === AST_NODE_TYPES.ReturnStatement && line.argument) {
        return isFullExpectCall(line.argument);
      }

      return false;
    });
  }

  return isFullExpectCall(body);
};
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
function addBlocklessNodeIndent(node: TSESTree.Node): void {
      if (node.type !== AST_NODE_TYPES.BlockStatement) {
        const lastParentToken = sourceCode.getTokenBefore(
          node,
          isNotOpeningParenToken,
        )!;

        let firstBodyToken = sourceCode.getFirstToken(node)!;
        let lastBodyToken = sourceCode.getLastToken(node)!;

        while (
          isOpeningParenToken(sourceCode.getTokenBefore(firstBodyToken)!) &&
          isClosingParenToken(sourceCode.getTokenAfter(lastBodyToken)!)
        ) {
          firstBodyToken = sourceCode.getTokenBefore(firstBodyToken)!;
          lastBodyToken = sourceCode.getTokenAfter(lastBodyToken)!;
        }
github jest-community / eslint-plugin-jest / src / rules / valid-describe.ts View on Github external
context.report({
            messageId: 'noAsyncDescribeCallback',
            node: callback,
          });
        }

        if (!isDescribeEach(node) && callback.params.length) {
          context.report({
            messageId: 'unexpectedDescribeArgument',
            loc: paramsLocation(callback.params),
          });
        }

        if (
          callback.body &&
          callback.body.type === AST_NODE_TYPES.BlockStatement
        ) {
          callback.body.body.forEach(node => {
            if (node.type === AST_NODE_TYPES.ReturnStatement) {
              context.report({
                messageId: 'unexpectedReturnInDescribe',
                node,
              });
            }
          });
        }
      },
    };

@typescript-eslint/experimental-utils

(Experimental) Utilities for working with TypeScript + ESLint together

MIT
Latest version published 11 months ago

Package Health Score

91 / 100
Full package analysis