Skip to content

Commit 2eee636

Browse files
feat: finalizes interface for consuming codebases (#4)
1 parent bedef2f commit 2eee636

11 files changed

Lines changed: 431 additions & 3883 deletions

index.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
const _ = require('lodash')
22

3+
const accessibilityRules = require('./style/accessibility.json')
4+
const base = require('./style/base.json')
35
const noDefaultAltText = require('./no-default-alt-text')
46

5-
const customRules = [noDefaultAltText]
7+
const customRules = [
8+
noDefaultAltText
9+
]
610

7-
const base = {
8-
config: {},
9-
customRules
10-
}
11+
module.exports = [...customRules]
1112

1213
customRules.forEach(rule => {
13-
base.config[rule.names[1]] = true
14+
base[rule.names[1]] = true
1415
})
1516

16-
module.exports.overwriteWith = function overwriteWith(consumerConfig) {
17-
// defaults are right-most
18-
return _.defaultsDeep(consumerConfig, base)
17+
module.exports.init = function init(consumerConfig) {
18+
// left overwrites right
19+
return _.defaultsDeep(consumerConfig, accessibilityRules, base)
1920
}
20-
21-
22-
module.exports = [...customRules]

no-default-alt-text.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
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-
const altTextRegex = /^Screen\s?shot \d{4}-\d{2}-\d{2} at \d \d{2} \d{2} [A|P]M$/gi
5-
const altTextTagRegex = /alt=\"Screen\s?shot \d{4}-\d{2}-\d{2} at \d \d{2} \d{2} [A|P]M\"/gi
4+
const altTextRegex = /^Screen ?[S|s]hot \d{4}-\d{2}-\d{2} at \d \d{2} \d{2} [A|P]M$/gi
5+
const altTextTagRegex = /alt=\"Screen ?[S|s]hot \d{4}-\d{2}-\d{2} at \d \d{2} \d{2} [A|P]M\"/gi
66

77
module.exports = {
8-
"names": ["GH001", "no-default-alt-text"],
9-
"description": "Images should not use the MacOS default screenshot filename as alternate text (alt text). For more information see: https://primer.style/design/accessibility/alternative-text-for-images",
8+
"names": [ "GH001", "no-default-alt-text" ],
9+
"description": "Images should not use the MacOS default screenshot filename as alternate text (alt text). If you have not changed this file, try merging main with your branch. For more information see: https://primer.style/design/accessibility/alternative-text-for-images",
1010
"information": new URL("https://primer.style/design/accessibility/alternative-text-for-images"),
11-
"tags": ["accessibility", "images"],
11+
"tags": [ "accessibility", "images" ],
1212
"function": function GH001(params, onError) {
13+
// markdown syntax
1314
params.tokens.filter(t => t.type === "inline").forEach(token => {
1415
token.children.filter(t => t.type === "image").forEach(image => {
1516
if (image.content.match(altTextRegex)) {
@@ -21,6 +22,7 @@ module.exports = {
2122
})
2223
})
2324

25+
// html syntax
2426
let lineNumber = 1
2527
params.lines.forEach(line => {
2628
if (line.match(altTextTagRegex)) {
@@ -32,4 +34,4 @@ module.exports = {
3234
lineNumber++
3335
})
3436
}
35-
}
37+
}

0 commit comments

Comments
 (0)