in src/Linters/DontHaveTwoEmptyLinesInARowLinter.hack [20:78]
public function getLintErrorForNode(
this::TContext $context,
this::TNode $token,
): ?ASTLintError {
if ($this->entireScriptIsClean($context)) {
return null;
}
if (!Str\contains($token->getCode(), \PHP_EOL.\PHP_EOL)) {
// We check for 2 eols, because the previous token may have the first.
return null;
}
$eol_count = $this->getAST()
->getPreviousToken($token)
?->getTrailing()
?->getLast()
|> $$ is EndOfLine ? 1 : 0;
$remove_leading = vec[];
$remove_trailing = vec[];
foreach ($token->getLeading()->toVec() as $trivia) {
if ($trivia is EndOfLine) {
$eol_count++;
if ($eol_count >= 3) {
$remove_leading[] = $trivia;
}
} else {
$eol_count = 0;
}
}
// We don't check the boundary with the next token.
// This will be checked by the loop above when linting
// that token instead.
$eol_count = 0;
foreach ($token->getTrailing()->toVec() as $trivia) {
if ($trivia is EndOfLine) {
$eol_count++;
if ($eol_count >= 3) {
$remove_trailing[] = $trivia;
}
} else {
$eol_count = 0;
}
}
if (C\is_empty($remove_leading) && C\is_empty($remove_trailing)) {
return null;
}
return new ASTLintError(
$this,
"Don't have two empty lines in a row",
$token,
() ==> static::removeTrivia($token, $remove_leading, $remove_trailing),
);
}