From c9df58f5f915428c67a6a424bd0d957ad30558b2 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 23 Sep 2025 17:24:03 +0800 Subject: [PATCH] Enable `@stylistic/spaced-comment` rule (#17941) --- eslint.config.js | 1 + src/language-graphql/parser-graphql.js | 2 +- src/language-handlebars/embed.js | 2 +- src/language-handlebars/parser-glimmer.js | 2 +- src/language-html/conditional-comment.js | 2 +- src/language-html/embed/angular-attributes.js | 2 +- src/language-html/embed/srcset.js | 2 +- src/language-html/print-preprocess.js | 10 ++++---- src/language-js/embed/css.js | 4 +-- src/language-js/embed/graphql.js | 4 +-- src/language-js/embed/html.js | 2 +- src/language-js/embed/markdown.js | 4 +-- src/language-js/parse/hermes.js | 2 +- src/language-js/print/jsx.js | 8 +++--- src/language-js/print/literal.js | 2 +- src/language-json/printer-estree-json.js | 2 +- src/language-markdown/mdx.js | 2 +- src/language-yaml/printer-yaml.js | 2 +- website/docusaurus.config.js | 25 +++++++++++++++---- 19 files changed, 48 insertions(+), 32 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index b54f892e5..985802cd1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -150,6 +150,7 @@ export default [ avoidEscape: true, }, ], + "@stylistic/spaced-comment": "error", /* @typescript-eslint/eslint-plugin */ "@typescript-eslint/prefer-ts-expect-error": "error", diff --git a/src/language-graphql/parser-graphql.js b/src/language-graphql/parser-graphql.js index d833863f5..400fc68de 100644 --- a/src/language-graphql/parser-graphql.js +++ b/src/language-graphql/parser-graphql.js @@ -32,7 +32,7 @@ function createParseError(error) { return error; } -function parse(text /*, options */) { +function parse(text /* , options */) { let ast; try { ast = parseGraphql(text, parseOptions); diff --git a/src/language-handlebars/embed.js b/src/language-handlebars/embed.js index 3256fbabc..b0b10b6ea 100644 --- a/src/language-handlebars/embed.js +++ b/src/language-handlebars/embed.js @@ -1,6 +1,6 @@ import { dedent, hardline, softline } from "../document/builders.js"; -function embed(path /*, options*/) { +function embed(path /* , options*/) { const { node } = path; if (node.type !== "TextNode") { diff --git a/src/language-handlebars/parser-glimmer.js b/src/language-handlebars/parser-glimmer.js index ed5bc012d..66fa2b1d2 100644 --- a/src/language-handlebars/parser-glimmer.js +++ b/src/language-handlebars/parser-glimmer.js @@ -57,7 +57,7 @@ const glimmerParseOptions = { plugins: { ast: [glimmerPrettierParsePlugin] }, }; -function parse(text /*, options */) { +function parse(text /* , options */) { let ast; try { ast = parseGlimmer(text, glimmerParseOptions); diff --git a/src/language-html/conditional-comment.js b/src/language-html/conditional-comment.js index 70c349919..21b79979f 100644 --- a/src/language-html/conditional-comment.js +++ b/src/language-html/conditional-comment.js @@ -72,7 +72,7 @@ function parseIeConditionalStartComment(node, parseHtml, match) { }; } -function parseIeConditionalEndComment(node /*, parseHtml, match */) { +function parseIeConditionalEndComment(node /* , parseHtml, match */) { return { type: "ieConditionalEndComment", sourceSpan: node.sourceSpan, diff --git a/src/language-html/embed/angular-attributes.js b/src/language-html/embed/angular-attributes.js index b3a48627e..b5f422ec1 100644 --- a/src/language-html/embed/angular-attributes.js +++ b/src/language-html/embed/angular-attributes.js @@ -14,7 +14,7 @@ import { } from "./utils.js"; function createAngularPrinter({ parser }) { - return (textToDoc, print, path /*, options*/) => + return (textToDoc, print, path /* , options*/) => formatAttributeValue( getUnescapedAttributeValue(path.node), textToDoc, diff --git a/src/language-html/embed/srcset.js b/src/language-html/embed/srcset.js index f818f7823..09f13fec6 100644 --- a/src/language-html/embed/srcset.js +++ b/src/language-html/embed/srcset.js @@ -5,7 +5,7 @@ import { printExpand } from "./utils.js"; /** @import {Doc} from "../../document/builders.js" */ -function printSrcset(path /*, options*/) { +function printSrcset(path /* , options*/) { if ( path.node.fullName === "srcset" && (path.parent.fullName === "img" || path.parent.fullName === "source") diff --git a/src/language-html/print-preprocess.js b/src/language-html/print-preprocess.js index 4a7aa1fbb..bdb26b3ce 100644 --- a/src/language-html/print-preprocess.js +++ b/src/language-html/print-preprocess.js @@ -32,7 +32,7 @@ function preprocess(ast, options) { return ast; } -function removeIgnorableFirstLf(ast /*, options */) { +function removeIgnorableFirstLf(ast /* , options */) { ast.walk((node) => { if ( node.type === "element" && @@ -52,7 +52,7 @@ function removeIgnorableFirstLf(ast /*, options */) { } function mergeIfConditionalStartEndCommentIntoElementOpeningTag( - ast /*, options */, + ast /* , options */, ) { /** * @@ -129,7 +129,7 @@ function mergeNodeIntoText(ast, shouldMerge, getValue) { }); } -function mergeCdataIntoText(ast /*, options */) { +function mergeCdataIntoText(ast /* , options */) { return mergeNodeIntoText( ast, (node) => node.type === "cdata", @@ -137,7 +137,7 @@ function mergeCdataIntoText(ast /*, options */) { ); } -function mergeSimpleElementIntoText(ast /*, options */) { +function mergeSimpleElementIntoText(ast /* , options */) { const isSimpleElement = (node) => node.type === "element" && node.attrs.length === 0 && @@ -327,7 +327,7 @@ function extractWhitespaces(ast, options) { }); } -function addIsSelfClosing(ast /*, options */) { +function addIsSelfClosing(ast /* , options */) { ast.walk((node) => { node.isSelfClosing = !node.children || diff --git a/src/language-js/embed/css.js b/src/language-js/embed/css.js index ac62beea2..65c0c0c35 100644 --- a/src/language-js/embed/css.js +++ b/src/language-js/embed/css.js @@ -4,7 +4,7 @@ import isNonEmptyArray from "../../utils/is-non-empty-array.js"; import { printTemplateExpressions } from "../print/template-literal.js"; import { isAngularComponentStyles } from "./utils.js"; -async function printEmbedCss(textToDoc, print, path /*, options*/) { +async function printEmbedCss(textToDoc, print, path /* , options*/) { const { node } = path; // Get full template literal with expressions replaced by placeholders @@ -157,7 +157,7 @@ function isCssProp({ parent, grandparent }) { ); } -function printCss(path /*, options*/) { +function printCss(path /* , options*/) { if ( isStyledJsx(path) || isStyledComponents(path) || diff --git a/src/language-js/embed/graphql.js b/src/language-js/embed/graphql.js index 0f817aa74..347f70257 100644 --- a/src/language-js/embed/graphql.js +++ b/src/language-js/embed/graphql.js @@ -5,7 +5,7 @@ import { } from "../print/template-literal.js"; import { hasLanguageComment } from "./utils.js"; -async function printEmbedGraphQL(textToDoc, print, path /*, options*/) { +async function printEmbedGraphQL(textToDoc, print, path /* , options*/) { const { node } = path; const numQuasis = node.quasis.length; @@ -121,7 +121,7 @@ function isGraphQL({ node, parent }) { ); } -function printGraphql(path /*, options*/) { +function printGraphql(path /* , options*/) { if (isGraphQL(path)) { return printEmbedGraphQL; } diff --git a/src/language-js/embed/html.js b/src/language-js/embed/html.js index ae293e903..21abc8c71 100644 --- a/src/language-js/embed/html.js +++ b/src/language-js/embed/html.js @@ -123,7 +123,7 @@ function isHtml(path) { const printEmbedHtml = printEmbedHtmlLike.bind(undefined, "html"); const printEmbedAngular = printEmbedHtmlLike.bind(undefined, "angular"); -function printHtml(path /*, options*/) { +function printHtml(path /* , options*/) { if (isHtml(path)) { return printEmbedHtml; } diff --git a/src/language-js/embed/markdown.js b/src/language-js/embed/markdown.js index 705f69cd4..35de137fb 100644 --- a/src/language-js/embed/markdown.js +++ b/src/language-js/embed/markdown.js @@ -6,7 +6,7 @@ import { } from "../../document/builders.js"; import { escapeTemplateCharacters } from "../print/template-literal.js"; -async function printEmbedMarkdown(textToDoc, print, path /*, options*/) { +async function printEmbedMarkdown(textToDoc, print, path /* , options*/) { const { node } = path; let text = node.quasis[0].value.raw.replaceAll( /((?:\\\\)*)\\`/gu, @@ -34,7 +34,7 @@ function getIndentation(str) { return firstMatchedIndent === null ? "" : firstMatchedIndent[1]; } -function printMarkdown(path /*, options*/) { +function printMarkdown(path /* , options*/) { if (isMarkdown(path)) { return printEmbedMarkdown; } diff --git a/src/language-js/parse/hermes.js b/src/language-js/parse/hermes.js index 5416e0eb0..0dd3d34a7 100644 --- a/src/language-js/parse/hermes.js +++ b/src/language-js/parse/hermes.js @@ -37,7 +37,7 @@ const parseOptions = { allowReturnOutsideFunction: true, }; -async function parse(text /*, options*/) { +async function parse(text /* , options*/) { let ast; try { ast = await hermesParse(text, parseOptions); diff --git a/src/language-js/print/jsx.js b/src/language-js/print/jsx.js index b1281959e..aeab8a792 100644 --- a/src/language-js/print/jsx.js +++ b/src/language-js/print/jsx.js @@ -743,7 +743,7 @@ function printJsxClosingElement(path, options, print) { return parts; } -function printJsxOpeningClosingFragment(path, options /*, print*/) { +function printJsxOpeningClosingFragment(path, options /* , print*/) { const { node } = path; const nodeHasComment = hasComment(node); const hasOwnLineComment = hasComment(node, CommentCheckFlags.Line); @@ -772,7 +772,7 @@ function printJsxElement(path, options, print) { return maybeWrapJsxElementInParens(path, elem, options); } -function printJsxEmptyExpression(path, options /*, print*/) { +function printJsxEmptyExpression(path, options /* , print*/) { const { node } = path; const requiresHardline = hasComment(node, CommentCheckFlags.Line); @@ -835,9 +835,9 @@ function printJsx(path, options, print) { return printJsxClosingElement(path, options, print); case "JSXOpeningFragment": case "JSXClosingFragment": - return printJsxOpeningClosingFragment(path, options /*, print*/); + return printJsxOpeningClosingFragment(path, options /* , print*/); case "JSXEmptyExpression": - return printJsxEmptyExpression(path, options /*, print*/); + return printJsxEmptyExpression(path, options /* , print*/); case "JSXText": /* c8 ignore next */ throw new Error("JSXText should be handled by JSXElement"); diff --git a/src/language-js/print/literal.js b/src/language-js/print/literal.js index 25fd9c35b..af8a2e567 100644 --- a/src/language-js/print/literal.js +++ b/src/language-js/print/literal.js @@ -6,7 +6,7 @@ import printString from "../../utils/print-string.js"; * @import {Node} from "../types/estree.js" */ -function printLiteral(path, options /*, print*/) { +function printLiteral(path, options /* , print*/) { const { node } = path; switch (node.type) { diff --git a/src/language-json/printer-estree-json.js b/src/language-json/printer-estree-json.js index 6987bb4b2..bb5521d28 100644 --- a/src/language-json/printer-estree-json.js +++ b/src/language-json/printer-estree-json.js @@ -80,7 +80,7 @@ const ignoredProperties = new Set([ "tokens", ]); -function clean(original, cloned /*, parent*/) { +function clean(original, cloned /* , parent*/) { const { type } = original; // We print quoted key if (type === "ObjectProperty") { diff --git a/src/language-markdown/mdx.js b/src/language-markdown/mdx.js index 09b5d5bb4..3dd36a77a 100644 --- a/src/language-markdown/mdx.js +++ b/src/language-markdown/mdx.js @@ -56,7 +56,7 @@ const tokenizeEsComment = (eat, value) => { }; /* c8 ignore next 2 */ -tokenizeEsSyntax.locator = (value /*, fromIndex*/) => +tokenizeEsSyntax.locator = (value /* , fromIndex*/) => isExport(value) || isImport(value) ? -1 : 1; tokenizeEsComment.locator = (value, fromIndex) => value.indexOf("{", fromIndex); diff --git a/src/language-yaml/printer-yaml.js b/src/language-yaml/printer-yaml.js index 8a15b3757..0d816bd51 100644 --- a/src/language-yaml/printer-yaml.js +++ b/src/language-yaml/printer-yaml.js @@ -408,7 +408,7 @@ function printFlowScalarContent(nodeType, content, options) { ); } -function clean(original, cloned /*, parent */) { +function clean(original, cloned /* , parent */) { if (isNode(original)) { switch (original.type) { case "comment": diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index a2d2b8767..a9ff79675 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -181,9 +181,20 @@ const config = { to: "/docs/install", }, { - html: /*html*/ ` - - Deploys by Netlify + html: /* HTML */ ` + + Deploys by Netlify `, }, @@ -222,7 +233,7 @@ const config = { href: `${GITHUB_URL}/issues`, }, { - html: /*html*/ ` + html: /* HTML */ ` - Star this project on GitHub + Star this project on GitHub `, },