Skip to content

Commit f5b1e48

Browse files
committed
Allow rule params to be configured
1 parent cce4a05 commit f5b1e48

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

no-generic-link-text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const stripAndDowncaseText = (text) => {
1212
return text
1313
.toLowerCase()
1414
.replace(/[.,/#!$%^&*;:{}=\-_`~()]/g, "")
15-
.replace(/\s{2,}/g, " ")
15+
.replace(/\s+/g, " ")
1616
.trim();
1717
};
1818

@@ -27,7 +27,7 @@ module.exports = {
2727
function: function GH002(params, onError) {
2828
// markdown syntax
2929
const allBannedLinkTexts = bannedLinkText.concat(
30-
params.config.banned_link_texts || []
30+
params.config.additional_banned_texts || []
3131
);
3232
const inlineTokens = params.tokens.filter((t) => t.type === "inline");
3333
for (const token of inlineTokens) {

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ describe("GH002: No Generic Link Text", () => {
99
"[Read more about GitHub](https://www.github.com/about)",
1010
"[](www.github.com)",
1111
"![Image](www.github.com)",
12-
"I am not a link, and unrelated",
12+
`
13+
## Hello
14+
I am not a link, and unrelated.
15+
![GitHub](some_image.png)
16+
`,
1317
];
1418

1519
const results = await runTest(strings, noGenericLinkTextRule);
@@ -20,12 +24,13 @@ describe("GH002: No Generic Link Text", () => {
2024
});
2125
});
2226
describe("failures", () => {
23-
test("markdown example", async () => {
27+
test("inline", async () => {
2428
const strings = [
2529
"[Click here](www.github.com)",
2630
"[here](www.github.com)",
2731
"Please [read more](www.github.com)",
2832
"[more](www.github.com)",
33+
"[link](www.github.com)",
2934
"You may [learn more](www.github.com) at GitHub",
3035
"[learn more.](www.github.com)",
3136
"[click here!](www.github.com)",
@@ -38,10 +43,26 @@ describe("GH002: No Generic Link Text", () => {
3843
.flat()
3944
.filter((name) => !name.includes("GH"));
4045

41-
expect(failedRules).toHaveLength(7);
46+
expect(failedRules).toHaveLength(8);
4247
for (const rule of failedRules) {
4348
expect(rule).toBe("no-generic-link-text");
4449
}
4550
});
51+
52+
test("additional words can be configured", async () => {
53+
const results = await runTest(
54+
["[something](www.github.com)"],
55+
noGenericLinkTextRule,
56+
// eslint-disable-next-line camelcase
57+
{ additional_banned_texts: ["something"] }
58+
);
59+
60+
const failedRules = results
61+
.map((result) => result.ruleNames)
62+
.flat()
63+
.filter((name) => !name.includes("GH"));
64+
65+
expect(failedRules).toHaveLength(1);
66+
});
4667
});
4768
});

test/utils/run-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const markdownlint = require("markdownlint");
22

3-
async function runTest(strings, rule) {
3+
async function runTest(strings, rule, ruleConfig) {
44
const thisRuleName = rule.names[1];
55

66
const config = {
77
config: {
88
default: false,
9-
[thisRuleName]: true,
9+
[thisRuleName]: ruleConfig || true,
1010
},
1111
customRules: [rule],
1212
};

0 commit comments

Comments
 (0)