Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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,
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.
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);
function getAdjacentCommentTokensFromCursor(cursor) {
const tokens = [];
let currentToken = cursor.getOneToken();
while (currentToken && isCommentToken(currentToken)) {
tokens.push(currentToken);
currentToken = cursor.getOneToken();
}
return tokens;
}
*/
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;
}
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;