Allow registering parsers with Node.js API
See original GitHub issueThe version of ESLint you are using.
7.9.0
The problem you want to solve.
When using the ESLint
class, it is possible to directly specify options.plugins
. These plugins then get stored in the additionalPluginPool
map inside that ESLint
instance (src). When loading a plugin, if it is found in the additionalPluginPool
, it does not trigger the ModuleResolver
(src). This provides the ability to bundle this code in a such a way that does not rely on eslint’s internal module resolution.
However, no such additional pool exists for parsers. When loading a parser, it immediately triggers the ModuleResolver
(src). Therefore, it appears that there is no way to use custom parsers in ESLint without relying on the internal ModuleResolver
.
Your take on the correct solution to problem.
Apply the same strategy used for plugins to parsers. Create a new, optional parsers
property on ESLint.Options
that would populate an additionalParserPool
map. Then on parser load, check this additionalParserPool
before moving to module resolution.
Are you willing to submit a pull request to implement this change? Yes, but I’d have to check with my current employer first in regards to the CLA.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
After looking through
xo
it appears that they userequire.resolve
(src) to pull in parser dependencies. I believe that webpack (for example) supports bundling static usage ofrequire.resolve
so that should work. With that workaround I’ll close this out. Thanks @mdjermanovic and @nzakas for the information and insight!@molisani the new config system is fairly well defined. You can get more details by visiting the issue I linked to. I really don’t want to add something that will be deprecated once the new config system is complete.
@mdjermanovic we are actually deprecating context.parserPath as part of the config changes. It will be replaced by context.parser.