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
Expose rule URLs to formatters #9841
Comments
What if we built a custom |
We sort of already do that with
I think it would have been better if we had provided accessor functions directly like |
You could make a custom |
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 |
We could add EDIT: we’d also need a |
I'm not sure I fully understand the discussion here. ESLint already attaches some internal information when |
This would work. We should consider where we put the metadata on the result object; for example, if we add metadata to every reported problem, we will end up with a lot of duplication. As a sidenote, I'm wondering if it would be better to provide
We don't need to do this if we attach the metadata to the result object. The implementation in #9840 proposed adding a separate argument to the formatter API, containing a map of all loaded rules. |
I see. I don't have an objection to attaching Yes, there's a potential for number of repeated data on a large set of errors. Not sure we need to optimism for that right away, but maybe we should. |
Why the concern about repeated data? It’s just a bunch of pointers in memory, right? The original use case for exposing a rule’s docs is to provide contextual help when reporting a problem. Attaching that info to the problem object has always made sense to me. |
You're correct that the rule metadata would only appear once in memory initially, but formatters that serialize the result object (like When running a big lint job which reports a lot of errors, the formatter output can get extremely large and can cause the process to run out of memory (e.g. #4731). I think we try to keep the result object reasonably small to prevent this from happening. |
The message object contains fix information-- the value isn't useful to the user, but the presence of the |
Personally, I would love to see an extra argument be added for this and other information. As a side note: This might finally allow my proposal to support arbitrary formatter options (with ESLint not knowing or caring about the structure of the options and just passing them through to formatters) to get off the ground... |
I was originally in favor of adding an extra argument for this, but on reconsideration I'm not sure it's a good idea. Presumably, anyone using a formatter like One nice thing about having a single serializable argument for formatters is that it allows linting results to be portable. If you use the |
Can the json formatter filter out noisy data? Or use |
I don't think filtering out the noisy data is a good idea for the reasons described in #9841 (comment) (it would effectively be deleting information, which would prevent consumers from using that information). It could use something like |
It's not directly related, but if we added something like this then it could partially solve the problem of report objects being too large, because users of the |
I’m simply proposing the JSON formatter’s behavior wouldn’t change. It would output no more or less information than it does now. |
I realize that, but I don't think it's ideal because it would prevent external integrations from taking advantage of rule metadata. |
Is there a reason the JSON has to match the exact structure of the API? |
I don't think it's an absolute requirement, but it makes things more convenient because the results object is the same regardless of whether you (a) use a custom formatter, or (b) use the |
@pmcelhaney @not-an-aardvark Where are we at on this? |
If I remember correctly, we want to pass a copy of a rule’s If we keep the metadata out of the results object by passing the rules as a second argument, we cheat the JSON object out of valuable information. It now occurs to me that we could create a “v2” JSON formatter that serializes an object with two top level properties: Would that work? |
@pmcelhaney That's a good idea and worth considering. Another might be to add a second argument to formatters (the options thing), and the existing formatter could use that to decide whether to include the new top level or just include the results only (default behavior). Thanks for your input! Hopefully we can get this moving again 😄 |
That seems like a reasonable compromise to me, although I think it would be better to give the formatter a name like |
As this is a core change, it falls under our new RFC process. I'd suggest that if we want to move this forward, that someone put together an RFC. Details can be found here: Thanks! |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
ESLint Version: 4.15.0
Now that
url
has been added tometa.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:
{ 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.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.)The text was updated successfully, but these errors were encountered: