Skip to content

Commit b7ef2f3

Browse files
nzakasmdjermanovic
andauthored
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 <[email protected]> * Update templates/formatter-examples.md.ejs Co-authored-by: Milos Djermanovic <[email protected]> --------- Co-authored-by: Milos Djermanovic <[email protected]>
1 parent 0bcb9a8 commit b7ef2f3

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

templates/formatter-examples.md.ejs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ You can specify a formatter using the `--format` or `-f` flag in the CLI. For ex
1414

1515
The built-in formatter options are:
1616

17-
<% Object.keys(formatterResults).forEach(function(formatterName) { -%>
17+
<% Object.keys(formatterResults).forEach(formatterName => { -%>
1818
* [<%= formatterName %>](#<%= formatterName %>)
1919
<% }) -%>
2020

@@ -56,19 +56,36 @@ npx eslint --format <Add formatter here> fullOfProblems.js
5656
```
5757

5858
## Built-In Formatter Options
59-
<% Object.keys(formatterResults).forEach(function(formatterName) { -%>
59+
<% Object.keys(formatterResults).forEach(formatterName => { -%>
6060
6161
### <%= formatterName %>
6262
6363
<%= formatterResults[formatterName].description %>
64+
<% if (formatterName !== "html") { -%>
65+
<%
66+
let codeFormat = "text";
67+
let output = formatterResults[formatterName].result;
68+
let outputNote = "Example output:";
6469
65-
Example output:
70+
if (output.startsWith("\u003C?xml")) {
71+
codeFormat = "xml";
72+
}
6673
67-
<% if (formatterName !== "html") { -%>
68-
```text
69-
<%- formatterResults[formatterName].result %>
74+
if (formatterName.includes("json")) {
75+
codeFormat = "json";
76+
output = JSON.stringify(JSON.parse(output), null, 4);
77+
outputNote = "Example output (formatted for easier reading):";
78+
}
79+
%>
80+
<%= outputNote %>
81+
82+
```<%= codeFormat %>
83+
<%- output %>
7084
```
7185
<% } else {-%>
86+
87+
Example output:
88+
7289
<iframe src="html-formatter-example.html" width="100%" height="460px"></iframe>
7390
<% } -%>
7491
<% }) -%>

0 commit comments

Comments
 (0)