How to use the @typescript-eslint/experimental-utils.AST_NODE_TYPES.MethodDefinition 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 / no-empty-function.ts View on Github external
function isAllowedEmptyConstructor(
      node: TSESTree.FunctionDeclaration | TSESTree.FunctionExpression,
    ): boolean {
      const parent = node.parent;
      if (
        isBodyEmpty(node) &&
        parent?.type === AST_NODE_TYPES.MethodDefinition &&
        parent.kind === 'constructor'
      ) {
        const { accessibility } = parent;

        return (
          // allow protected constructors
          (accessibility === 'protected' && isAllowedProtectedConstructors) ||
          // allow private constructors
          (accessibility === 'private' && isAllowedPrivateConstructors) ||
          // allow constructors which have parameter properties
          hasParameterProperties(node)
        );
      }

      return false;
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / space-before-function-paren.ts View on Github external
function isNamedFunction(
      node:
        | TSESTree.ArrowFunctionExpression
        | TSESTree.FunctionDeclaration
        | TSESTree.FunctionExpression,
    ): boolean {
      if (node.id) {
        return true;
      }

      const parent = node.parent!;

      return (
        parent.type === AST_NODE_TYPES.MethodDefinition ||
        (parent.type === AST_NODE_TYPES.Property &&
          (parent.kind === 'get' || parent.kind === 'set' || parent.method))
      );
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-readonly.ts View on Github external
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:
        "Member '{{name}}' is never reassigned; mark it as `readonly`.",
github jonaskello / eslint-plugin-functional / src / util / typeguard.ts View on Github external
export function isMethodDefinition(
  node: TSESTree.Node
): node is TSESTree.MethodDefinition {
  return node.type === AST_NODE_TYPES.MethodDefinition;
}
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / promise-function-async.ts View on Github external
const returnType = checker.getReturnTypeOfSignature(signatures[0]);

      if (
        !util.containsAllTypesByName(
          returnType,
          allowAny!,
          allAllowedPromiseNames,
        )
      ) {
        return;
      }

      if (
        node.parent &&
        (node.parent.type === AST_NODE_TYPES.Property ||
          node.parent.type === AST_NODE_TYPES.MethodDefinition) &&
        (node.parent.kind === 'get' || node.parent.kind === 'set')
      ) {
        return;
      }

      context.report({
        messageId: 'missingAsync',
        node,
      });
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / member-ordering.ts View on Github external
function getMemberName(
      node: TSESTree.ClassElement | TSESTree.TypeElement,
    ): string | null {
      switch (node.type) {
        case AST_NODE_TYPES.TSPropertySignature:
        case AST_NODE_TYPES.TSMethodSignature:
        case AST_NODE_TYPES.TSAbstractClassProperty:
        case AST_NODE_TYPES.ClassProperty:
          return util.getNameFromMember(node, sourceCode);
        case AST_NODE_TYPES.TSAbstractMethodDefinition:
        case AST_NODE_TYPES.MethodDefinition:
          return node.kind === 'constructor'
            ? 'constructor'
            : util.getNameFromMember(node, sourceCode);
        case AST_NODE_TYPES.TSConstructSignatureDeclaration:
          return 'new';
        case AST_NODE_TYPES.TSIndexSignature:
          return util.getNameFromIndexSignature(node);
        default:
          return null;
      }
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / prefer-readonly.ts View on Github external
function isConstructor(node: TSESTree.Node): boolean {
      return (
        node.type === AST_NODE_TYPES.MethodDefinition &&
        node.kind === 'constructor'
      );
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / adjacent-overload-signatures.ts View on Github external
if (!member.declaration) {
            return null;
          }

          return getMemberName(member.declaration);
        }
        case AST_NODE_TYPES.TSDeclareFunction:
        case AST_NODE_TYPES.FunctionDeclaration:
          return member.id && member.id.name;
        case AST_NODE_TYPES.TSMethodSignature:
          return util.getNameFromMember(member, sourceCode);
        case AST_NODE_TYPES.TSCallSignatureDeclaration:
          return 'call';
        case AST_NODE_TYPES.TSConstructSignatureDeclaration:
          return 'new';
        case AST_NODE_TYPES.MethodDefinition:
          return util.getNameFromMember(member, sourceCode);
      }

      return null;
    }
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / explicit-function-return-type.ts View on Github external
function isConstructor(node: TSESTree.Node | undefined): boolean {
      return (
        !!node &&
        node.type === AST_NODE_TYPES.MethodDefinition &&
        node.kind === 'constructor'
      );
    }

@typescript-eslint/experimental-utils

(Experimental) Utilities for working with TypeScript + ESLint together

MIT
Latest version published 10 months ago

Package Health Score

85 / 100
Full package analysis