Skip to content

Commit

Permalink
set error on the tag
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Oct 5, 2023
1 parent bf1b34c commit 6482958
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
11 changes: 7 additions & 4 deletions lib/md045.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
const { addError } = require("../helpers");
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark.cjs");

const nextLinesRe = /[\r\n][\s\S]*$/;

module.exports = {
"names": [ "MD045", "no-alt-text" ],
"description": "Images should have alternate text (alt text)",
Expand Down Expand Up @@ -33,13 +35,14 @@ module.exports = {
if (htmlTagInfo && htmlTagInfo.name === "img") {
const hasAltAttribute = new RegExp(/alt=/);
if (!hasAltAttribute.test(token.text)) {
const range = (token.startLine === token.endLine) ?
[ token.startColumn, token.endColumn - token.startColumn ] :
undefined;
const range = [
token.startColumn,
token.text.replace(nextLinesRe, "").length
];
addError(
onError,
token.startLine,
undefined,
"Element: " + htmlTagInfo.name,
undefined,
range
);
Expand Down
26 changes: 16 additions & 10 deletions test/snapshots/markdownlint-test-scenarios.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -13934,7 +13934,7 @@ Generated by [AVA](https://avajs.dev).
errors: [
{
errorContext: null,
errorDetail: null,
errorDetail: 'Element: img',
errorRange: [
20,
44,
Expand Down Expand Up @@ -18759,7 +18759,7 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorDetail: 'Element: img',
errorRange: [
6,
20,
Expand Down Expand Up @@ -33947,7 +33947,7 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorDetail: 'Element: img',
errorRange: [
1,
25,
Expand All @@ -33963,7 +33963,7 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorDetail: 'Element: img',
errorRange: [
1,
21,
Expand All @@ -33979,8 +33979,11 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorRange: null,
errorDetail: 'Element: img',
errorRange: [
1,
4,
],
fixInfo: null,
lineNumber: 44,
ruleDescription: 'Images should have alternate text (alt text)',
Expand All @@ -33992,8 +33995,11 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorRange: null,
errorDetail: 'Element: img',
errorRange: [
1,
4,
],
fixInfo: null,
lineNumber: 48,
ruleDescription: 'Images should have alternate text (alt text)',
Expand Down Expand Up @@ -37267,7 +37273,7 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorDetail: 'Element: img',
errorRange: [
1,
36,
Expand Down Expand Up @@ -38774,7 +38780,7 @@ Generated by [AVA](https://avajs.dev).
},
{
errorContext: null,
errorDetail: null,
errorDetail: 'Element: img',
errorRange: [
1,
52,
Expand Down
Binary file modified test/snapshots/markdownlint-test-scenarios.js.snap
Binary file not shown.

0 comments on commit 6482958

Please sign in to comment.