- Notifications
You must be signed in to change notification settings - Fork5
Introduce ano-empty-alt-text
rule#85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
### Incorrect 👎 | ||
```md | ||
 |
iansan5653Oct 6, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not sure about this example. The alt text in the Markdown form is never quoted like an HTML property, so this would result in an image tag like<img alt='""' src="cat.png" />
. While an alt text of""
is not useful, it's not empty either. The only way to create a truly empty alt tag in Markdown is with the HTML formalt=""
, so maybe we should only focus on HTML for this rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think auseful-alt-text
rule might be an interesting avenue to explore, where we ban things like "screenshot", "image", "example", '""', etc. But I think that's a separate rule from empty text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah! You're right -- thank you for catching that! I'll stick with HTML for this rule!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
useful-alt-text
Theno-default-alt-text currently flags alternative text like,image
,Image
,Screen Shot 2022-06-26 at 7 41 30 PM
though it's not comprehensive by any means. We could potentially expand on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yeah, I think we definitely could expand on that! It might be interesting to see if we can run a query to figure out what the most common alt texts are across GitHub -- I bet the top 20 or so are all things we'd probably want to lint against.
src/rules/no-empty-string-alt.js Outdated
const inlineImages = params.parsers.markdownit.tokens.filter( | ||
(token) => | ||
token.type === "inline" && | ||
token.children.some((child) => child.type === "image"), | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Per other comment - we probably should limit this rule to just HTML tags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Removed markdown syntax in00fc5dd!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
test/no-empty-string-alt.test.js Outdated
expect(results).toHaveLength(0); | ||
}); | ||
}); | ||
describe("failures", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Not super important, but it might also be useful to have a test for two failures in one line, like:
<imgsrc="cat.png"alt="" /> <imgsrc="dog.png"alt="" />
I think we do handle this correctly with theg
flag and iterating over matches per line, but it probably would still be good to test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Good idea! Done in8f80d4d.
src/rules/index.js Outdated
rules: [ | ||
require("./no-default-alt-text"), | ||
require("./no-generic-link-text"), | ||
require("./no-empty-string-alt"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🤔 Maybe we should call this oneno-empty-alt
orno-empty-alt-text
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I likeno-empty-alt-text
!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Renamed inf2d9774.
Co-authored-by: Ian Sanders <iansan5653@github.com>
Co-authored-by: Ian Sanders <iansan5653@github.com>
This reverts commit5b17abf.Reverting because we are using this index.
no-empty-string-alt
ruleno-empty-alt-text
ruleThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Should we export a preset for GitHub markdown?
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Ian Sanders <iansan5653@github.com>
Co-authored-by: Ian Sanders <iansan5653@github.com>
discussing over Slack! |
Uh oh!
There was an error while loading.Please reload this page.
This PR introduces a new rule,
no-empty-alt-text
which nudges people to add alt text when they set an image to decorative. Settingalt=""
to mark decorative images is usually acceptable, but currently leads to unexpected behaviors, specifically on GitHub.There is currently a known issue on GitHub where all images are rendered inside of an anchor tag. As a result of this, decorative images result in links without an accessible name. Therefore, it's a good idea to always set alt text on markdown images on GitHub. However, this rule isn't really a long term solution and this issue is best fixed in GitHub in the long-term.
This rule should be removed in the future when we stops wrapping images in anchor tags.
We plan to enable this ingithub/accessibility-alt-text-bot#33.