xojs/xo

[feat/discussion] allow an option to get rule meta data for lintText

spence-s opened this issue · 4 comments

I was looking into making diagnostics in the vscode extension link to the rule documentation, if available, in the UI. This is accomplished via the engine.getRulesMetaForResults method and is most likely best done in the lintText/lintFiles methods.

After taking a look the simplest way to accomplish this for lintText may something like a very simple 1-2 liner:

if(inputOptions.meta)
	report.rulesMeta = engine.getRulesMetaForResults(report)

I didn't dig too deep into lintFiles, it looks like it'd be more complex, but I'm not sure if it's something we'd even want from the CLI perspective. For my use case here, I would only need it on lintText results.

Alternatively, we could just expose getRulesMetaForResults as a method on XO and you could pass the result from lintText?

We could...the only issue with that is that it is less efficient, in that to do that you'd need to gather up the options 2x and instantiate eslint again separate from the eslint instance that creates the report. I think cosmic config caches everything so it shouldn't be much overhead? That would be my only worry.

@sindresorhus If you let me know which method you'd prefer. I'd be glad to submit a PR for this when I get the time.

Let's go with what you proposed. Sounds better.

decided that there isn't an explicit need for this in xo, since xo generates links with this package, via the pretty formatter. https://www.npmjs.com/package/eslint-rule-docs - which I am also now using in the extension for the same purpose.