Skip to content
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 our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add no-generic-link-text rule #10

Merged
merged 17 commits into from Dec 21, 2022
Merged

Add no-generic-link-text rule #10

merged 17 commits into from Dec 21, 2022

Conversation

khiga8
Copy link
Contributor

@khiga8 khiga8 commented Aug 26, 2022

Giving markdownlint rule-making a go 馃挭

  • Pulled out a function used in the test for the first rule into a shared helper.
  • Added a lint rule against generic link text in markdown called no-generic-link-text. This follows a similar rule we have in erblint-github. Seems like this would be a common violation in markdown.

For now this rule only handles inline links because I wanted to avoid the complexities around determining link text of a link tag, especially since different markdown parsers have different levels of ARIA support.

@khiga8 khiga8 requested a review from a team as a code owner August 26, 2022 20:59
@accessibility-bot
Copy link
Collaborator

馃憢 Hello and thanks for pinging us! An accessibility first responder will review this soon.

  • 馃捇 On PRs for our review: please provide a review environment with steps to validate, screenshots (with alt text), or videos (with description following) demonstrating functionality we should be checking. This will help speed up our review and feedback cycle.
  • 鈿狅笍 If this is urgent, please visit us in #accessibility on Slack and tag the first responder(s) listed in the channel topic.

@khiga8 khiga8 requested review from a team, bolonio and owenniblock August 26, 2022 21:56
no-generic-link-text.js Outdated Show resolved Hide resolved
@khiga8
Copy link
Contributor Author

khiga8 commented Dec 20, 2022

I am finally revisiting this as downtime work during FR and following the steps outlined in: https://github.com/github/markdownlint-github#development to try running this rule.

However, I'm finding that the custom rules aren't running at all. I thought that this was a problem with my branch, but I'm seeing that the published package might be broken too.

In the accessibility repo, I introduced a violation but that isn't being flagged... I think the way we're exporting configurations might be off. 馃

Update: It seemed to be an issue with the config in accessibility repo! Proceeding!

@khiga8 khiga8 marked this pull request as draft December 20, 2022 22:41
@khiga8
Copy link
Contributor Author

khiga8 commented Dec 21, 2022

I made some updates because when I tested this against the github/accessibility repo, I found my logic was weird and no violations were being raised! It turns out my understanding of the parser was wrong.

I made additional updates by peeking at a link text related rules in markdownlint (md042) to make sure I was collecting the link text correctly and made my tests more robust. I then tested this against github/accessibility repo which correctly caught 3 violations. I also tested this against github/thehub and it seems to be working well.

I additionally pulled the stripAndDowncaseText out into its own file with tests.

I also added support so consumers can configure additional banned texts like so in addition to the default ones we have:

{
    "no-default-alt-text": true,
    "no-duplicate-header": true,
    "no-generic-link-text": { 
      "additional_banned_texts": ["something"]
    }
}

I opened a separate issue to add docs for each rule: #12.

I am hoping to cut a new release after this!

function: function GH002(params, onError) {
// markdown syntax
const allBannedLinkTexts = bannedLinkText.concat(
params.config.additional_banned_texts || []
Copy link
Contributor Author

@khiga8 khiga8 Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using snake case to follow the convention set in markdownlint for how rule configs are set.

@khiga8 khiga8 marked this pull request as ready for review December 21, 2022 17:08
const allBannedLinkTexts = bannedLinkText.concat(
params.config.additional_banned_texts || []
);
const inlineTokens = params.tokens.filter((t) => t.type === "inline");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found markdown-it demo and using the debug functionality helpful for understanding how markdown is parsed.

Additionally, I referenced: md042.

@khiga8
Copy link
Contributor Author

khiga8 commented Dec 21, 2022

I want to see this rule running in our projects successfully. Then I plan to upstream it to markdownlint. I opened an issue there and got approval (DavidAnson/markdownlint#681).

expect(results[0].errorDetail).toBe("For link: Click here");
});

test("additional words can be configured", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

馃挅

@@ -0,0 +1,50 @@
const { stripAndDowncaseText } = require("./helpers/strip-and-downcase-text");

const bannedLinkText = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible or worth making this work for various languages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin doesn't currently have i18n support, but I added support so people can additionally configure text so they can through that!

Related: #10 (comment)

Copy link
Contributor Author

@khiga8 khiga8 Dec 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we will want to address i18n in a separate issue! I'll make an issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khiga8 khiga8 mentioned this pull request Dec 21, 2022
@khiga8 khiga8 merged commit ea1958d into main Dec 21, 2022
@khiga8 khiga8 deleted the kh-rule branch December 21, 2022 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants