Skip to content

Commit dfc7ec1

Browse files
docs: Formatters page updates (#16566)
* docs: Formatters page updates add more information about the built-in formatters Fixes #16476 * add formatter text generation * fix issue and rename manifest * fix manifest formatting issues * restore generated page to state of eslint/eslint:main * rename and refactor as json * fix template spacing * Apply suggestions from code review Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent 8ba124c commit dfc7ec1

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

Makefile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,9 @@ function lintMarkdown(files) {
447447
*/
448448
function getFormatterResults() {
449449
const stripAnsi = require("strip-ansi");
450+
const formattersMetadata = require("./lib/cli-engine/formatters/formatters-meta.json");
450451

451-
const formatterFiles = fs.readdirSync("./lib/cli-engine/formatters/"),
452+
const formatterFiles = fs.readdirSync("./lib/cli-engine/formatters/").filter(fileName => !fileName.includes("formatters-meta.json")),
452453
rules = {
453454
"no-else-return": "warn",
454455
indent: ["warn", 4],
@@ -489,7 +490,8 @@ function getFormatterResults() {
489490
);
490491

491492
data.formatterResults[name] = {
492-
result: stripAnsi(formattedOutput)
493+
result: stripAnsi(formattedOutput),
494+
description: formattersMetadata.find(formatter => formatter.name === name).description
493495
};
494496
}
495497
return data;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
[
2+
{
3+
"name": "checkstyle",
4+
"description": "Outputs results to the [Checkstyle](https://checkstyle.sourceforge.io/) format."
5+
},
6+
{
7+
"name": "compact",
8+
"description": "Human-readable output format. Mimics the default output of JSHint."
9+
},
10+
{
11+
"name": "html",
12+
"description": "Outputs results to HTML. The `html` formatter is useful for visual presentation in the browser."
13+
},
14+
{
15+
"name": "jslint-xml",
16+
"description": "Outputs results to format compatible with the [JSLint Jenkins plugin](https://plugins.jenkins.io/jslint/)."
17+
},
18+
{
19+
"name": "json-with-metadata",
20+
"description": "Outputs JSON-serialized results. The `json-with-metadata` provides the same linting results as the [`json`](#json) formatter with additional metadata about the rules applied. The linting results are included in the `results` property and the rules metadata is included in the `metadata` property.\n\nAlternatively, you can use the [ESLint Node.js API](../../developer-guide/nodejs-api) to programmatically use ESLint."
21+
},
22+
{
23+
"name": "json",
24+
"description": "Outputs JSON-serialized results. The `json` formatter is useful when you want to programmatically work with the CLI's linting results.\n\nAlternatively, you can use the [ESLint Node.js API](../../developer-guide/nodejs-api) to programmatically use ESLint."
25+
},
26+
{
27+
"name": "junit",
28+
"description": "Outputs results to format compatible with the [JUnit Jenkins plugin](https://plugins.jenkins.io/junit/)."
29+
},
30+
{
31+
"name": "stylish",
32+
"description": "Human-readable output format. This is the default formatter."
33+
},
34+
{
35+
"name": "tap",
36+
"description": "Outputs results to the [Test Anything Protocol (TAP)](https://testanything.org/) specification format."
37+
},
38+
{
39+
"name": "unix",
40+
"description": "Outputs results to a format similar to many commands in UNIX-like systems. Parsable with tools such as [grep](https://www.gnu.org/software/grep/manual/grep.html), [sed](https://www.gnu.org/software/sed/manual/sed.html), and [awk](https://www.gnu.org/software/gawk/manual/gawk.html)."
41+
},
42+
{
43+
"name": "visualstudio",
44+
"description": "Outputs results to format compatible with the integrated terminal of the [Visual Studio](https://visualstudio.microsoft.com/) IDE. When using Visual Studio, you can click on the linting results in the integrated terminal to go to the issue in the source code."
45+
}
46+
]

templates/formatter-examples.md.ejs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ edit_link: https://github.com/eslint/eslint/edit/main/templates/formatter-exampl
1010

1111
ESLint comes with several built-in formatters to control the appearance of the linting results, and supports third-party formatters as well.
1212

13-
You can specify a formatter using the `--format` or `-f` flag on the command line. For example, `--format json` uses the `json` formatter.
13+
You can specify a formatter using the `--format` or `-f` flag in the CLI. For example, `--format json` uses the `json` formatter.
1414

1515
The built-in formatter options are:
1616

@@ -20,9 +20,9 @@ The built-in formatter options are:
2020

2121
## Example Source
2222

23-
Examples of each formatter were created from linting `fullOfProblems.js` using the `.eslintrc` configuration shown below.
23+
Examples of each formatter were created from linting `fullOfProblems.js` using the `.eslintrc.json` configuration shown below.
2424

25-
### `fullOfProblems.js`
25+
`fullOfProblems.js`:
2626

2727
```js
2828
function addOne(i) {
@@ -34,7 +34,7 @@ function addOne(i) {
3434
};
3535
```
3636

37-
### `.eslintrc`
37+
`.eslintrc.json`:
3838

3939
```json
4040
{
@@ -49,17 +49,26 @@ function addOne(i) {
4949
}
5050
```
5151

52-
## Output Examples
52+
Tests the formatters with the CLI:
53+
54+
```shell
55+
npx eslint --format <Add formatter here> fullOfProblems.js
56+
```
57+
58+
## Built-In Formatter Options
5359
<% Object.keys(formatterResults).forEach(function(formatterName) { -%>
5460
5561
### <%= formatterName %>
56-
<% if (formatterName !== "html") { -%>
5762
63+
<%= formatterResults[formatterName].description %>
64+
65+
Example output:
66+
67+
<% if (formatterName !== "html") { -%>
5868
```text
5969
<%= formatterResults[formatterName].result %>
6070
```
6171
<% } else {-%>
62-
6372
<iframe src="html-formatter-example.html" width="100%" height="460px"></iframe>
6473
<% } -%>
6574
<% }) -%>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy