Skip to content

Commit 4c9e5ed

Browse files
authored
docs: improve flat config examples (#190)
1 parent 9e968b9 commit 4c9e5ed

File tree

2 files changed

+79
-22
lines changed

2 files changed

+79
-22
lines changed

docs/getting-started.md

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,91 @@ yarn add -D eslint @html-eslint/parser @html-eslint/eslint-plugin
2525

2626
If you are using the ESLint [Flat config](https://eslint.org/docs/latest/use/configure/configuration-files-new), see examples below.
2727

28+
#### Minimal configuration
29+
30+
```js,eslint.config.js
31+
import html from "@html-eslint/eslint-plugin";
32+
33+
export default [
34+
// your own configurations.
35+
{
36+
// recommended configuration included in the plugin
37+
...html.configs["flat/recommended"],
38+
files: ["**/*.html"],
39+
},
40+
];
41+
```
42+
43+
or if using `require(..);`
44+
45+
```js,eslint.config.js
46+
const html = require("@html-eslint/eslint-plugin");
47+
48+
module.exports = [
49+
// your own configurations.
50+
{
51+
// recommended configuration included in the plugin
52+
... html.configs["flat/recommended"],
53+
files: ["**/*.html"],
54+
},
55+
];
56+
```
57+
58+
#### Recommended rules with some customization
59+
2860
```js,eslint.config.js
2961
import html from "@html-eslint/eslint-plugin";
30-
import parser from "@html-eslint/parser";
3162

3263
export default [
33-
// recommended configuration included in the plugin
34-
html.configs["flat/recommended"],
3564
// your own configurations.
3665
{
66+
// recommended configuration included in the plugin
67+
...html.configs["flat/recommended"],
68+
files: ["**/*.html"],
69+
rules: {
70+
...html.configs["flat/recommended"].rules, // Must be defined. If not, all recommended rules will be lost
71+
"@html-eslint/indent": "error",
72+
},
73+
},
74+
];
75+
```
76+
77+
or if using `require(..);`
78+
79+
```js,eslint.config.js
80+
const html = require("@html-eslint/eslint-plugin");
81+
82+
module.exports = [
83+
// your own configurations.
84+
{
85+
// recommended configuration included in the plugin
86+
...html.configs["flat/recommended"],
87+
files: ["**/*.html"],
88+
rules: {
89+
...html.configs["flat/recommended"].rules, // Must be defined. If not, all recommended rules will be lost
90+
"@html-eslint/indent": "error",
91+
},
92+
},
93+
];
94+
```
95+
96+
#### Explicit plugin and parser configuration
97+
98+
```js,eslint.config.js
99+
import html from "@html-eslint/eslint-plugin";
100+
import htmlParser from "@html-eslint/parser";
101+
102+
export default [
103+
// your own configurations.
104+
{
105+
// recommended configuration included in the plugin
106+
...html.configs["flat/recommended"],
37107
files: ["**/*.html"],
38108
plugins: {
39109
"@html-eslint": html,
40110
},
41111
languageOptions: {
42-
parser,
43-
},
44-
rules: {
45-
"@html-eslint/indent": "error",
112+
parser: htmlParser,
46113
},
47114
},
48115
];
@@ -52,22 +119,19 @@ or if using `require(..);`
52119

53120
```js,eslint.config.js
54121
const html = require("@html-eslint/eslint-plugin");
55-
const parser = require("@html-eslint/parser");
122+
const htmlParser = require("@html-eslint/parser");
56123

57124
module.exports = [
58-
// recommended configuration included in the plugin
59-
html.configs["flat/recommended"],
60125
// your own configurations.
61126
{
127+
// recommended configuration included in the plugin
128+
...html.configs["flat/recommended"],
62129
files: ["**/*.html"],
63130
plugins: {
64131
"@html-eslint": html,
65132
},
66133
languageOptions: {
67-
parser,
68-
},
69-
rules: {
70-
"@html-eslint/indent": "error",
134+
parser: htmlParser,
71135
},
72136
},
73137
];
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
import html from "@html-eslint/eslint-plugin";
2-
import parser from "@html-eslint/parser";
32

43
export default [
5-
html.configs["flat/recommended"],
64
{
5+
...html.configs["flat/recommended"],
76
files: ["**/*.html"],
8-
plugins: {
9-
"@html-eslint": html,
10-
},
11-
languageOptions: {
12-
parser,
13-
},
147
},
158
];

0 commit comments

Comments
 (0)