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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add new rule: no-generic-link-name #1459

Draft
wants to merge 39 commits into
base: next
Choose a base branch
from

Conversation

khiga8
Copy link
Contributor

@khiga8 khiga8 commented Jan 6, 2025

Closes: #681

This PR introduces a new lint rule to discourage generic, unhelpful link names. More context in linked issue!

While this rule has a default set of "banned names", consumers have the option to override the default and set their own banned words through the link_texts config if they'd like.

lib/md039.mjs Outdated Show resolved Hide resolved
@khiga8 khiga8 changed the base branch from main to next January 6, 2025 22:33
@khiga8
Copy link
Contributor Author

khiga8 commented Jan 6, 2025

I'm not sure how to interpret this failure:

 test › markdownlint-test › validateJsonUsingConfigSchemaStrict

  Rejected promise returned by test. Reason:

  SyntaxError {
    message: 'Unexpected token } in JSON at position 42',
  }

I'd appreciate pointers!

@DavidAnson
Copy link
Owner

Great! I'll make a first pass review later tonight. Regarding the test failure you ask about, I think it is due to the trailing commas added to the new configuration comment at the bottom of test/long-lines-long-reference-definitions.md. JSON does not allow trailing commas.

In general, I think this would be the first built-in rule which only works in a single language (English) in its default configuration. I'm not sure how I feel about that... Certainly, all the documentation is in English because that's all I know and it's fairly common as a default language in the industry for documentation and code. However, to have the linting tool itself start to "favor" one language over another feels a little weird?

I'm open to counter-arguments or examples of another built-in rule that behaves like this. At the same time, having this rule default to an empty list would make it less useful. (Though there is precedent for that, see MD044/proper-names.) I do not think I want to start maintaining multiple translations for the phrase list because there are a lot of languages out there and I can only validate English for correctness.

@DavidAnson
Copy link
Owner

I was curious how a similar-ish project handled this situation: get-alex/alex#202

Ugh, that is not really a road I went to start down. My current thinking is to do something similar to MD044/proper-names and default this rule to an empty list.

I'm still open to feedback, though!

Copy link
Owner

@DavidAnson DavidAnson left a comment

Choose a reason for hiding this comment

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

Okay, it may look like a lot, but most of the changes are pretty small. :) Thanks for starting this out - let's continue the conversation around naming and default value in the body of the PR.

README.md Outdated Show resolved Hide resolved
doc/md059.md Outdated Show resolved Hide resolved
helpers/helpers.cjs Outdated Show resolved Hide resolved
helpers/helpers.cjs Outdated Show resolved Hide resolved
helpers/helpers.cjs Outdated Show resolved Hide resolved
test/markdown-in-html.md Outdated Show resolved Hide resolved
test/no-generic-link-name-config-override.md Outdated Show resolved Hide resolved
test/no-generic-link-name.md Outdated Show resolved Hide resolved
test/no-generic-link-name.md Outdated Show resolved Hide resolved
test/table-content-with-issues.md Show resolved Hide resolved
@khiga8
Copy link
Contributor Author

khiga8 commented Jan 7, 2025

Hey @DavidAnson, thank you for your speedy and thorough review!

I like your suggestion of renaming this to descriptive-link-text, so I've made corresponding updates in this PR.

Certainly, all the documentation is in English because that's all I know and it's fairly common as a default language in the industry for documentation and code. However, to have the linting tool itself start to "favor" one language over another feels a little weird?

My current thinking is to do something similar to MD044/proper-names and default this rule to an empty list.

For sure, these are valid concerns!

My personal preference is for setting a default list for the English language (since we have a general sense of common, "non-descriptive names" for the following reasons:

  • If consumers of this project want to expand on the default words, disagree with the defaults, or add support for additional languages, they have the option to do so through the config.
  • Setting some kind of default would make this rule useful for more projects immediately and help spread awareness around best a11y practices versus having to discover this through the docs.

I guess there's also a question around whether this rule should be on/off by default (not sure if you have a standard procedure for new rules?) If this rule is on by default with a list of defaults, some projects will encounter a lot of failure when bumping up the version. But then again, maybe that's okay because if a project doesn't feel ready to enforce the rule, they can turn it off.

Let me know what you think!


Go to this [link]((https://example.com/javascript/about)). {MD059}

[link][1] {MD059}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DavidAnson Is this what you meant by reference link?
Do you have an example of a "shortcut link"?

related: #1459 (comment)

Copy link
Owner

Choose a reason for hiding this comment

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

Copy link
Owner

Choose a reason for hiding this comment

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

Yours is a reference link, but it looks more like a footnote. Let's use something more typical as shown in the examples I link.

@DavidAnson
Copy link
Owner

All rules are enabled by default and I'd like to keep it that way. You make a good point about this being more discoverable if there are default values. Then I'd want to document that there will ONLY be English defaults so people don't PR Klingon or something. I don't mind it breaking for existing sites, but I want to be sure the default list is super obviously bad. Like "here" bad. People can disagree, but nobody should argue that "here" is a good link text. :)

Copy link
Owner

@DavidAnson DavidAnson left a comment

Choose a reason for hiding this comment

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

Looking good, thanks for making all those edits!! After going through these new comments, please update schema/build-config-schema.mjs which will automatically update some of the other files like the schema, etc., once you run npm run ci. I see test failures, but assume it's mostly stuff like this. You may get failures in the TestRepos workflow - use npm run update-snapshots and npm run clone-test-repos then npm run update-snapshots-test-repos to automatically update all the snapshot files. We can have a look at what impact this new rule has on the test repos based on that.

doc-build/md059.md Outdated Show resolved Hide resolved
doc-build/md059.md Show resolved Hide resolved
doc-build/md059.md Outdated Show resolved Hide resolved
doc-build/md059.md Show resolved Hide resolved
doc-build/md059.md Outdated Show resolved Hide resolved
test/descriptive-link-text.md Show resolved Hide resolved
test/descriptive-link-text.md Show resolved Hide resolved

Go to this [link]((https://example.com/javascript/about)). {MD059}

[link][1] {MD059}
Copy link
Owner

Choose a reason for hiding this comment

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

Yours is a reference link, but it looks more like a footnote. Let's use something more typical as shown in the examples I link.

test/descriptive-link-text.md Outdated Show resolved Hide resolved
test/long-lines-long-reference-definitions.md Outdated Show resolved Hide resolved
@khiga8

This comment was marked as outdated.

addErrorContext(
onError,
labelText.startLine,
text,
Copy link
Contributor Author

@khiga8 khiga8 Jan 18, 2025

Choose a reason for hiding this comment

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

 -       errorContext: `[click␍␊
 +       errorContext: `[click␊
         here]`,

I can't figure out why Windows behaves differently and returns a different text for the link test case with a line break. Curious if you might have any ideas @DavidAnson.

Copy link
Owner

Choose a reason for hiding this comment

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

This looks like a \r\n vs. \n line ending difference. If you're getting this error, it's reporting an error that spans multiple lines. I left a comment about preventing that by checking startLine and endLine of the span. (See my comment on the main chat before spending time on this.)

@khiga8
Copy link
Contributor Author

khiga8 commented Jan 18, 2025

Hey @DavidAnson! I believe I've addressed all your comments now. I have one remaining issue I'd appreciate your eyes on - #1459 (comment).

@khiga8 khiga8 requested a review from DavidAnson January 18, 2025 04:50
@DavidAnson
Copy link
Owner

Thank you! I replied to that open issue above. (FYI, I may not get back to this for a couple of days.)

At this stage in the process, I'll make another/final pass over the entire change. It's likely I'll have more nitpicks. Are you okay with me applying them to your PR here? What I typically do is squash the author's comments into one (attributed to then) with a following commit by me titled something like "final tweaks for previous commit". Unless you enjoy my nitpicking, this is probably the most efficient option. :)

One thing I'll do is review every new violation in test-repos. Skimming that now, it looks like the vast majority are "here" and "link" which is expected (plus a couple of "more"s). However, there are about 20 like this in mdn which deserve better understanding. If you beat me to that, please reply here with your thoughts:

test-repos/mdn-content/files/en-us/web/html/attributes/rel/preload/index.md: 105: MD059/descriptive-link-text Link text should be descriptive [Context: "[\`<link>\`]"]

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.

[Proposal] Rule to discourage generic link text
2 participants