Files
freeCodeCamp/tools/linter/markdown-yaml.js
Oliver Eyton-Williams 9de68bd4a7 feat: Add rule checking Prism languages
The linter now checks that fences have languages and that those languages are
supported by PrismJS. The linter has been extended over the guide with its own
set of rules that only validate code fences.
2019-07-19 15:30:17 +05:30

25 lines
693 B
JavaScript

const yaml = require('js-yaml');
module.exports = {
names: ['yaml-linter'],
description: 'YAML code blocks should be valid',
tags: ['yaml'],
function: function rule(params, onError) {
params.tokens
.filter(param => param.type === 'fence')
.filter(param => param.info === 'yml' || param.info === 'yaml')
// TODO since the parser only looks for yml, should we reject yaml blocks?
.forEach(codeBlock => {
try {
yaml.safeLoad(codeBlock.content);
} catch (e) {
onError({
lineNumber: codeBlock.lineNumber,
detail: e.message,
context: codeBlock.line
});
}
});
}
};