Files
SnowLuma/.pnpm-store/v11/files/de/024e1a285bf7250df9ac4bb83be3f5a4782726d6aaf0e51f101460dad2d3e0b9cebc98d5d90fe3de70be34bc4daeded8bae52b807ecf5d506658da16bddd53
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

50 lines
1.4 KiB
Plaintext

import { J as isSurroundedBy, f as createRule, q as isStringLiteral } from "../utils.js";
const QUOTE_SETTINGS = {
"prefer-double": {
quote: "\"",
description: "singlequote",
convert(str) {
return str.replace(/'/gu, "\"");
}
},
"prefer-single": {
quote: "'",
description: "doublequote",
convert(str) {
return str.replace(/"/gu, "'");
}
}
};
var jsx_quotes_default = createRule({
name: "jsx-quotes",
meta: {
type: "layout",
docs: { description: "Enforce the consistent use of either double or single quotes in JSX attributes" },
fixable: "whitespace",
schema: [{
type: "string",
enum: ["prefer-single", "prefer-double"]
}],
defaultOptions: ["prefer-double"],
messages: { unexpected: "Unexpected usage of {{description}}." }
},
create(context, [quoteOption]) {
const setting = QUOTE_SETTINGS[quoteOption];
function usesExpectedQuotes(node) {
return node.value.includes(setting.quote) || isSurroundedBy(node.raw, setting.quote);
}
return { JSXAttribute(node) {
const attributeValue = node.value;
if (attributeValue && isStringLiteral(attributeValue) && !usesExpectedQuotes(attributeValue)) context.report({
node: attributeValue,
messageId: "unexpected",
data: { description: setting.description },
fix(fixer) {
return fixer.replaceText(attributeValue, setting.convert(attributeValue.raw));
}
});
} };
}
});
export { jsx_quotes_default as t };