Skip to content

Commit b344b1a

Browse files
authored
Update regex logic for flagging alt text (#38)
1 parent 22916a1 commit b344b1a

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Regex to match alt text that is the same as the default image filename
22
// e.g. "Screen Shot 2020-10-20 at 2 52 27 PM"
33
// e.g. "Screenshot 2020-10-20 at 2 52 27 PM"
4+
// e.g. "Clean Shot 2020-10-20 @45x"
5+
// e.g. "image"
46
const defaultMacOsScreenshotMarkdownRegex =
5-
/^Screen ?[S|s]hot \d{4}-\d{2}-\d{2} at \d \d{2} \d{2} [A|P]M$/gi;
7+
/^(Screen|Clean) ?[S|s]hot \d{4}-\d{2}-\d{2}/gi;
68
const imageMarkdownRegex = /^image$/i;
79

810
const defaultMacOsScreenshotHtmlRegex =
9-
/alt="Screen ?[S|s]hot \d{4}-\d{2}-\d{2} at \d \d{2} \d{2} [A|P]M"/gi;
11+
/alt="(Screen|Clean) ?[S|s]hot \d{4}-\d{2}-\d{2}/gi;
1012
const imageHtmlRegex = /alt="image"/i;
1113

1214
module.exports = {

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe("GH001: No Default Alt Text", () => {
3333
"![ScreenShot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)",
3434
"![Screen shot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)",
3535
"![Screenshot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)",
36+
"![Clean Shot 2022-06-26 at 7 41 30 PM](https://user-images.githubusercontent.com/abcdef.png)",
3637
"![image](https://user-images.githubusercontent.com/abcdef.png)",
3738
"![Image](https://user-images.githubusercontent.com/abcdef.png)",
3839
];
@@ -44,7 +45,7 @@ describe("GH001: No Default Alt Text", () => {
4445
.flat()
4546
.filter((name) => !name.includes("GH"));
4647

47-
expect(failedRules).toHaveLength(6);
48+
expect(failedRules).toHaveLength(7);
4849
for (const rule of failedRules) {
4950
expect(rule).toBe("no-default-alt-text");
5051
}
@@ -56,6 +57,7 @@ describe("GH001: No Default Alt Text", () => {
5657
'<img alt="ScreenShot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
5758
'<img alt="Screen shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
5859
'<img alt="Screenshot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
60+
'<img alt="Clean Shot 2022-06-26 at 7 41 30 PM" src="https://user-images.githubusercontent.com/abcdef.png">',
5961
'<img alt="Image" src="https://user-images.githubusercontent.com/abcdef.png">',
6062
'<img alt="image" src="https://user-images.githubusercontent.com/abcdef.png">',
6163
];
@@ -67,7 +69,7 @@ describe("GH001: No Default Alt Text", () => {
6769
.flat()
6870
.filter((name) => !name.includes("GH"));
6971

70-
expect(failedRules).toHaveLength(6);
72+
expect(failedRules).toHaveLength(7);
7173
for (const rule of failedRules) {
7274
expect(rule).toBe("no-default-alt-text");
7375
}

0 commit comments

Comments
 (0)