mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-09-22 05:40:48 +02:00
30 lines
915 B
JavaScript
30 lines
915 B
JavaScript
// @ts-check
|
|
|
|
"use strict";
|
|
|
|
const { addError } = require("../helpers");
|
|
const { filterByTypes } = require("../helpers/micromark.cjs");
|
|
|
|
module.exports = {
|
|
"names": [ "MD045", "no-alt-text" ],
|
|
"description": "Images should have alternate text (alt text)",
|
|
"tags": [ "accessibility", "images" ],
|
|
"function": function MD045(params, onError) {
|
|
const images = filterByTypes(params.parsers.micromark.tokens, [ "image" ]);
|
|
for (const image of images) {
|
|
const labelTexts = filterByTypes(image.children, [ "labelText" ]);
|
|
if (labelTexts.some((labelText) => labelText.text.length === 0)) {
|
|
const range = (image.startLine === image.endLine) ?
|
|
[ image.startColumn, image.endColumn - image.startColumn ] :
|
|
undefined;
|
|
addError(
|
|
onError,
|
|
image.startLine,
|
|
undefined,
|
|
undefined,
|
|
range
|
|
);
|
|
}
|
|
}
|
|
}
|
|
};
|