feat: check for unclosed code blocks (#56700)

This commit is contained in:
Oliver Eyton-Williams
2024-10-18 14:15:52 +02:00
committed by GitHub
parent 898b78c2de
commit 7298db7faf
4 changed files with 21 additions and 1 deletions
@@ -95,3 +95,4 @@ Rentals are usually stationary services, not something that stops.
}
]
}
```
@@ -78,3 +78,4 @@ Refers to the act of being introduced to someone for the first time.
}
]
}
```
@@ -0,0 +1,17 @@
module.exports = {
names: ['closed-code-blocks'],
description: 'Code blocks must have closing triple backticks',
tags: ['code'],
function: function rule(params, onError) {
params.parsers.micromark.tokens
.filter(token => token.type === 'codeFenced')
.forEach(token => {
if (token.text.trim().slice(-3) !== '```') {
onError({
lineNumber: token.endLine,
detail: `Code blocks must have closing triple backticks.`
});
}
});
}
};
+2 -1
View File
@@ -2,13 +2,14 @@ const markdownlint = require('markdownlint');
const lintPrism = require('./markdown-prism');
const lintYAML = require('./markdown-yaml');
const fencedCodeBlock = require('./fenced-code-block');
function linter(rules) {
const lint = (file, next) => {
const options = {
files: [file.path],
config: rules,
customRules: [lintYAML, lintPrism]
customRules: [lintYAML, lintPrism, fencedCodeBlock]
};
markdownlint(options, function callback(err, result) {
const resultString = (result || '').toString();