Enable @stylistic/spaced-comment rule (#17941)
This commit is contained in:
1 parent
27b9d59271
commit
c9df58f5f9
19 files changed
+48
-32
No files matched your search
@@ -150,6 +150,7 @@ export default [
|
|||||||
avoidEscape: true,
|
avoidEscape: true,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
"@stylistic/spaced-comment": "error",
|
||||||
|
|
||||||
/* @typescript-eslint/eslint-plugin */
|
/* @typescript-eslint/eslint-plugin */
|
||||||
"@typescript-eslint/prefer-ts-expect-error": "error",
|
"@typescript-eslint/prefer-ts-expect-error": "error",
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function createParseError(error) {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parse(text /*, options */) {
|
function parse(text /* , options */) {
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = parseGraphql(text, parseOptions);
|
ast = parseGraphql(text, parseOptions);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { dedent, hardline, softline } from "../document/builders.js";
|
import { dedent, hardline, softline } from "../document/builders.js";
|
||||||
|
|
||||||
function embed(path /*, options*/) {
|
function embed(path /* , options*/) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
|
|
||||||
if (node.type !== "TextNode") {
|
if (node.type !== "TextNode") {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ const glimmerParseOptions = {
|
|||||||
plugins: { ast: [glimmerPrettierParsePlugin] },
|
plugins: { ast: [glimmerPrettierParsePlugin] },
|
||||||
};
|
};
|
||||||
|
|
||||||
function parse(text /*, options */) {
|
function parse(text /* , options */) {
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = parseGlimmer(text, glimmerParseOptions);
|
ast = parseGlimmer(text, glimmerParseOptions);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ function parseIeConditionalStartComment(node, parseHtml, match) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseIeConditionalEndComment(node /*, parseHtml, match */) {
|
function parseIeConditionalEndComment(node /* , parseHtml, match */) {
|
||||||
return {
|
return {
|
||||||
type: "ieConditionalEndComment",
|
type: "ieConditionalEndComment",
|
||||||
sourceSpan: node.sourceSpan,
|
sourceSpan: node.sourceSpan,
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ import {
|
|||||||
} from "./utils.js";
|
} from "./utils.js";
|
||||||
|
|
||||||
function createAngularPrinter({ parser }) {
|
function createAngularPrinter({ parser }) {
|
||||||
return (textToDoc, print, path /*, options*/) =>
|
return (textToDoc, print, path /* , options*/) =>
|
||||||
formatAttributeValue(
|
formatAttributeValue(
|
||||||
getUnescapedAttributeValue(path.node),
|
getUnescapedAttributeValue(path.node),
|
||||||
textToDoc,
|
textToDoc,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { printExpand } from "./utils.js";
|
|||||||
|
|
||||||
/** @import {Doc} from "../../document/builders.js" */
|
/** @import {Doc} from "../../document/builders.js" */
|
||||||
|
|
||||||
function printSrcset(path /*, options*/) {
|
function printSrcset(path /* , options*/) {
|
||||||
if (
|
if (
|
||||||
path.node.fullName === "srcset" &&
|
path.node.fullName === "srcset" &&
|
||||||
(path.parent.fullName === "img" || path.parent.fullName === "source")
|
(path.parent.fullName === "img" || path.parent.fullName === "source")
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function preprocess(ast, options) {
|
|||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeIgnorableFirstLf(ast /*, options */) {
|
function removeIgnorableFirstLf(ast /* , options */) {
|
||||||
ast.walk((node) => {
|
ast.walk((node) => {
|
||||||
if (
|
if (
|
||||||
node.type === "element" &&
|
node.type === "element" &&
|
||||||
@@ -52,7 +52,7 @@ function removeIgnorableFirstLf(ast /*, options */) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mergeIfConditionalStartEndCommentIntoElementOpeningTag(
|
function mergeIfConditionalStartEndCommentIntoElementOpeningTag(
|
||||||
ast /*, options */,
|
ast /* , options */,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* <!--[if ...]><!--><target><!--<![endif]-->
|
* <!--[if ...]><!--><target><!--<![endif]-->
|
||||||
@@ -129,7 +129,7 @@ function mergeNodeIntoText(ast, shouldMerge, getValue) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeCdataIntoText(ast /*, options */) {
|
function mergeCdataIntoText(ast /* , options */) {
|
||||||
return mergeNodeIntoText(
|
return mergeNodeIntoText(
|
||||||
ast,
|
ast,
|
||||||
(node) => node.type === "cdata",
|
(node) => node.type === "cdata",
|
||||||
@@ -137,7 +137,7 @@ function mergeCdataIntoText(ast /*, options */) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function mergeSimpleElementIntoText(ast /*, options */) {
|
function mergeSimpleElementIntoText(ast /* , options */) {
|
||||||
const isSimpleElement = (node) =>
|
const isSimpleElement = (node) =>
|
||||||
node.type === "element" &&
|
node.type === "element" &&
|
||||||
node.attrs.length === 0 &&
|
node.attrs.length === 0 &&
|
||||||
@@ -327,7 +327,7 @@ function extractWhitespaces(ast, options) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addIsSelfClosing(ast /*, options */) {
|
function addIsSelfClosing(ast /* , options */) {
|
||||||
ast.walk((node) => {
|
ast.walk((node) => {
|
||||||
node.isSelfClosing =
|
node.isSelfClosing =
|
||||||
!node.children ||
|
!node.children ||
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import isNonEmptyArray from "../../utils/is-non-empty-array.js";
|
|||||||
import { printTemplateExpressions } from "../print/template-literal.js";
|
import { printTemplateExpressions } from "../print/template-literal.js";
|
||||||
import { isAngularComponentStyles } from "./utils.js";
|
import { isAngularComponentStyles } from "./utils.js";
|
||||||
|
|
||||||
async function printEmbedCss(textToDoc, print, path /*, options*/) {
|
async function printEmbedCss(textToDoc, print, path /* , options*/) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
|
|
||||||
// Get full template literal with expressions replaced by placeholders
|
// 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 (
|
if (
|
||||||
isStyledJsx(path) ||
|
isStyledJsx(path) ||
|
||||||
isStyledComponents(path) ||
|
isStyledComponents(path) ||
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
} from "../print/template-literal.js";
|
} from "../print/template-literal.js";
|
||||||
import { hasLanguageComment } from "./utils.js";
|
import { hasLanguageComment } from "./utils.js";
|
||||||
|
|
||||||
async function printEmbedGraphQL(textToDoc, print, path /*, options*/) {
|
async function printEmbedGraphQL(textToDoc, print, path /* , options*/) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
|
|
||||||
const numQuasis = node.quasis.length;
|
const numQuasis = node.quasis.length;
|
||||||
@@ -121,7 +121,7 @@ function isGraphQL({ node, parent }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function printGraphql(path /*, options*/) {
|
function printGraphql(path /* , options*/) {
|
||||||
if (isGraphQL(path)) {
|
if (isGraphQL(path)) {
|
||||||
return printEmbedGraphQL;
|
return printEmbedGraphQL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ function isHtml(path) {
|
|||||||
const printEmbedHtml = printEmbedHtmlLike.bind(undefined, "html");
|
const printEmbedHtml = printEmbedHtmlLike.bind(undefined, "html");
|
||||||
const printEmbedAngular = printEmbedHtmlLike.bind(undefined, "angular");
|
const printEmbedAngular = printEmbedHtmlLike.bind(undefined, "angular");
|
||||||
|
|
||||||
function printHtml(path /*, options*/) {
|
function printHtml(path /* , options*/) {
|
||||||
if (isHtml(path)) {
|
if (isHtml(path)) {
|
||||||
return printEmbedHtml;
|
return printEmbedHtml;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
} from "../../document/builders.js";
|
} from "../../document/builders.js";
|
||||||
import { escapeTemplateCharacters } from "../print/template-literal.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;
|
const { node } = path;
|
||||||
let text = node.quasis[0].value.raw.replaceAll(
|
let text = node.quasis[0].value.raw.replaceAll(
|
||||||
/((?:\\\\)*)\\`/gu,
|
/((?:\\\\)*)\\`/gu,
|
||||||
@@ -34,7 +34,7 @@ function getIndentation(str) {
|
|||||||
return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
|
return firstMatchedIndent === null ? "" : firstMatchedIndent[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
function printMarkdown(path /*, options*/) {
|
function printMarkdown(path /* , options*/) {
|
||||||
if (isMarkdown(path)) {
|
if (isMarkdown(path)) {
|
||||||
return printEmbedMarkdown;
|
return printEmbedMarkdown;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const parseOptions = {
|
|||||||
allowReturnOutsideFunction: true,
|
allowReturnOutsideFunction: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function parse(text /*, options*/) {
|
async function parse(text /* , options*/) {
|
||||||
let ast;
|
let ast;
|
||||||
try {
|
try {
|
||||||
ast = await hermesParse(text, parseOptions);
|
ast = await hermesParse(text, parseOptions);
|
||||||
|
|||||||
@@ -743,7 +743,7 @@ function printJsxClosingElement(path, options, print) {
|
|||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
function printJsxOpeningClosingFragment(path, options /*, print*/) {
|
function printJsxOpeningClosingFragment(path, options /* , print*/) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
const nodeHasComment = hasComment(node);
|
const nodeHasComment = hasComment(node);
|
||||||
const hasOwnLineComment = hasComment(node, CommentCheckFlags.Line);
|
const hasOwnLineComment = hasComment(node, CommentCheckFlags.Line);
|
||||||
@@ -772,7 +772,7 @@ function printJsxElement(path, options, print) {
|
|||||||
return maybeWrapJsxElementInParens(path, elem, options);
|
return maybeWrapJsxElementInParens(path, elem, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
function printJsxEmptyExpression(path, options /*, print*/) {
|
function printJsxEmptyExpression(path, options /* , print*/) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
const requiresHardline = hasComment(node, CommentCheckFlags.Line);
|
const requiresHardline = hasComment(node, CommentCheckFlags.Line);
|
||||||
|
|
||||||
@@ -835,9 +835,9 @@ function printJsx(path, options, print) {
|
|||||||
return printJsxClosingElement(path, options, print);
|
return printJsxClosingElement(path, options, print);
|
||||||
case "JSXOpeningFragment":
|
case "JSXOpeningFragment":
|
||||||
case "JSXClosingFragment":
|
case "JSXClosingFragment":
|
||||||
return printJsxOpeningClosingFragment(path, options /*, print*/);
|
return printJsxOpeningClosingFragment(path, options /* , print*/);
|
||||||
case "JSXEmptyExpression":
|
case "JSXEmptyExpression":
|
||||||
return printJsxEmptyExpression(path, options /*, print*/);
|
return printJsxEmptyExpression(path, options /* , print*/);
|
||||||
case "JSXText":
|
case "JSXText":
|
||||||
/* c8 ignore next */
|
/* c8 ignore next */
|
||||||
throw new Error("JSXText should be handled by JSXElement");
|
throw new Error("JSXText should be handled by JSXElement");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import printString from "../../utils/print-string.js";
|
|||||||
* @import {Node} from "../types/estree.js"
|
* @import {Node} from "../types/estree.js"
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function printLiteral(path, options /*, print*/) {
|
function printLiteral(path, options /* , print*/) {
|
||||||
const { node } = path;
|
const { node } = path;
|
||||||
|
|
||||||
switch (node.type) {
|
switch (node.type) {
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const ignoredProperties = new Set([
|
|||||||
"tokens",
|
"tokens",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
function clean(original, cloned /*, parent*/) {
|
function clean(original, cloned /* , parent*/) {
|
||||||
const { type } = original;
|
const { type } = original;
|
||||||
// We print quoted key
|
// We print quoted key
|
||||||
if (type === "ObjectProperty") {
|
if (type === "ObjectProperty") {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ const tokenizeEsComment = (eat, value) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* c8 ignore next 2 */
|
/* c8 ignore next 2 */
|
||||||
tokenizeEsSyntax.locator = (value /*, fromIndex*/) =>
|
tokenizeEsSyntax.locator = (value /* , fromIndex*/) =>
|
||||||
isExport(value) || isImport(value) ? -1 : 1;
|
isExport(value) || isImport(value) ? -1 : 1;
|
||||||
|
|
||||||
tokenizeEsComment.locator = (value, fromIndex) => value.indexOf("{", fromIndex);
|
tokenizeEsComment.locator = (value, fromIndex) => value.indexOf("{", fromIndex);
|
||||||
|
|||||||
@@ -408,7 +408,7 @@ function printFlowScalarContent(nodeType, content, options) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function clean(original, cloned /*, parent */) {
|
function clean(original, cloned /* , parent */) {
|
||||||
if (isNode(original)) {
|
if (isNode(original)) {
|
||||||
switch (original.type) {
|
switch (original.type) {
|
||||||
case "comment":
|
case "comment":
|
||||||
|
|||||||
@@ -181,9 +181,20 @@ const config = {
|
|||||||
to: "/docs/install",
|
to: "/docs/install",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
html: /*html*/ `
|
html: /* HTML */ `
|
||||||
<a href="https://www.netlify.com" target="_blank" rel="noreferrer noopener" aria-label="Deploys by Netlify">
|
<a
|
||||||
<img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" alt="Deploys by Netlify" width="114" height="51" style="margin-top: 8px;" />
|
href="https://www.netlify.com"
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer noopener"
|
||||||
|
aria-label="Deploys by Netlify"
|
||||||
|
>
|
||||||
|
<img
|
||||||
|
src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg"
|
||||||
|
alt="Deploys by Netlify"
|
||||||
|
width="114"
|
||||||
|
height="51"
|
||||||
|
style="margin-top: 8px;"
|
||||||
|
/>
|
||||||
</a>
|
</a>
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@@ -222,7 +233,7 @@ const config = {
|
|||||||
href: `${GITHUB_URL}/issues`,
|
href: `${GITHUB_URL}/issues`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
html: /*html*/ `
|
html: /* HTML */ `
|
||||||
<a
|
<a
|
||||||
href="https://github.com/prettier/prettier"
|
href="https://github.com/prettier/prettier"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
@@ -230,7 +241,11 @@ const config = {
|
|||||||
aria-label="Star this project on GitHub"
|
aria-label="Star this project on GitHub"
|
||||||
class="footer__github-stars"
|
class="footer__github-stars"
|
||||||
>
|
>
|
||||||
<img src="https://img.shields.io/github/stars/prettier/prettier?style=social" loading="lazy" alt="Star this project on GitHub" />
|
<img
|
||||||
|
src="https://img.shields.io/github/stars/prettier/prettier?style=social"
|
||||||
|
loading="lazy"
|
||||||
|
alt="Star this project on GitHub"
|
||||||
|
/>
|
||||||
</a>
|
</a>
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in new issue
Block a user