Skip to content
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

Pass filename to parsers if available #78

Closed
jquense opened this issue Jan 16, 2019 · 6 comments
Closed

Pass filename to parsers if available #78

jquense opened this issue Jan 16, 2019 · 6 comments

Comments

@jquense
Copy link
Contributor

jquense commented Jan 16, 2019

Now that babel supports typescript it's possible to have a single parser for js and ts files, except for the limiting factor that parsers don't know what type of file they are looking at. In other places, I've turned on flow/ts support based on the input file extension, and i think that approach would work well here as well.

what do you think about either adding babel ts support out of the box, or at least altering the parser api to take in the filename so third party parsers could do it?

@jquense
Copy link
Contributor Author

jquense commented Jan 29, 2019

friendly ping :)

@renke
Copy link
Owner

renke commented Jan 30, 2019

Hi @jquense

yes, I agree with you that Babel should be the way forward now that it supports TypeScript. I'll see what I can do for the next release. The project was in a Hiatus kind of state, but I will try to invest more time in the upcoming days/weeks.

On a related note, I am still not sure how to deal with parserOptions. I'd like import-sort to support most JavaScript/TypeScript files out-of-the-box with minimal extra config provided by the user. We briefly talked about this in #54. Maybe you have some new insight on this topic?

@jquense
Copy link
Contributor Author

jquense commented Jan 30, 2019

hey @renke np on the timing, I understand how maintaining these sorts of projects goes. I'm happy to help out maintaining as well if you're interested, we have pretty fully integrated import-sot into our workflows at work so are reasonably invested.

I think maybe the best approach nowadays to babel is to use babel.parse() which will use whatever config the user has already set up, meaning no additional configuration is needed just for import-sort. This approach works well, we just merged something similar into react-docgen and i've done it for a bunch other tooling (namely astroturf). We still would need to pass the filename to the parser, and the cwd so it can find the config and then do the needed switches off the file name/extension. But that would probably give the best out of the box experience, along with switching the default extensions for babel to include ts ones (overridable)

happy to put together a PR if that sounds good?

@renke
Copy link
Owner

renke commented Feb 2, 2019

Hi @jquense

I just pushed c782850 to master, is what you had in mind?

The Babel parser now uses .babelrc (if any is found). It also looks at the file extension and adds the TypeScript plugin if the file ends in .ts or .tsx (but only when no .babelrc was found).

The TypeScript parser can probably be deprecated now. I also intent to add import-sort-parser-babylon as (optional?) dependency and probably some kind of default style to import-sort-cli, such that npx import-sort-cli … can be used without having to install any packages.

@jquense
Copy link
Contributor Author

jquense commented Feb 2, 2019

Nice ! That looks awesome, seems like being down to one parser is definitely a week. Looking forward to testing this out

@renke
Copy link
Owner

renke commented Feb 16, 2019

I just released this as part of v6. Let me know if you find any problems!

@renke renke closed this as completed Feb 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants