Skip to content

Commit cd7f829

Browse files
authored
feat: support skip frontmatter (#301)
* feat: support frontmatter * add tests * add integration-tests * add docs * add tests * Update .cspell.json
1 parent d367b20 commit cd7f829

File tree

24 files changed

+451
-25
lines changed

24 files changed

+451
-25
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"packages/eslint-plugin/types/**"
1414
],
1515
"words": [
16+
"frontmatter",
1617
"rehype",
1718
"tailwindcss",
1819
"codemirror",

docs/integrating-template-engine.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ parserOptions: {
7272
templateEngineSyntax: TEMPLATE_ENGINE_SYNTAX.ERB;
7373
}
7474
```
75+
76+
## Skip frontmatter
77+
78+
If you are using frontmatter in html, set the parser options to `"frontmatter": true`, which tells the plugin to ignore the frontmatter part. (default: `false`)
79+
80+
```js
81+
parserOptions: {
82+
frontmatter: true,
83+
}
84+
```

packages/eslint-plugin/tests/rules/element-newline.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ Bar
225225
},
226226
},
227227
},
228+
{
229+
code: `---
230+
tag: <div></div><div></div>
231+
---
232+
`,
233+
languageOptions: {
234+
parserOptions: {
235+
frontmatter: true,
236+
},
237+
},
238+
},
228239
],
229240
invalid: [
230241
{
@@ -685,6 +696,31 @@ aaa<strong>bbb</strong><a>ccc</a>
685696
},
686697
],
687698
},
699+
{
700+
code: `---
701+
tag: <div></div><div></div>
702+
---
703+
<div></div><div></div>
704+
`,
705+
errors: [
706+
{
707+
message: "There should be a linebreak after </div>.",
708+
line: 4,
709+
column: 1,
710+
},
711+
],
712+
output: `---
713+
tag: <div></div><div></div>
714+
---
715+
<div></div>
716+
<div></div>
717+
`,
718+
languageOptions: {
719+
parserOptions: {
720+
frontmatter: true,
721+
},
722+
},
723+
},
688724
],
689725
});
690726

packages/eslint-plugin/tests/rules/indent.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,19 @@ function createTests() {
413413
</html>
414414
`,
415415
},
416+
{
417+
code: `---
418+
name: value
419+
---
420+
<div>
421+
</div>
422+
`,
423+
languageOptions: {
424+
parserOptions: {
425+
frontmatter: true,
426+
},
427+
},
428+
},
416429
],
417430
invalid: [
418431
{
@@ -1244,6 +1257,44 @@ id="bar"
12441257
},
12451258
},
12461259
},
1260+
{
1261+
code: `<div>
1262+
<div></div>
1263+
</div>
1264+
`,
1265+
languageOptions: {
1266+
parserOptions: {
1267+
frontmatter: true,
1268+
},
1269+
},
1270+
errors: wrongIndentErrors(1),
1271+
output: `<div>
1272+
<div></div>
1273+
</div>
1274+
`,
1275+
},
1276+
{
1277+
code: `---
1278+
name: value
1279+
---
1280+
<div>
1281+
<div></div>
1282+
</div>
1283+
`,
1284+
languageOptions: {
1285+
parserOptions: {
1286+
frontmatter: true,
1287+
},
1288+
},
1289+
errors: wrongIndentErrors(1),
1290+
output: `---
1291+
name: value
1292+
---
1293+
<div>
1294+
<div></div>
1295+
</div>
1296+
`,
1297+
},
12471298
],
12481299
};
12491300
}

packages/integration-test/fixtures/eslint-v8-legacy-config/.eslintrc.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ module.exports = {
2323
"@html-eslint/sort-attrs": ["error"],
2424
"@html-eslint/quotes": ["error"]
2525
}
26+
},
27+
{
28+
files: ["**/*.html"],
29+
parser: "@html-eslint/parser",
30+
parserOptions: {
31+
frontmatter: true,
32+
},
33+
plugins: ["@html-eslint"],
34+
rules: {
35+
"@html-eslint/indent": ["error", 2],
36+
}
2637
}
2738
]
2839
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
name: foo
3+
---
4+
<div>
5+
<div></div>
6+
</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
name: foo
3+
---
4+
<div>
5+
<div></div>
6+
</div>

0 commit comments

Comments
 (0)