How to use the eslint-utils.isOpeningParenToken function in eslint-utils

To help you get started, we’ve selected a few eslint-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 sikidamjanovic / cowrite / node_modules / @typescript-eslint / eslint-plugin / dist / rules / indent-new-do-not-use / index.js View on Github external
NewExpression(node) {
                // Only indent the arguments if the NewExpression has parens (e.g. `new Foo(bar)` or `new Foo()`, but not `new Foo`
                if (node.arguments.length > 0 ||
                    (eslint_utils_1.isClosingParenToken(sourceCode.getLastToken(node)) &&
                        eslint_utils_1.isOpeningParenToken(sourceCode.getLastToken(node, 1)))) {
                    addFunctionCallIndent(node);
                }
            },
            'ObjectExpression, ObjectPattern'(node) {
github sikidamjanovic / cowrite / node_modules / @typescript-eslint / eslint-plugin / dist / rules / indent-new-do-not-use / index.js View on Github external
function getFirstToken(element) {
                let token = sourceCode.getTokenBefore(element);
                while (eslint_utils_1.isOpeningParenToken(token) && token !== startToken) {
                    token = sourceCode.getTokenBefore(token);
                }
                return sourceCode.getTokenAfter(token);
            }
            // Run through all the tokens in the list, and offset them by one indent level (mainly for comments, other things will end up overridden)
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
NewExpression(node) {
        // Only indent the arguments if the NewExpression has parens (e.g. `new Foo(bar)` or `new Foo()`, but not `new Foo`
        if (
          node.arguments.length > 0 ||
          (isClosingParenToken(sourceCode.getLastToken(node)!) &&
            isOpeningParenToken(sourceCode.getLastToken(node, 1)!))
        ) {
          addFunctionCallIndent(node);
        }
      },
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 / indent-new-do-not-use / index.ts View on Github external
tokens.forEach(nextToken => {
        // Accumulate a list of parenthesis pairs
        if (isOpeningParenToken(nextToken)) {
          parenStack.push(nextToken);
        } else if (isClosingParenToken(nextToken)) {
          parenPairs.unshift({ left: parenStack.pop()!, right: nextToken });
        }
      });
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
function getFirstToken(element: TSESTree.Node): TSESTree.Token {
        let token = sourceCode.getTokenBefore(element)!;

        while (isOpeningParenToken(token) && token !== startToken) {
          token = sourceCode.getTokenBefore(token)!;
        }
        return sourceCode.getTokenAfter(token)!;
      }
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)!;
        }

        offsets.setDesiredOffsets(
          [firstBodyToken.range[0], lastBodyToken.range[1]],
          lastParentToken,
          1,
        );

        /*
         * For blockless nodes with semicolon-first style, don't indent the semicolon.
         * e.g.
         * if (foo) bar()
github typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
ArrowFunctionExpression(node) {
        const firstToken = sourceCode.getFirstToken(node)!;

        if (isOpeningParenToken(firstToken)) {
          const openingParen = firstToken;
          const closingParen = sourceCode.getTokenBefore(
            node.body,
            isClosingParenToken,
          )!;

          parameterParens.add(openingParen);
          parameterParens.add(closingParen);
          addElementListIndent(
            node.params,
            openingParen,
            closingParen,
            options.FunctionExpression.parameters!,
          );
        }
        addBlocklessNodeIndent(node.body);
github sikidamjanovic / cowrite / node_modules / @typescript-eslint / eslint-plugin / dist / rules / indent-new-do-not-use / index.js View on Github external
ArrowFunctionExpression(node) {
                const firstToken = sourceCode.getFirstToken(node);
                if (eslint_utils_1.isOpeningParenToken(firstToken)) {
                    const openingParen = firstToken;
                    const closingParen = sourceCode.getTokenBefore(node.body, eslint_utils_1.isClosingParenToken);
                    parameterParens.add(openingParen);
                    parameterParens.add(closingParen);
                    addElementListIndent(node.params, openingParen, closingParen, options.FunctionExpression.parameters);
                }
                addBlocklessNodeIndent(node.body);
            },
            AssignmentExpression(node) {