Fix inconsistent language comment detection (#9743)
This commit is contained in:
1 parent
25d53fa9b3
commit
664d0d33b5
6 files changed
+46
-20
No files matched your search
@@ -19,8 +19,6 @@ const {
|
||||
hasFlowShorthandAnnotationComment,
|
||||
hasFlowAnnotationComment,
|
||||
hasIgnoreComment,
|
||||
hasComment,
|
||||
CommentCheckFlags,
|
||||
} = require("./utils");
|
||||
const { locStart, locEnd } = require("./loc");
|
||||
|
||||
@@ -866,18 +864,6 @@ function handleTSMappedTypeComments({
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @param {(comment: Comment) => boolean} fn
|
||||
* @returns boolean
|
||||
*/
|
||||
function hasLeadingComment(node, fn = () => true) {
|
||||
if (node.leadingComments) {
|
||||
return node.leadingComments.some(fn);
|
||||
}
|
||||
return hasComment(node, CommentCheckFlags.Leading, fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node
|
||||
* @returns {boolean}
|
||||
@@ -994,7 +980,6 @@ module.exports = {
|
||||
handleOwnLineComment,
|
||||
handleEndOfLineComment,
|
||||
handleRemainingComment,
|
||||
hasLeadingComment,
|
||||
isTypeCastComment,
|
||||
getGapRegex,
|
||||
getCommentChildNodes,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
const { isBlockComment } = require("./utils");
|
||||
const { hasLeadingComment } = require("./comments");
|
||||
const { hasComment, CommentCheckFlags } = require("./utils");
|
||||
const formatMarkdown = require("./embed/markdown");
|
||||
const formatCss = require("./embed/css");
|
||||
const formatGraphql = require("./embed/graphql");
|
||||
@@ -267,10 +266,10 @@ function hasLanguageComment(node, languageName) {
|
||||
// we will not trim the comment value and we will expect exactly one space on
|
||||
// either side of the GraphQL string
|
||||
// Also see ./clean.js
|
||||
return hasLeadingComment(
|
||||
return hasComment(
|
||||
node,
|
||||
(comment) =>
|
||||
isBlockComment(comment) && comment.value === ` ${languageName} `
|
||||
CommentCheckFlags.Block | CommentCheckFlags.Leading,
|
||||
({ value }) => value === ` ${languageName} `
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user