Use const instead of enum for choices in generated schema (#20084)

Thank you!
This commit is contained in:
Lazizbek Ergashev authored and GitHub committed 2026-09-16 21:32:30 +08:00
1 parent fe7fadc35e
commit 753f783086
2 files changed
+50 -148

No files matched your search

+1 -1
View File
@@ -115,7 +115,7 @@ function optionTypeToSchemaType(optionType) {
} }
function choiceToSchema(choice) { function choiceToSchema(choice) {
return { enum: [choice.value], description: choice.description }; return { const: choice.value, description: choice.description };
} }
async function generateSchema() { async function generateSchema() {
@@ -12,16 +12,12 @@ exports[`schema 1`] = `
"description": "Include parentheses around a sole arrow function parameter.", "description": "Include parentheses around a sole arrow function parameter.",
"oneOf": [ "oneOf": [
{ {
"const": "always",
"description": "Always include parens. Example: \`(x) => x\`", "description": "Always include parens. Example: \`(x) => x\`",
"enum": [
"always",
],
}, },
{ {
"const": "avoid",
"description": "Omit parens when possible. Example: \`x => x\`", "description": "Omit parens when possible. Example: \`x => x\`",
"enum": [
"avoid",
],
}, },
], ],
}, },
@@ -50,16 +46,12 @@ exports[`schema 1`] = `
"description": "Control how Prettier formats quoted code embedded in the file.", "description": "Control how Prettier formats quoted code embedded in the file.",
"oneOf": [ "oneOf": [
{ {
"const": "auto",
"description": "Format embedded code if Prettier can automatically identify it.", "description": "Format embedded code if Prettier can automatically identify it.",
"enum": [
"auto",
],
}, },
{ {
"const": "off",
"description": "Never automatically format embedded code.", "description": "Never automatically format embedded code.",
"enum": [
"off",
],
}, },
], ],
}, },
@@ -68,29 +60,21 @@ exports[`schema 1`] = `
"description": "Which end of line characters to apply.", "description": "Which end of line characters to apply.",
"oneOf": [ "oneOf": [
{ {
"const": "lf",
"description": "Line Feed only (\\n), common on Linux and macOS as well as inside git repos", "description": "Line Feed only (\\n), common on Linux and macOS as well as inside git repos",
"enum": [
"lf",
],
}, },
{ {
"const": "crlf",
"description": "Carriage Return + Line Feed characters (\\r\\n), common on Windows", "description": "Carriage Return + Line Feed characters (\\r\\n), common on Windows",
"enum": [
"crlf",
],
}, },
{ {
"const": "cr",
"description": "Carriage Return character only (\\r), used very rarely", "description": "Carriage Return character only (\\r), used very rarely",
"enum": [
"cr",
],
}, },
{ {
"const": "auto",
"description": "Maintain existing "description": "Maintain existing
(mixed values within one file are normalised by looking at what's used after the first line)", (mixed values within one file are normalised by looking at what's used after the first line)",
"enum": [
"auto",
],
}, },
], ],
}, },
@@ -99,16 +83,12 @@ exports[`schema 1`] = `
"description": "Where to print operators when binary expressions wrap lines.", "description": "Where to print operators when binary expressions wrap lines.",
"oneOf": [ "oneOf": [
{ {
"const": "start",
"description": "Print operators at the start of new lines.", "description": "Print operators at the start of new lines.",
"enum": [
"start",
],
}, },
{ {
"const": "end",
"description": "Print operators at the end of previous lines.", "description": "Print operators at the end of previous lines.",
"enum": [
"end",
],
}, },
], ],
}, },
@@ -127,22 +107,16 @@ exports[`schema 1`] = `
"description": "How to handle whitespaces in HTML.", "description": "How to handle whitespaces in HTML.",
"oneOf": [ "oneOf": [
{ {
"const": "css",
"description": "Respect the default value of CSS display property.", "description": "Respect the default value of CSS display property.",
"enum": [
"css",
],
}, },
{ {
"const": "strict",
"description": "Whitespaces are considered sensitive.", "description": "Whitespaces are considered sensitive.",
"enum": [
"strict",
],
}, },
{ {
"const": "ignore",
"description": "Whitespaces are considered insensitive.", "description": "Whitespaces are considered insensitive.",
"enum": [
"ignore",
],
}, },
], ],
}, },
@@ -161,170 +135,116 @@ exports[`schema 1`] = `
"description": "How to wrap object literals.", "description": "How to wrap object literals.",
"oneOf": [ "oneOf": [
{ {
"const": "preserve",
"description": "Keep as multi-line, if there is a newline between the opening brace and first property.", "description": "Keep as multi-line, if there is a newline between the opening brace and first property.",
"enum": [
"preserve",
],
}, },
{ {
"const": "collapse",
"description": "Fit to a single line when possible.", "description": "Fit to a single line when possible.",
"enum": [
"collapse",
],
}, },
], ],
}, },
"parser": { "parser": {
"anyOf": [ "anyOf": [
{ {
"const": "flow",
"description": "Flow", "description": "Flow",
"enum": [
"flow",
],
}, },
{ {
"const": "babel",
"description": "JavaScript", "description": "JavaScript",
"enum": [
"babel",
],
}, },
{ {
"const": "babel-flow",
"description": "Flow", "description": "Flow",
"enum": [
"babel-flow",
],
}, },
{ {
"const": "babel-ts",
"description": "TypeScript", "description": "TypeScript",
"enum": [
"babel-ts",
],
}, },
{ {
"const": "typescript",
"description": "TypeScript", "description": "TypeScript",
"enum": [
"typescript",
],
}, },
{ {
"const": "acorn",
"description": "JavaScript", "description": "JavaScript",
"enum": [
"acorn",
],
}, },
{ {
"const": "espree",
"description": "JavaScript", "description": "JavaScript",
"enum": [
"espree",
],
}, },
{ {
"const": "meriyah",
"description": "JavaScript", "description": "JavaScript",
"enum": [
"meriyah",
],
}, },
{ {
"const": "css",
"description": "CSS", "description": "CSS",
"enum": [
"css",
],
}, },
{ {
"const": "less",
"description": "Less", "description": "Less",
"enum": [
"less",
],
}, },
{ {
"const": "scss",
"description": "SCSS", "description": "SCSS",
"enum": [
"scss",
],
}, },
{ {
"const": "json",
"description": "JSON", "description": "JSON",
"enum": [
"json",
],
}, },
{ {
"const": "json5",
"description": "JSON5", "description": "JSON5",
"enum": [
"json5",
],
}, },
{ {
"const": "jsonc",
"description": "JSON with Comments", "description": "JSON with Comments",
"enum": [
"jsonc",
],
}, },
{ {
"const": "json-stringify",
"description": "JSON.stringify", "description": "JSON.stringify",
"enum": [
"json-stringify",
],
}, },
{ {
"const": "graphql",
"description": "GraphQL", "description": "GraphQL",
"enum": [
"graphql",
],
}, },
{ {
"const": "markdown",
"description": "Markdown", "description": "Markdown",
"enum": [
"markdown",
],
}, },
{ {
"const": "mdx",
"description": "MDX", "description": "MDX",
"enum": [
"mdx",
],
}, },
{ {
"const": "vue",
"description": "Vue", "description": "Vue",
"enum": [
"vue",
],
}, },
{ {
"const": "yaml",
"description": "YAML", "description": "YAML",
"enum": [
"yaml",
],
}, },
{ {
"const": "glimmer",
"description": "Ember / Handlebars", "description": "Ember / Handlebars",
"enum": [
"glimmer",
],
}, },
{ {
"const": "html",
"description": "HTML", "description": "HTML",
"enum": [
"html",
],
}, },
{ {
"const": "angular",
"description": "Angular", "description": "Angular",
"enum": [
"angular",
],
}, },
{ {
"const": "lwc",
"description": "Lightning Web Components", "description": "Lightning Web Components",
"enum": [
"lwc",
],
}, },
{ {
"const": "mjml",
"description": "MJML", "description": "MJML",
"enum": [
"mjml",
],
}, },
{ {
"description": "Custom parser", "description": "Custom parser",
@@ -352,22 +272,16 @@ exports[`schema 1`] = `
"description": "How to wrap prose.", "description": "How to wrap prose.",
"oneOf": [ "oneOf": [
{ {
"const": "always",
"description": "Wrap prose if it exceeds the print width.", "description": "Wrap prose if it exceeds the print width.",
"enum": [
"always",
],
}, },
{ {
"const": "never",
"description": "Do not wrap prose.", "description": "Do not wrap prose.",
"enum": [
"never",
],
}, },
{ {
"const": "preserve",
"description": "Wrap prose as-is.", "description": "Wrap prose as-is.",
"enum": [
"preserve",
],
}, },
], ],
}, },
@@ -376,22 +290,16 @@ exports[`schema 1`] = `
"description": "Change when properties in objects are quoted.", "description": "Change when properties in objects are quoted.",
"oneOf": [ "oneOf": [
{ {
"const": "as-needed",
"description": "Only add quotes around object properties where required.", "description": "Only add quotes around object properties where required.",
"enum": [
"as-needed",
],
}, },
{ {
"const": "consistent",
"description": "If at least one property in an object requires quotes, quote all properties.", "description": "If at least one property in an object requires quotes, quote all properties.",
"enum": [
"consistent",
],
}, },
{ {
"const": "preserve",
"description": "Respect the input use of quotes in object properties.", "description": "Respect the input use of quotes in object properties.",
"enum": [
"preserve",
],
}, },
], ],
}, },
@@ -437,22 +345,16 @@ The range will extend backwards to the start of the first line containing the se
"description": "Print trailing commas wherever possible when multi-line.", "description": "Print trailing commas wherever possible when multi-line.",
"oneOf": [ "oneOf": [
{ {
"const": "all",
"description": "Trailing commas wherever possible (including function arguments).", "description": "Trailing commas wherever possible (including function arguments).",
"enum": [
"all",
],
}, },
{ {
"const": "es5",
"description": "Trailing commas where valid in ES5 (objects, arrays, etc.)", "description": "Trailing commas where valid in ES5 (objects, arrays, etc.)",
"enum": [
"es5",
],
}, },
{ {
"const": "none",
"description": "No trailing commas.", "description": "No trailing commas.",
"enum": [
"none",
],
}, },
], ],
}, },