Simplify needsHardlineAfterDanglingComment (#18797)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
fisker Cheungandautofix-ci[bot] authored and GitHub committed 2026-01-30 10:55:52 +08:00
1 parent 3ff9bf78d8
commit 0844e463c9
14 files changed
+35 -44

No files matched your search

+1 -2
View File
@@ -11,10 +11,9 @@ import isNonEmptyArray from "../../utilities/is-non-empty-array.js";
import { locEnd, locStart } from "../loc.js";
import { getCallArguments } from "../utilities/call-arguments.js";
import { isInsideCallOrNewExpressionParentheses } from "../utilities/call-or-new-expression-parentheses.js";
import { isBlockComment, isLineComment } from "../utilities/comment-types.js";
import { createTypeCheckFunction } from "../utilities/create-type-check-function.js";
import { getFunctionParameters } from "../utilities/function-parameters.js";
import { isBlockComment } from "../utilities/is-block-comment.js";
import { isLineComment } from "../utilities/is-line-comment.js";
import { isMethod } from "../utilities/is-method.js";
import { isObjectProperty } from "../utilities/is-object-property.js";
import { isPrettierIgnoreComment } from "../utilities/is-prettier-ignore-comment.js";
+7 -2
View File
@@ -1,10 +1,12 @@
import * as assert from "#universal/assert";
import { commentsPropertyInOptions } from "../../../constants.js";
import { locEnd, locEndWithFullText, locStart } from "../../loc.js";
import {
isBlockComment,
isLineComment,
} from "../../utilities/comment-types.js";
import { createTypeCheckFunction } from "../../utilities/create-type-check-function.js";
import { getRaw } from "../../utilities/get-raw.js";
import { isBlockComment } from "../../utilities/is-block-comment.js";
import { isLineComment } from "../../utilities/is-line-comment.js";
import { isTypeCastComment } from "../../utilities/is-type-cast-comment.js";
import { stripComments } from "../../utilities/strip-comments.js";
import { mergeNestledJsdocComments } from "./merge-nestled-jsdoc-comments.js";
@@ -252,7 +254,10 @@ function assertComments(comments, text) {
// Flow
const closingMark = commentText.endsWith("*-/") ? "*-/" : "*/";
assert.equal("/*" + comment.value + closingMark, commentText);
return;
}
throw new Error(`Unknown comment type '${comment.type}'.`);
}
}
@@ -1,7 +1,9 @@
import { locEnd, locStart } from "../../loc.js";
import { isBlockComment } from "../../utilities/is-block-comment.js";
import {
isBlockComment,
isLineComment,
} from "../../utilities/comment-types.js";
import isIndentableBlockComment from "../../utilities/is-indentable-block-comment.js";
import { isLineComment } from "../../utilities/is-line-comment.js";
function mergeNestledJsdocComments(comments) {
if (comments.length < 2) {
+1 -2
View File
@@ -5,9 +5,8 @@ import {
replaceEndOfLine,
} from "../../document/index.js";
import { locEnd, locStart } from "../loc.js";
import { isBlockComment } from "../utilities/is-block-comment.js";
import { isBlockComment, isLineComment } from "../utilities/comment-types.js";
import isIndentableBlockComment from "../utilities/is-indentable-block-comment.js";
import { isLineComment } from "../utilities/is-line-comment.js";
/**
@import {Doc} from "../../document/index.js"
+1 -1
View File
@@ -10,8 +10,8 @@ import { printDanglingComments } from "../../main/comments/print.js";
import hasNewline from "../../utilities/has-newline.js";
import hasNewlineInRange from "../../utilities/has-newline-in-range.js";
import { locEnd, locStart } from "../loc.js";
import { isLineComment } from "../utilities/comment-types.js";
import { CommentCheckFlags, getComments } from "../utilities/comments.js";
import { isLineComment } from "../utilities/is-line-comment.js";
import { stripComments } from "../utilities/strip-comments.js";
import { printClassMemberSemicolon } from "./class.js";
+1 -1
View File
@@ -12,12 +12,12 @@ import { printDanglingComments } from "../../main/comments/print.js";
import hasNewlineInRange from "../../utilities/has-newline-in-range.js";
import { locEnd, locStart } from "../loc.js";
import needsParentheses from "../parentheses/needs-parentheses.js";
import { isBlockComment } from "../utilities/comment-types.js";
import {
CommentCheckFlags,
getComments,
hasComment,
} from "../utilities/comments.js";
import { isBlockComment } from "../utilities/is-block-comment.js";
import { isLoneShortArgument } from "../utilities/is-lone-short-argument.js";
import { isSimpleExpressionByNodeCount } from "../utilities/is-simple-expression-by-node-count.js";
import {
+1 -1
View File
@@ -1,8 +1,8 @@
import { indent, softline } from "../../document/index.js";
import hasNewline from "../../utilities/has-newline.js";
import { locEnd, locStart } from "../loc.js";
import { isBlockComment } from "../utilities/comment-types.js";
import { hasComment } from "../utilities/comments.js";
import { isBlockComment } from "../utilities/is-block-comment.js";
function printTryStatement(path, options, print) {
const { node } = path;
+1 -1
View File
@@ -9,7 +9,7 @@ import { insertPragma } from "./pragma.js";
import { printComment } from "./print/comment.js";
import { printEstree } from "./print/index.js";
import getVisitorKeys from "./traverse/get-visitor-keys.js";
import { isBlockComment } from "./utilities/is-block-comment.js";
import { isBlockComment } from "./utilities/comment-types.js";
import hasPrettierIgnore from "./utilities/is-ignored.js";
const features = {
@@ -4,6 +4,17 @@ import { createTypeCheckFunction } from "./create-type-check-function.js";
@import {Comment} from "../types/estree.js";
*/
/**
* @param {Comment} comment
* @returns {boolean}
*/
const isBlockComment = createTypeCheckFunction([
"Block",
"CommentBlock",
// `meriyah`
"MultiLine",
]);
const isLineComment = createTypeCheckFunction([
"Line",
"CommentLine",
@@ -18,4 +29,4 @@ const isLineComment = createTypeCheckFunction([
"InterpreterDirective",
]);
export { isLineComment };
export { isBlockComment, isLineComment };
+1 -2
View File
@@ -1,6 +1,5 @@
import isNonEmptyArray from "../../utilities/is-non-empty-array.js";
import { isBlockComment } from "./is-block-comment.js";
import { isLineComment } from "./is-line-comment.js";
import { isBlockComment, isLineComment } from "./comment-types.js";
import { isPrettierIgnoreComment } from "./is-prettier-ignore-comment.js";
/**
@@ -1,18 +0,0 @@
import { createTypeCheckFunction } from "./create-type-check-function.js";
/**
@import {Comment} from "../types/estree.js";
*/
/**
* @param {Comment} comment
* @returns {boolean}
*/
const isBlockComment = createTypeCheckFunction([
"Block",
"CommentBlock",
// `meriyah`
"MultiLine",
]);
export { isBlockComment };
@@ -1,4 +1,4 @@
import { isBlockComment } from "./is-block-comment.js";
import { isBlockComment } from "./comment-types.js";
function isIndentableBlockCommentInternal(comment) {
/*
@@ -1,4 +1,4 @@
import { isBlockComment } from "./is-block-comment.js";
import { isBlockComment } from "./comment-types.js";
/**
@import {Comment} from "../types/estree.js"
@@ -1,5 +1,5 @@
import { CommentCheckFlags, getComments, hasComment } from "./comments.js";
import { isBlockComment } from "./is-block-comment.js";
import { isLineComment } from "./comment-types.js";
import { CommentCheckFlags, getComments } from "./comments.js";
/**
@import {
@@ -12,13 +12,7 @@ import { isBlockComment } from "./is-block-comment.js";
* @returns {boolean}
*/
function needsHardlineAfterDanglingComment(node) {
if (!hasComment(node)) {
return false;
}
const lastDanglingComment = getComments(node, CommentCheckFlags.Dangling).at(
-1,
);
return lastDanglingComment && !isBlockComment(lastDanglingComment);
return isLineComment(getComments(node, CommentCheckFlags.Dangling).at(-1));
}
export { needsHardlineAfterDanglingComment };