Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc29f004

Browse files
authored
Update and add more test coverage forno-default-alt-text (#84)
* Make sure that HTML that is inlined is supported* Add detail* Update the helpers to support multiple errors in one line* add test support
1 parent98da1c7 commitc29f004

6 files changed

+33
-18
lines changed

‎src/rules/no-default-alt-text.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ module.exports = {
2323
function:functionGH001(params,onError){
2424
consthtmlTagsWithImages=params.parsers.markdownit.tokens.filter(
2525
(token)=>{
26-
returntoken.type==="html_block"&&token.content.includes("<img");
26+
return(
27+
(token.type==="html_block"&&token.content.includes("<img"))||
28+
(token.type==="inline"&&
29+
token.content.includes("<img")&&
30+
token.children.some((child)=>child.type==="html_inline"))
31+
);
2732
},
2833
);
2934
constinlineImages=params.parsers.markdownit.tokens.filter(
@@ -36,12 +41,15 @@ module.exports = {
3641
constlineRange=token.map;
3742
constlineNumber=token.lineNumber;
3843
constlines=params.lines.slice(lineRange[0],lineRange[1]);
39-
4044
for(leti=0;i<lines.length;i++){
4145
constline=lines[i];
4246
letmatches;
4347
if(token.type==="inline"){
44-
matches=line.matchAll(markdownAltRegex);
48+
if(token.children.some((child)=>child.type==="html_inline")){
49+
matches=line.matchAll(htmlAltRegex);
50+
}else{
51+
matches=line.matchAll(markdownAltRegex);
52+
}
4553
}else{
4654
matches=line.matchAll(htmlAltRegex);
4755
}
@@ -51,6 +59,7 @@ module.exports = {
5159
onError({
5260
lineNumber:lineNumber+i,
5361
range:[startIndex+1,altText.length],
62+
detail:`Flagged alt:${altText}`,
5463
});
5564
}
5665
}

‎test/accessibility-rules.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("when A11y rules applied", () => {
2626
.map((failure)=>failure.ruleNames)
2727
.flat();
2828

29-
expect(failuresForExampleFile).toHaveLength(1);
29+
expect(failuresForExampleFile).toHaveLength(3);
3030
expect(failureNames).toContain("no-default-alt-text");
3131
});
3232
});

‎test/example.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#Example Violations
22

33
![Screen Shot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)
4+
5+
<imgalt="image"><imgalt="Image">

‎test/no-default-alt-text.test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ describe("GH001: No Default Alt Text", () => {
1111
];
1212

1313
constresults=awaitrunTest(strings,altTextRule);
14-
15-
for(constresultofresults){
16-
expect(result).not.toBeDefined();
17-
}
14+
expect(results.length).toBe(0);
1815
});
1916
test("html image",async()=>{
2017
conststrings=[
2118
'<img alt="A helpful description" src="https://user-images.githubusercontent.com/abcdef.png">',
2219
];
2320

2421
constresults=awaitrunTest(strings,altTextRule);
25-
26-
for(constresultofresults){
27-
expect(result).not.toBeDefined();
28-
}
22+
expect(results.length).toBe(0);
2923
});
3024
});
3125
describe("failures",()=>{
@@ -77,6 +71,17 @@ describe("GH001: No Default Alt Text", () => {
7771
}
7872
});
7973

74+
test("flags multiple consecutive inline images",async()=>{
75+
conststrings=['<img alt="image"><img alt="Image">'];
76+
constresults=awaitrunTest(strings,altTextRule);
77+
expect(results).toHaveLength(2);
78+
79+
expect(results[0].errorRange).toEqual([11,5]);
80+
expect(results[0].errorDetail).toEqual("Flagged alt: image");
81+
expect(results[1].errorRange).toEqual([28,5]);
82+
expect(results[1].errorDetail).toEqual("Flagged alt: Image");
83+
});
84+
8085
test("error message",async()=>{
8186
conststrings=[
8287
"![Screen Shot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)",

‎test/no-generic-link-text.test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ describe("GH002: No Generic Link Text", () => {
1717
];
1818

1919
constresults=awaitrunTest(strings,noGenericLinkTextRule);
20-
21-
for(constresultofresults){
22-
expect(result).not.toBeDefined();
23-
}
20+
expect(results.length).toBe(0);
2421
});
2522
});
2623
describe("failures",()=>{

‎test/utils/run-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function runTest(strings, rule, ruleConfig) {
1111
customRules:[rule],
1212
};
1313

14-
returnawaitPromise.all(
14+
constresults=awaitPromise.all(
1515
strings.map((variation)=>{
1616
constthisTestConfig={
1717
...config,
@@ -21,11 +21,13 @@ async function runTest(strings, rule, ruleConfig) {
2121
returnnewPromise((resolve,reject)=>{
2222
markdownlint(thisTestConfig,(err,result)=>{
2323
if(err)reject(err);
24-
resolve(result[0][0]);
24+
resolve(result[0]);
2525
});
2626
});
2727
}),
2828
);
29+
30+
returnresults.flat();
2931
}
3032

3133
exports.runTest=runTest;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp