eslint / js

Monorepo for the JS language tools.
BSD 2-Clause "Simplified" License
2.29k stars 195 forks source link

Expose acorn plugin from espree module #623

Open molisani opened 2 months ago

molisani commented 2 months ago

The espree parser is defined as a plugin for the Acorn parser. This plugin used to be accessible via espree/lib/espree.js, but this is now an internal module and cannot be imported directly.

Could this value be exported from the package? Something like export const acornPlugin = espree;

nzakas commented 2 months ago

The fact that Espree is currently implemented as an Acorn plugin doesn't mean it always will be, so it doesn't make sense to export the Acorn plugin from the espree package.

However, I've been thinking it might be helpful to look at creating a different package that is more of general "ESLint Acorn plugin" that formats Acorn results in the way ESLint wants them. Espree could then use that, with any additional modifications necessary to get the full Espree experience. That would require a bit of thought, though, as it wouldn't make sense just to take the entire current Espree Acorn plugin and expose that.

@eslint/eslint-team what do you think about this idea?

molisani commented 2 months ago

I'd be perfectly happy if there was another package that exposed an "ESLint Acorn plugin", rather than exposing it from this package.

For context: I have a use case at work where we build a custom Acorn parser with specific behaviors, then we re-use that parser for ESLint. Right now we depend on espree@7 (which doesn't have exports defined on the package.json) so we can just directly import espree/lib/espree. We include the espree plugin with our own plugins and that produces a parser that works with ESLint. I ran into this exports issue when I went to update espree as it was introduced with espree@8.

nzakas commented 2 months ago

@molisani thanks, that's very helpful context, and I think is a vote in favor of exposing the "ESLint Acorn plugin" separately to allow for people to build custom parsers with Acorn that can be used with ESLint.

nzakas commented 2 months ago

Ping @eslint/eslint-tsc

fasttime commented 2 months ago

However, I've been thinking it might be helpful to look at creating a different package that is more of general "ESLint Acorn plugin" that formats Acorn results in the way ESLint wants them. Espree could then use that, with any additional modifications necessary to get the full Espree experience. That would require a bit of thought, though, as it wouldn't make sense just to take the entire current Espree Acorn plugin and expose that.

I like the idea of an Acorn plugin, but to be honest I don't understand what is specific to Espree that is not also specific to ESLint, or was specific to ESLint at some point in time. So I'm not sure what the general "ESLint Acorn plugin" should expose if not the entire current Espree Acorn plugin, as the OP suggested. I'd be happy to comment on a more detailed proposal.

nzakas commented 2 months ago

So I'm not sure what the general "ESLint Acorn plugin" should expose if not the entire current Espree Acorn plugin, as the OP suggested.

I'd need to look more closely, but basically it would be Espree without JSX support or impliedStrict (no ecmaFeatures) and would only export the plugin and not a parse() function.

sam3k commented 1 month ago

Per TSC meeting on 2024-10-17, @mdjermanovic will look more closely into this so the team can make a decision on next steps.

mdjermanovic commented 3 weeks ago

I'm in favor of extracting an ESLint Acorn plugin into a separate package 👍

nzakas commented 3 weeks ago

Marking as accepted. I'll plan on taking a look at this after the CSS and YAML plugins, so if anyone else wants to take a look first, please be my guest.