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

Add urls pointing to docs on all messages #273

Merged
merged 8 commits into from
Sep 18, 2021
Merged

Add urls pointing to docs on all messages #273

merged 8 commits into from
Sep 18, 2021

Conversation

remcohaszing
Copy link
Member

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and couldn’t find anything (or linked relevant results below)
  • If applicable, I’ve added docs and tests

Description of changes

Allow unified-lint-rule to accept an object instead of a source string, which can specify named properties, including source and url. The url is set on all reported vfile messages.

All remark-lint rules have been updated to use an object and set the url.

Closes #272

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Sep 7, 2021
script/util/rule.js Outdated Show resolved Hide resolved
@codecov-commenter

This comment has been minimized.

Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

I like the idea of adding more metadata for reporters to be able to surface 👍

Comment on lines +27 to +28
const id = typeof meta === 'string' ? meta : meta.origin
const url = typeof meta === 'string' ? undefined : meta.url
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it would make sense to use some of the same semantics eslint uses? 🤔
They leverage a docs field https://eslint.org/docs/developer-guide/working-with-rules#rule-basics

docs (object) is required for core rules of ESLint:

  • description (string) provides the short description of the rule in the rules index
  • category (string) specifies the heading under which the rule is listed in the rules index
  • recommended (boolean) is whether the "extends": "eslint:recommended" property in a configuration file enables the rule
  • url (string) specifies the URL at which the full documentation can be accessed (enabling code editors to provide a helpful link on highlighted rule violations)
  • suggestion (boolean) specifies whether rules can return suggestions (defaults to false if omitted)

In particular, description, category, and url seem relevant.
And having it scoped (to docs or something else) keeps url open to any other uses we may have in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I could nest the url property inside an object property docs. Although none of the other properties seem to map to any properties relevant to vfile messages. I also don’t really see another use case for the url property.

I think it’s fine as-is, but if you feel strong about this and it’s ok with @wooorm,, I’ll introduce the docs object with only url for now.

Copy link
Member

@ChristianMurphy ChristianMurphy Sep 8, 2021

Choose a reason for hiding this comment

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

I don't feel strongly about scoping.
I do find url floating in meta confusing though.
If I saw

{
  origin: "something",
  url: "https://example.com"
}

without some additional context/comments, I'd have very little understanding of the intent.

Something like:

{
  lintRuleName: "something",
  documentationUrl: "https://example.com"
}

would be more verbose, but clearer.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree if you put it that way. Although url and origin match the names of the properties on vfile messages they represent.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm, thoughts @wooorm? 💭

Another approach could be to update the type definition to carry some description through.
#273 (comment)
Which would benefit folks using an IDE with TS-language-server support, but would still leave ambiguity otherwise.

Copy link
Member

@wooorm wooorm Sep 8, 2021

Choose a reason for hiding this comment

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

  • category — that’s a bit like origin
  • recommended — more needed because ESLint does stuff by default, whereas remark-lint is opt-in only
  • suggestion — some retext rules add an actual/expected, but lint rules don’t
  • description — how much should this be? Markdown? Short message? Isn’t either the error message or the full readme enough? vfile-reporter does support a note I believe btw, which can have some more information

Re Christian’s point on:

{
  origin: "something",
  url: "https://example.com"
}

looking nondescript, I’d say that perhaps it is that way because of how it’s abstracted. A more practical example:

{
  origin: 'remark-lint:blockquote-indentation',
  url: 'https://github.com/remarkjs/remark-lint/tree/main/packages/remark-lint-blockquote-indentation#readme'
},

looks clear to me.


And for types as an alternative, the description is already defined in the types (@fileoverview) and extracted and put into the readme.
We could:

  • Put that description in the JSDoc attached to the rule
  • Put the description in a string (and the URL), and instead generate the readme based on actual code rather than comments

Copy link
Member Author

Choose a reason for hiding this comment

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

We could:

  • Put that description in the JSDoc attached to the rule
  • Put the description in a string (and the URL), and instead generate the readme based on actual code rather than comments

Yes, we could. Although I doubt this has much added value. unified-lint-rule could support note anyway, but I think this is out of scope for this PR.

test.js Outdated Show resolved Hide resolved
script/util/rule.js Outdated Show resolved Hide resolved
Co-authored-by: Christian Murphy <christian.murphy.42@gmail.com>
Copy link
Member

@ChristianMurphy ChristianMurphy left a comment

Choose a reason for hiding this comment

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

Probably outside of the scope of the PR, but another thing I noticed.
The readme for unified-lint-rule doesn't include an API section

packages/unified-lint-rule/index.d.ts Outdated Show resolved Hide resolved
@ChristianMurphy ChristianMurphy added 📚 area/docs This affects documentation 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Sep 8, 2021
remcohaszing and others added 3 commits September 8, 2021 19:31
test.js Show resolved Hide resolved
@wooorm
Copy link
Member

wooorm commented Sep 12, 2021

Looks good to me. @ChristianMurphy?

@wooorm wooorm changed the title Specify urls on vfile messages Add urls pointing to docs on all messages Sep 18, 2021
@wooorm wooorm merged commit 201e995 into remarkjs:main Sep 18, 2021
@github-actions

This comment has been minimized.

@wooorm wooorm added the 💪 phase/solved Post is done label Sep 18, 2021
@github-actions github-actions bot removed the 🤞 phase/open Post is being triaged manually label Sep 18, 2021
@wooorm
Copy link
Member

wooorm commented Sep 18, 2021

Released!

simnalamburt pushed a commit to simnalamburt/remark-lint that referenced this pull request Mar 19, 2024
Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>

Closes remarkjsGH-272.
Closes remarkjsGH-273.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 area/docs This affects documentation 🗄 area/interface This affects the public interface 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

Add url to vfile messages
4 participants