How to use the eslint-utils.isCommentToken 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 typescript-eslint / typescript-eslint / packages / eslint-plugin / src / rules / indent-new-do-not-use / index.ts View on Github external
if (firstTokenOfLine.loc.start.line !== lineNumber) {
            // Don't check the indentation of multi-line tokens (e.g. template literals or block comments) twice.
            return;
          }

          // If the token matches the expected expected indentation, don't report it.
          if (
            validateTokenIndent(
              firstTokenOfLine,
              offsets.getDesiredIndent(firstTokenOfLine),
            )
          ) {
            return;
          }

          if (isCommentToken(firstTokenOfLine)) {
            const tokenBefore = precedingTokens.get(firstTokenOfLine);
            const tokenAfter = tokenBefore
              ? sourceCode.getTokenAfter(tokenBefore)!
              : sourceCode.ast.tokens[0];

            const mayAlignWithBefore =
              tokenBefore &&
              !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
            const mayAlignWithAfter =
              tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);

            // If a comment matches the expected indentation of the token immediately before or after, don't report it.
            if (
              (mayAlignWithBefore &&
                validateTokenIndent(
                  firstTokenOfLine,
github sikidamjanovic / cowrite / node_modules / @typescript-eslint / eslint-plugin / dist / rules / indent-new-do-not-use / index.js View on Github external
sourceCode.lines.forEach((_, lineIndex) => {
                    const lineNumber = lineIndex + 1;
                    if (!tokenInfo.firstTokensByLineNumber.has(lineNumber)) {
                        // Don't check indentation on blank lines
                        return;
                    }
                    const firstTokenOfLine = tokenInfo.firstTokensByLineNumber.get(lineNumber);
                    if (firstTokenOfLine.loc.start.line !== lineNumber) {
                        // Don't check the indentation of multi-line tokens (e.g. template literals or block comments) twice.
                        return;
                    }
                    // If the token matches the expected expected indentation, don't report it.
                    if (validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(firstTokenOfLine))) {
                        return;
                    }
                    if (eslint_utils_1.isCommentToken(firstTokenOfLine)) {
                        const tokenBefore = precedingTokens.get(firstTokenOfLine);
                        const tokenAfter = tokenBefore
                            ? sourceCode.getTokenAfter(tokenBefore)
                            : sourceCode.ast.tokens[0];
                        const mayAlignWithBefore = tokenBefore &&
                            !hasBlankLinesBetween(tokenBefore, firstTokenOfLine);
                        const mayAlignWithAfter = tokenAfter && !hasBlankLinesBetween(firstTokenOfLine, tokenAfter);
                        // If a comment matches the expected indentation of the token immediately before or after, don't report it.
                        if ((mayAlignWithBefore &&
                            validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenBefore))) ||
                            (mayAlignWithAfter &&
                                validateTokenIndent(firstTokenOfLine, offsets.getDesiredIndent(tokenAfter)))) {
                            return;
                        }
                    }
                    // Otherwise, report the token/comment.
github eslint / eslint / lib / source-code / source-code.js View on Github external
node.type === "SwitchStatement" && node.cases.length === 0
            ) {
                comments.trailing = this.getTokens(node, {
                    includeComments: true,
                    filter: isCommentToken
                });
            }

            /*
             * Iterate over tokens before and after node and collect comment tokens.
             * Do not include comments that exist outside of the parent node
             * to avoid duplication.
             */
            let currentToken = this.getTokenBefore(node, { includeComments: true });

            while (currentToken && isCommentToken(currentToken)) {
                if (node.parent && (currentToken.start < node.parent.start)) {
                    break;
                }
                comments.leading.push(currentToken);
                currentToken = this.getTokenBefore(currentToken, { includeComments: true });
            }

            comments.leading.reverse();

            currentToken = this.getTokenAfter(node, { includeComments: true });

            while (currentToken && isCommentToken(currentToken)) {
                if (node.parent && (currentToken.end > node.parent.end)) {
                    break;
                }
                comments.trailing.push(currentToken);
github eslint / eslint / lib / source-code / token-store / index.js View on Github external
function getAdjacentCommentTokensFromCursor(cursor) {
    const tokens = [];
    let currentToken = cursor.getOneToken();

    while (currentToken && isCommentToken(currentToken)) {
        tokens.push(currentToken);
        currentToken = cursor.getOneToken();
    }

    return tokens;
}
github eslint / eslint / lib / source-code / source-code.js View on Github external
*/
            let currentToken = this.getTokenBefore(node, { includeComments: true });

            while (currentToken && isCommentToken(currentToken)) {
                if (node.parent && (currentToken.start < node.parent.start)) {
                    break;
                }
                comments.leading.push(currentToken);
                currentToken = this.getTokenBefore(currentToken, { includeComments: true });
            }

            comments.leading.reverse();

            currentToken = this.getTokenAfter(node, { includeComments: true });

            while (currentToken && isCommentToken(currentToken)) {
                if (node.parent && (currentToken.end > node.parent.end)) {
                    break;
                }
                comments.trailing.push(currentToken);
                currentToken = this.getTokenAfter(currentToken, { includeComments: true });
            }
        }

        this._commentCache.set(node, comments);
        return comments;
    }
github eslint / eslint / lib / source-code / source-code.js View on Github external
const findJSDocComment = astNode => {
            const tokenBefore = this.getTokenBefore(astNode, { includeComments: true });

            if (
                tokenBefore &&
                isCommentToken(tokenBefore) &&
                tokenBefore.type === "Block" &&
                tokenBefore.value.charAt(0) === "*" &&
                astNode.loc.start.line - tokenBefore.loc.end.line <= 1
            ) {
                return tokenBefore;
            }

            return null;
        };
        let parent = node.parent;