From b7ef2f34fe12b68a366e1b4bf5f64d7332c6e72e Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Wed, 11 Oct 2023 17:59:44 -0400 Subject: [PATCH] docs: Enable pretty code formatter output (#17635) * docs: Enable pretty code formatter output fixes #17505 * Add note about formatted output * Update templates/formatter-examples.md.ejs Co-authored-by: Milos Djermanovic * Update templates/formatter-examples.md.ejs Co-authored-by: Milos Djermanovic --------- Co-authored-by: Milos Djermanovic --- templates/formatter-examples.md.ejs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/templates/formatter-examples.md.ejs b/templates/formatter-examples.md.ejs index 20f46f2d5aa..e18eb18995f 100644 --- a/templates/formatter-examples.md.ejs +++ b/templates/formatter-examples.md.ejs @@ -14,7 +14,7 @@ You can specify a formatter using the `--format` or `-f` flag in the CLI. For ex The built-in formatter options are: -<% Object.keys(formatterResults).forEach(function(formatterName) { -%> +<% Object.keys(formatterResults).forEach(formatterName => { -%> * [<%= formatterName %>](#<%= formatterName %>) <% }) -%> @@ -56,19 +56,36 @@ npx eslint --format fullOfProblems.js ``` ## Built-In Formatter Options -<% Object.keys(formatterResults).forEach(function(formatterName) { -%> +<% Object.keys(formatterResults).forEach(formatterName => { -%> ### <%= formatterName %> <%= formatterResults[formatterName].description %> +<% if (formatterName !== "html") { -%> +<% + let codeFormat = "text"; + let output = formatterResults[formatterName].result; + let outputNote = "Example output:"; -Example output: + if (output.startsWith("\u003C?xml")) { + codeFormat = "xml"; + } -<% if (formatterName !== "html") { -%> -```text -<%- formatterResults[formatterName].result %> + if (formatterName.includes("json")) { + codeFormat = "json"; + output = JSON.stringify(JSON.parse(output), null, 4); + outputNote = "Example output (formatted for easier reading):"; + } +%> +<%= outputNote %> + +```<%= codeFormat %> +<%- output %> ``` <% } else {-%> + +Example output: + <% } -%> <% }) -%>