Update MD045/no-alt-text to report instances of HTML "img" tags missing an "alt" attribute (fixes #992).

This commit is contained in:
Kate Higa 2023-10-18 23:20:19 -07:00 committed by GitHub
parent 0afedaebf4
commit 531e58ed9a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 274 additions and 25 deletions

View file

@ -1,4 +1,4 @@
<h1 align="center"><img src="https://placekitten.com/300/150"/></h1>
<h1 align="center"><img src="https://placekitten.com/300/150" alt="A kitten" /></h1>
Text

View file

@ -88,7 +88,7 @@ Text ``text <em> text`` text
Text
Text <a href="#anchor">inline {MD033}</a> text
text <img src="src.png"/> text {MD033}
text <img src="src.png" alt="Description" /> text {MD033}
Text

View file

@ -28,5 +28,43 @@ Multi-line image with alternate text ![Alternate text](image.jpg "Title"
Multi-line image without alternate text ![](image.jpg "Title"
) {MD045:28}
<!-- markdownlint-disable no-inline-html -->
Image tag with alt attribute set to text
<img src="image.png" alt="Descriptive text" />
Image tag with alt attribute not set
<img src="image.png" alt> {MD045}
Image tag with alt attribute set to decorative with an empty double-quote string
<img src="image.png" alt="" />
Image tag with alt attribute set to decorative with an empty single-quote string
<img src="image.png" alt='' />
Image tag with no alt attribute <img src="image.png" /> {MD045}
Multi-line image tag with no alt text
<img
src="image.png"> {MD045:48}
Multi-line image tag with alt attribute not set
<img
src="image.png"
alt> {MD045:52}
Multi-line image tag with alt text
<img
src="image.png"
alt="Description"
>
Uppercase image tag with alt attribute set
<IMG SRC="cat.png" ALT="Descriptive text">
Uppercase image tag with no alt set <IMG SRC="cat.png" /> {MD045}
<!-- markdownlint-restore no-inline-html -->
[notitle]: image.jpg
[title]: image.jpg "Title"

View file

@ -6,7 +6,7 @@ Bad text javascript. {MD044}
Bad code `javascript`. {MD044}
<img src="img/javascript/image.png">
<img src="img/javascript/image.png" alt="Description">
<script type="text/javascript">
javascript {MD044}

View file

@ -89,7 +89,7 @@ Text referencing MultipleCase name.
Text referencing MULTIPLECASE name. {MD044}
Text referencing mULTIPLEcASE name.
<img src="img/javascript/image.png" error="{MD044}">
<img src="img/javascript/image.png" alt="Description" error="{MD044}">
<script type="text/javascript">
{MD044:94}

View file

@ -8,7 +8,7 @@ Generated by [AVA](https://avajs.dev).
> Expected linting violations
''
'test-repos/apache-airflow/tests/system/providers/apache/hive/example_twitter_README.md: 36: MD045/no-alt-text Images should have alternate text (alt text)'
## https://github.com/dotnet/docs
@ -37,7 +37,13 @@ Generated by [AVA](https://avajs.dev).
> Expected linting violations
`test-repos/mdn-content/files/en-us/web/svg/attribute/d/index.md: 234: MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 10]␊
`test-repos/mdn-content/files/en-us/web/css/angle/index.md: 38: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mdn-content/files/en-us/web/css/angle/index.md: 49: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mdn-content/files/en-us/web/css/angle/index.md: 60: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mdn-content/files/en-us/web/css/angle/index.md: 71: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mdn-content/files/en-us/web/css/transform-function/rotate3d/index.md: 67: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mdn-content/files/en-us/web/css/transform-function/rotate3d/index.md: 251: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mdn-content/files/en-us/web/svg/attribute/d/index.md: 234: MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 10]␊
test-repos/mdn-content/files/en-us/web/svg/attribute/d/index.md: 556: MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 12]␊
test-repos/mdn-content/files/en-us/web/svg/attribute/d/index.md: 769: MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 12]␊
test-repos/mdn-content/files/en-us/web/svg/attribute/d/index.md: 838: MD007/ul-indent Unordered list indentation [Expected: 0; Actual: 12]`
@ -58,6 +64,7 @@ Generated by [AVA](https://avajs.dev).
test-repos/mochajs-mocha/MAINTAINERS.md: 34: MD051/link-fragments Link fragments should be valid [Context: "[Projects](#projects)"]␊
test-repos/mochajs-mocha/PROJECT_CHARTER.md: 51: MD051/link-fragments Link fragments should be valid [Context: "[§2: Scope](#%c2%a72-scope)"]␊
test-repos/mochajs-mocha/PROJECT_CHARTER.md: 56: MD051/link-fragments Link fragments should be valid [Context: "[§2: Scope](#%c2%a72-scope)"]␊
test-repos/mochajs-mocha/README.md: 36: MD045/no-alt-text Images should have alternate text (alt text)␊
test-repos/mochajs-mocha/docs/index.md: 32: MD051/link-fragments Link fragments should be valid [Context: "[global variable leak detection](#-check-leaks)"]␊
test-repos/mochajs-mocha/docs/index.md: 33: MD051/link-fragments Link fragments should be valid [Context: "[optionally run tests that match a regexp](#-grep-regexp-g-regexp)"]␊
test-repos/mochajs-mocha/docs/index.md: 34: MD051/link-fragments Link fragments should be valid [Context: "[auto-exit to prevent "hanging" with an active loop](#-exit)"]␊
@ -205,4 +212,4 @@ Generated by [AVA](https://avajs.dev).
> Expected linting violations
''
'test-repos/webpack-webpack-js-org/README.md: 3: MD045/no-alt-text Images should have alternate text (alt text)'

View file

@ -13955,7 +13955,7 @@ Generated by [AVA](https://avajs.dev).
{
errors: [],
fixed: `<h1 align="center"><img src="https://placekitten.com/300/150"/></h1>
fixed: `<h1 align="center"><img src="https://placekitten.com/300/150" alt="A kitten" /></h1>
Text␊
@ -18688,7 +18688,7 @@ Generated by [AVA](https://avajs.dev).
errorDetail: 'Element: img',
errorRange: [
6,
20,
39,
],
fixInfo: null,
lineNumber: 91,
@ -18854,7 +18854,7 @@ Generated by [AVA](https://avajs.dev).
Text␊
Text <a href="#anchor">inline {MD033}</a> text␊
text <img src="src.png"/> text {MD033}␊
text <img src="src.png" alt="Description" /> text {MD033}␊
Text␊
@ -34476,6 +34476,86 @@ Generated by [AVA](https://avajs.dev).
'no-alt-text',
],
},
{
errorContext: null,
errorDetail: null,
errorRange: [
1,
25,
],
fixInfo: null,
lineNumber: 37,
ruleDescription: 'Images should have alternate text (alt text)',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md045.md',
ruleNames: [
'MD045',
'no-alt-text',
],
},
{
errorContext: null,
errorDetail: null,
errorRange: [
33,
23,
],
fixInfo: null,
lineNumber: 45,
ruleDescription: 'Images should have alternate text (alt text)',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md045.md',
ruleNames: [
'MD045',
'no-alt-text',
],
},
{
errorContext: null,
errorDetail: null,
errorRange: [
1,
4,
],
fixInfo: null,
lineNumber: 48,
ruleDescription: 'Images should have alternate text (alt text)',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md045.md',
ruleNames: [
'MD045',
'no-alt-text',
],
},
{
errorContext: null,
errorDetail: null,
errorRange: [
1,
4,
],
fixInfo: null,
lineNumber: 52,
ruleDescription: 'Images should have alternate text (alt text)',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md045.md',
ruleNames: [
'MD045',
'no-alt-text',
],
},
{
errorContext: null,
errorDetail: null,
errorRange: [
37,
21,
],
fixInfo: null,
lineNumber: 65,
ruleDescription: 'Images should have alternate text (alt text)',
ruleInformation: 'https://github.com/DavidAnson/markdownlint/blob/v0.0.0/doc/md045.md',
ruleNames: [
'MD045',
'no-alt-text',
],
},
],
fixed: `# Images with and without alternate text␊
@ -34507,6 +34587,44 @@ Generated by [AVA](https://avajs.dev).
Multi-line image without alternate text ![](image.jpg "Title"␊
) {MD045:28}␊
<!-- markdownlint-disable no-inline-html -->
Image tag with alt attribute set to text␊
<img src="image.png" alt="Descriptive text" />
Image tag with alt attribute not set␊
<img src="image.png" alt> {MD045}␊
Image tag with alt attribute set to decorative with an empty double-quote string␊
<img src="image.png" alt="" />
Image tag with alt attribute set to decorative with an empty single-quote string␊
<img src="image.png" alt='' />
Image tag with no alt attribute <img src="image.png" /> {MD045}␊
Multi-line image tag with no alt text␊
<img
src="image.png"> {MD045:48}␊
Multi-line image tag with alt attribute not set␊
<img
src="image.png"␊
alt> {MD045:52}␊
Multi-line image tag with alt text␊
<img
src="image.png"␊
alt="Description"␊
>␊
Uppercase image tag with alt attribute set␊
<IMG SRC="cat.png" ALT="Descriptive text">
Uppercase image tag with no alt set <IMG SRC="cat.png" /> {MD045}␊
<!-- markdownlint-restore no-inline-html -->
[notitle]: image.jpg␊
[title]: image.jpg "Title"␊
`,
@ -37726,7 +37844,7 @@ Generated by [AVA](https://avajs.dev).
Bad code \`JavaScript\`. {MD044}␊
<img src="img/javascript/image.png">
<img src="img/javascript/image.png" alt="Description">
<script type="text/javascript">
JavaScript {MD044}␊
@ -39313,7 +39431,7 @@ Generated by [AVA](https://avajs.dev).
Text referencing multiplecase name. {MD044}␊
Text referencing mULTIPLEcASE name.␊
<img src="img/JavaScript/image.png" error="{MD044}">
<img src="img/JavaScript/image.png" alt="Description" error="{MD044}">
<script type="text/JavaScript">
{MD044:94}␊