How to use the @typescript-eslint/experimental-utils.AST_NODE_TYPES.FunctionExpression 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
);

      // Remove overload definition to avoid confusion of no-redeclare rule.
      const { defs, identifiers } = upperScope.set.get(id.name)!;
      for (let i = 0; i < defs.length; ++i) {
        const def = defs[i];
        if (
          def.type === 'FunctionName' &&
          def.node.type === AST_NODE_TYPES.TSDeclareFunction
        ) {
          defs.splice(i, 1);
          identifiers.splice(i, 1);
          break;
        }
      }
    } else if (type === AST_NODE_TYPES.FunctionExpression && id) {
      scopeManager.__nestFunctionExpressionNameScope(node);
    }

    // Open the function scope.
    scopeManager.__nestFunctionScope(node, this.isInnerMethodDefinition);
    const innerScope = this.currentScope();

    // Process the type parameters
    this.visit(typeParameters);

    // Process parameter declarations.
    for (let i = 0; i < params.length; ++i) {
      this.visitPattern(
        params[i],
        { processRightHandNodes: true },
        (pattern, info) => {
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / member-ordering.ts View on Github external
create(context, [options]) {
    const sourceCode = context.getSourceCode();

    const functionExpressions = [
      AST_NODE_TYPES.FunctionExpression,
      AST_NODE_TYPES.ArrowFunctionExpression,
    ];

    /**
     * Gets the node type.
     * @param node the node to be evaluated.
     */
    function getNodeType(
      node: TSESTree.ClassElement | TSESTree.TypeElement,
    ): string | null {
      // TODO: add missing TSCallSignatureDeclaration
      switch (node.type) {
        case AST_NODE_TYPES.TSAbstractMethodDefinition:
        case AST_NODE_TYPES.MethodDefinition:
          return node.kind;
        case AST_NODE_TYPES.TSMethodSignature:
github jonaskello / eslint-plugin-functional / src / util / typeguard.ts View on Github external
export function isFunctionExpressionLike(
  node: TSESTree.Node
): node is TSESTree.FunctionExpression | TSESTree.ArrowFunctionExpression {
  return (
    node.type === AST_NODE_TYPES.FunctionExpression ||
    node.type === AST_NODE_TYPES.ArrowFunctionExpression
  );
}
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / no-useless-constructor.ts View on Github external
MethodDefinition(node): void {
        if (
          node.value &&
          node.value.type === AST_NODE_TYPES.FunctionExpression &&
          node.value.body &&
          checkAccessibility(node) &&
          checkParams(node)
        ) {
          rules.MethodDefinition(node);
        }
      },
    };
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-nullish-coalescing.ts View on Github external
if (
      (current.type === AST_NODE_TYPES.ConditionalExpression ||
        current.type === AST_NODE_TYPES.DoWhileStatement ||
        current.type === AST_NODE_TYPES.IfStatement ||
        current.type === AST_NODE_TYPES.ForStatement ||
        current.type === AST_NODE_TYPES.WhileStatement) &&
      parents.has(current.test)
    ) {
      return true;
    }

    if (
      [
        AST_NODE_TYPES.ArrowFunctionExpression,
        AST_NODE_TYPES.FunctionExpression,
      ].includes(current.type)
    ) {
      /**
       * This is a weird situation like:
       * `if (() => a || b) {}`
       * `if (function () { return a || b }) {}`
       */
      return false;
    }

    current = current.parent;
  }

  return false;
}
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-readonly.ts View on Github external
TSESTree,
  AST_NODE_TYPES,
} from '@typescript-eslint/experimental-utils';

type MessageIds = 'preferReadonly';

type Options = [
  {
    onlyInlineLambdas?: boolean;
  },
];

const functionScopeBoundaries = [
  AST_NODE_TYPES.ArrowFunctionExpression,
  AST_NODE_TYPES.FunctionDeclaration,
  AST_NODE_TYPES.FunctionExpression,
  AST_NODE_TYPES.MethodDefinition,
].join(', ');

export default util.createRule({
  name: 'prefer-readonly',
  meta: {
    docs: {
      description:
        "Requires that private members are marked as `readonly` if they're never modified outside of the constructor",
      category: 'Best Practices',
      recommended: false,
      requiresTypeChecking: true,
    },
    fixable: 'code',
    messages: {
      preferReadonly:
github jest-community / eslint-plugin-jest / src / rules / utils.ts View on Github external
export const isFunction = (node: TSESTree.Node): node is FunctionExpression =>
  node.type === AST_NODE_TYPES.FunctionExpression ||
  node.type === AST_NODE_TYPES.ArrowFunctionExpression;
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
'BlockStatement, ClassBody'(
        node: TSESTree.BlockStatement | TSESTree.ClassBody,
      ) {
        let blockIndentLevel;

        if (node.parent && isOuterIIFE(node.parent)) {
          blockIndentLevel = options.outerIIFEBody;
        } else if (
          node.parent &&
          (node.parent.type === AST_NODE_TYPES.FunctionExpression ||
            node.parent.type === AST_NODE_TYPES.ArrowFunctionExpression)
        ) {
          blockIndentLevel = options.FunctionExpression.body;
        } else if (
          node.parent &&
          node.parent.type === AST_NODE_TYPES.FunctionDeclaration
        ) {
          blockIndentLevel = options.FunctionDeclaration.body;
        } else {
          blockIndentLevel = 1;
        }

        /*
         * For blocks that aren't lone statements, ensure that the opening curly brace
         * is aligned with the parent.
         */
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
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,
  AST_NODE_TYPES.FunctionDeclaration,
  AST_NODE_TYPES.FunctionExpression,
  AST_NODE_TYPES.Identifier,
  AST_NODE_TYPES.IfStatement,
  AST_NODE_TYPES.Literal,
  AST_NODE_TYPES.LabeledStatement,
  AST_NODE_TYPES.LogicalExpression,
  AST_NODE_TYPES.MemberExpression,
  AST_NODE_TYPES.MetaProperty,
  AST_NODE_TYPES.MethodDefinition,
  AST_NODE_TYPES.NewExpression,
  AST_NODE_TYPES.ObjectExpression,
  AST_NODE_TYPES.ObjectPattern,
  AST_NODE_TYPES.Program,
  AST_NODE_TYPES.Property,
  AST_NODE_TYPES.RestElement,
  AST_NODE_TYPES.ReturnStatement,
  AST_NODE_TYPES.SequenceExpression,
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / no-explicit-any.ts View on Github external
function isNodeValidFunction(node: TSESTree.Node): boolean {
      return [
        AST_NODE_TYPES.ArrowFunctionExpression,
        AST_NODE_TYPES.FunctionDeclaration,
        AST_NODE_TYPES.FunctionExpression,
        AST_NODE_TYPES.TSFunctionType,
        AST_NODE_TYPES.TSCallSignatureDeclaration,
      ].includes(node.type);
    }

@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