How to use the @typescript-eslint/experimental-utils.AST_NODE_TYPES.ArrowFunctionExpression 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 / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
import { TokenInfo } from './TokenInfo';
import { createRule, ExcludeKeys, RequireKeys } from '../../util';

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,
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / space-before-function-paren.ts View on Github external
function getConfigForFunction(
      node:
        | TSESTree.ArrowFunctionExpression
        | TSESTree.FunctionDeclaration
        | TSESTree.FunctionExpression,
    ): FuncOption {
      if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {
        // Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar
        if (
          node.async &&
          isOpeningParenToken(sourceCode.getFirstToken(node, { skip: 1 })!)
        ) {
          return overrideConfig.asyncArrow ?? baseConfig;
        }
      } else if (isNamedFunction(node)) {
        return overrideConfig.named ?? baseConfig;

        // `generator-star-spacing` should warn anonymous generators. E.g. `function* () {}`
      } else if (!node.generator) {
        return overrideConfig.anonymous ?? baseConfig;
      }

      return 'ignore';
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / explicit-function-return-type.ts View on Github external
function getLocEnd(
      node:
        | TSESTree.ArrowFunctionExpression
        | TSESTree.FunctionDeclaration
        | TSESTree.FunctionExpression,
    ): TSESTree.LineAndColumnData {
      /* highlight `=>` */
      if (node.type === AST_NODE_TYPES.ArrowFunctionExpression) {
        return sourceCode.getTokenBefore(
          node.body,
          token =>
            token.type === AST_TOKEN_TYPES.Punctuator && token.value === '=>',
        )!.loc.end;
      }

      return sourceCode.getTokenBefore(node.body!)!.loc.end;
    }
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:
          return 'method';
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.
         */
        if (node.parent && !STATEMENT_LIST_PARENTS.has(node.parent.type)) {
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-nullish-coalescing.ts View on Github external
parents.add(current);

    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
import { typeIsOrHasBaseType } from '../util';
import {
  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',
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 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;

@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