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
Allow registering parsers with Node.js API #13694
Comments
Hi @molisani, thanks for the issue!
Can you please provide more details about your use case, is the intention to use ESLint in browsers? |
Sure, I can explain. This not for use in the browser. We currently have an eslint plugin + parser setup for projects that use one of our internal JS environments. Right now, users are required to install and configure these manually in order to run our custom lint rules (with the parser). However, we also ship a cli as our primary interface (they're how users build/run projects for this environment). We are investigating the solution of including eslint and these plugins and parsers as dependencies of the cli tool, so that users don't have to set up their own eslint environment. From there, we could use webpack or some other bundler to reduce the deployed size. I first noticed this when I was attempting to use the |
It's worth noting that this plugin strategy is going to change completely with the new config system in development. As such, we aren't making any further changes to the current config system (it will make achieving backwards compatibility a lot harder). With the new config system, ESLint will no longer be doing any module resolving and you'll be able to slide in any object from anywhere you so choose. |
Is the entire internal config system locked down now? Is there any way that this feature could be landed just for the Node.js API ( It doesn't seem like to much code to implement, but if you're not making any changes to this part of the code I understand. |
It doesn't look like a trivial change, because it should also account for If we add a feature to pass a parser object through the ESLint API, then we should probably somehow make sure that
There are cli tools like standard and xo that use ESLint and plugins as runtime dependencies. I'm not sure if there are tools that successfully bundle them instead. |
@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. |
After looking through |
The 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 specifyoptions.plugins
. These plugins then get stored in theadditionalPluginPool
map inside thatESLint
instance (src). When loading a plugin, if it is found in theadditionalPluginPool
, it does not trigger theModuleResolver
(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 internalModuleResolver
.Your take on the correct solution to problem.
Apply the same strategy used for plugins to parsers. Create a new, optional
parsers
property onESLint.Options
that would populate anadditionalParserPool
map. Then on parser load, check thisadditionalParserPool
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.
The text was updated successfully, but these errors were encountered: