question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expose rule URLs to formatters

See original GitHub issue

ESLint 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 or rule.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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:26 (25 by maintainers)

github_iconTop GitHub Comments

2reactions
not-an-aardvarkcommented, Jan 12, 2018

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 to Linter to get a single rule without copying the map).

1reaction
not-an-aardvarkcommented, Jun 1, 2018

It now occurs to me that we could create a “v2” JSON formatter that serializes an object with two top level properties: results and rules.

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 original json formatter would be obsoleted.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found