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.
25 lines
693 B
JavaScript
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
|
|
});
|
|
}
|
|
});
|
|
}
|
|
};
|