Expose rule URLs to formatters
See original GitHub issueESLint Version: 4.15.0
Now that url
has been added to meta.docs
(#6582) we can use that field to share more information about a rule in the output.
The most obvious place to start is the HTML formatter, which includes links to rule documentation. Currently the links only work for core rules because eslint.org
is hard-coded in the URL.
I opened a pull request (#9840) to get an idea of what kind of changes would be needed, and @not-an-aardvark has some great comments, which I’m just going to copy verbatim:
- I like the idea here – it seems like it would be useful to provide url info to formatters.
- If we do add a second argument to formatters, I think it should be an object (perhaps something like
{ rules: ruleMap }
) rather than the rule map itself. That way, if we want to provide additional information to formatters in a later enhancement, we could add it to the same object, so formatters wouldn’t need to remember the argument order and do something like function(results, unused, newInfo) {}. getRules
is currently somewhat slow, because it requires it requires loading all core rules from the filesystem, and copying a map of rules with ~250 elements. (Currently, we only load a core rule for the first time when it’s actually used, which reduces startup time.) I wonder if it would be better to pass an object like{ getRule: ruleName => rule }
to the formatter, so that it would only need to load the rules that are needed.- As an open question, would it be better to just give formatters access to
rule.meta
orrule.meta.docs
rather than giving access to a rule itself? Giving formatters access to a rule object itself would allow them to do things such as rerunning the rule, which seems like it could be confusing because formatters are just supposed to apply a transformation to the results. (Admittedly, I’m not sure why a formatter would want to rerun the rule, but ideally I think we should provide the minimal API needed to be useful.)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:26 (25 by maintainers)
Top Results From Across the Web
URL Formatting Requirements - Win32 apps - Microsoft Learn
URL Formats in Use For example, Microsoft Outlook supports folder names with arbitrary characters, including those that are illegal in URLs ...
Read more >URL format - Cloudflare Image Optimization
URL format. You can convert and resize images by requesting them via a specially-formatted URL. This way you do not need to write...
Read more >Creating and managing Lambda function URLs
Configure a Lambda function URL to assign an HTTP(S) endpoint to your Lambda function without having to integrate with other AWS services.
Read more >Basic writing and formatting syntax - GitHub Docs
Create sophisticated formatting for your prose and code on GitHub with simple syntax.
Read more >Dynamic URLs vs. static URLs | Google Search Central Blog
Fact: There is no limit on the number of parameters, but a good rule of thumb would be to ... If you have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That could work, although I feel like it’s a lot of complexity for something that users shouldn’t need to do anyway. Maybe a better solution would be to make a breaking change and not allow users to mutate anything (maybe by exposing a similar interface that doesn’t have any mutator methods, or adding something like
getRule
toLinter
to get a single rule without copying the map).That seems like a reasonable compromise to me, although I think it would be better to give the formatter a name like
json-with-metadata
rather than “v2” to avoid implying that the originaljson
formatter would be obsoleted.