Update MD040/fenced-code-language to add allowed_languages parameter (fixes #610).

This commit is contained in:
Sam Chen 2022-10-18 03:29:29 +08:00 committed by GitHub
parent c333976a44
commit 01ba757d3a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 199 additions and 9 deletions

View file

@ -925,7 +925,7 @@ test("readme", (t) => new Promise((resolve) => {
}));
test("rules", (t) => new Promise((resolve) => {
t.plan(374);
t.plan(375);
fs.readFile("doc/Rules.md", "utf8",
(err, contents) => {
t.falsy(err);

View file

@ -0,0 +1,5 @@
{
"MD040": {
"allowed_languages": ["js", "scss", "md", "TS"]
}
}

View file

@ -0,0 +1,45 @@
# md040-allowed_languages.md
Code block with `html` not in allowed_languages:
```html
<h1>markdownlint</h1> {MD040:5}
```
Code block with `css` not in allowed_languages:
```css
body {} {MD040:11}
```
Code block with `js` in allowed_languages:
```js
console.log('markdownlint')
```
Code block with `scss` in allowed_languages:
```scss
body {
h1 {
color: red;
}
}
```
Code block with `md` in allowed_languages:
```MD
hello md
```
Code block with `TS` in allowed_languages:
```ts
body {
h1 {
color: red;
}
}
```

View file

@ -29318,6 +29318,87 @@ Generated by [AVA](https://avajs.dev).
`,
}
## md040-allowed_languages.md
> Snapshot 1
{
errors: [
{
errorContext: null,
errorDetail: '"html" is not allowed',
errorRange: null,
fixInfo: null,
lineNumber: 5,
ruleDescription: 'Fenced code blocks should have a language specified',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md040',
ruleNames: [
'MD040',
'fenced-code-language',
],
},
{
errorContext: null,
errorDetail: '"css" is not allowed',
errorRange: null,
fixInfo: null,
lineNumber: 11,
ruleDescription: 'Fenced code blocks should have a language specified',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/Rules.md#md040',
ruleNames: [
'MD040',
'fenced-code-language',
],
},
],
fixed: `# md040-allowed_languages.md␊
Code block with \`html\` not in allowed_languages:␊
\`\`\`html␊
<h1>markdownlint</h1> {MD040:5}␊
\`\`\`␊
Code block with \`css\` not in allowed_languages:␊
\`\`\`css␊
body {} {MD040:11}␊
\`\`\`␊
Code block with \`js\` in allowed_languages:␊
\`\`\`js␊
console.log('markdownlint')␊
\`\`\`␊
Code block with \`scss\` in allowed_languages:␊
\`\`\`scss␊
body {␊
h1 {␊
color: red;␊
}␊
}␊
\`\`\`␊
Code block with \`md\` in allowed_languages:␊
\`\`\`MD␊
hello md␊
\`\`\`␊
Code block with \`TS\` in allowed_languages:␊
\`\`\`ts␊
body {␊
h1 {␊
color: red;␊
}␊
}␊
\`\`\`␊
`,
}
## md041-ignore-leading-comments-combined.md
> Snapshot 1