mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat: check for unclosed code blocks (#56700)
This commit is contained in:
committed by
GitHub
parent
898b78c2de
commit
7298db7faf
@@ -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,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();
|
||||
|
||||
Reference in New Issue
Block a user