-
-
Notifications
You must be signed in to change notification settings - Fork 209
Feature: Enable syntax based on reading from .babelrc
#573
Comments
Makes perfect sense to me. Much better long term solution and it's good for perf, too. |
I'd like to work on this. |
And agree, I think it should use the new |
Awesome, looks like @loganfsmyth was thinking about the babel side in babel/babel#6332 (comment) (didn't realize we had a PR for getting parserOpts earlier) |
fwiw, once this is implemented, the airbnb eslint config can finally switch parsers to babel-eslint, since we’ll be able to get parsing errors on syntax we’re not transforming - this includes enabling async/await and class fields. |
As for a fallback, i would definitely want a parser option that caused the linting run to fail outright if there’s no babel config present. |
I have some time to work on this right now, but wanted to make sure we agreed on an API. @loganfsmyth's suggestion of exposing a parsing method that would do config loading, parse, and return the AST seems like a good suggestion to me. This is similar to how Does this seem like a good way forward here? cc @JamesHenry if you have any suggestions, having worked with what I believe to be a similar architecture for typescript-eslint-parser |
It looks like @xtuc is actually working on this, so I'll unassign myself. |
I had the intention to do so, but missing time unfortunately. Feel free to take it. Don't hesitate to ping me tho. |
Ok so after babel/babel#7291 I think we would make a peerDep on |
Yeah, though it'll have to have a minimum requirement of a beta version, which is kind of weird? |
I think it would be that way unless it's backported, same with the other integrations unfortunately |
Wait, so that PR is sufficient to close this? Now babel-eslint can automatically read my babelrc and will refuse to parse things i don’t transform? |
That's the first step, looks like this just got closed when that was merged. |
Yeah still need a PR on this end for sure |
I have a PR in the works. Edit: Waiting on the next Babel release, which should be soon! |
And sorry, didn't mean to link that. This was the only open issue and I went into autopilot 😅 |
In the meantime, we can discuss this: babel/babel#7291 (comment) Copying and pasting my question for ease of discussion:
It looks like there's general consensus around 1 or 3, with one vote for 1. I'm also leaning towards 1 because I think it provides clarity around when someone should be using babel-eslint vs the default parser, which seems to have been a point of confusion for a long time. |
I'm fine with |
My use case is that i want to specify targets and transforms, and i want the linting task to fail loudly when any other syntax is encountered. Is that option 1? |
I'd like to also add I think that it is easier to reason about than 3, because we avoid the hardcoded and hardly up to date list of plugins. The warning would have the same effect of 1, but users can choose to ignore it. |
@ljharb Just to be clear - you mean specify targets and transforms in your |
@ljharb That would be the case either way, this list is specifically for if a file has been ignored in the Babel config. @kaicataldo I agree with @nicolo-ribaudo here, I'd say if we did have a fallback it should be the no-plugins version. |
How does everyone feel about going with option 1 and, if users can ask for it, add option 5? |
As a user, I'm not sure if I understand what default plugins vs no plugins means. The lease surprising thing would be to do what babel does. If that means loading default plugins in absence of a user config, it should probably do that. However, the default list of plugins should be kept in babel, not maintained as a separate list in babel-eslint - I'm assuming that's what "may not be up to date" meant. I think this extends beyond just babel-eslint does though. There should be a standard set for every tool that uses babel, which IMO should be "use .babelrc; do what babel does". There needs to be a consistent expectation set, no matter what tool is used. |
@lukescott This question only applies if your Babel config for instance had
what happens if you try to lint a file in So we either
|
Throw an error. Always better to fail loudly than silently. |
(To clarify, eslint should ignore things via eslintignore, not via babel ignore) |
I think the main thing that made me unsure is that if you forget to put something in |
Oh, got it. Thanks for the clarification. Failing loudly for now sounds good to me 👍 Just out of curiosity, if someone did want to lint |
@lukescott ESLint also has glob-based configuation. Looks like Babel was released yesterday - will be able to start working on this PR in earnest today. |
I've come across a small snag in working on this. The location information is stripped from errors thrown by the parser when calling @loganfsmyth I'm happy to chat about this in the Babel Slack in real time if it's easier, but it looks like we'll have to figure out some way to not strip this information out if we want to use the same logic that's used to process files during a full transform run. |
As an update - we've landed a PR that adds this location information back in (babel/babel#7314). I'm just waiting on the next Babel release so that I can finish the babel-eslint PR. |
Have a WIP PR up here: #594. I have to dig into testing next, but wanted to see what everyone thought of the implementation. |
Nice, this is fixed by #711 thanks to @kaicataldo, will be in the next release! haha noticed this was a year ago |
Ref #434 (subset of syntax), #523 (user plugins), #505 (Typescript)
babel-eslint/lib/parse.js
Lines 18 to 22 in bf27f60
Instead of having to:
*
option (found out that was a bad idea due to breaking changes between plugins like decorators/decorators2 so wouldn't be able to easily resolve that)We should be able to just read from a user's Babel config.
@babel/core
should expose a way for another tool to get relevant information from a user's config file (like return the list of syntax plugins used).babel-eslint
could try to read that and just populate the parser options and we can remove the defaults. I think it's safe to assume if you are using babel-eslint you are using babel, and should have a config (can wrap in try/catch or fallback to default list)?@babel/core
maybe? Then it would use the version of babel in your project rather than it's own dep. And maybe the same for the eslint deps?babel-eslint/package.json
Lines 14 to 17 in bf27f60
edit: I believe we are only using
@babel/types
to get the the VISITOR_KEYS, and traverse to do a fast transform of the ASTThoughts? cc @ljharb @kaicataldo @loganfsmyth @azz @danez @zertosh
The text was updated successfully, but these errors were encountered: