Galooshi / import-js

A tool to simplify importing JS modules
MIT License
525 stars 55 forks source link

No more implicit React identifiers #609

Closed mikabytes closed 10 months ago

mikabytes commented 10 months ago

Much inspiration from #580, thanks @madox2!

This PR never includes implicit React imports, unlike that PR. See issue for more information.

@trotzig Do you have some React projects where you could try this out in a sharp real-life environment? I don't do React, so I can't be too sure. All the tests are passing fine.

mikabytes commented 10 months ago

I verified this today running the steps below. I think this should be good to merge, but I'm not 100% sure as I haven't worked with React since some 8 years ago.

Steps to test:

mkdir test ; cd test

npm init

echo "const a = <Test />" > test.js

importjs fix test.js

cat test.js

Result before PR:

{"messages":["Imported React from 'react'"],"fileContent":"import React from 'react'\n\nconst a = <Test />;\n","unresolvedImports":{}}

Result after PR:

{"messages":[],"fileContent":"const a = <Test />\n","unresolvedImports":{}}
trotzig commented 10 months ago

Glad you tried it out yourself -- I'm dealing with a family emergency and will likely be less active for a while. 🙏

mikabytes commented 10 months ago

No worries @trotzig, glad to hear you're keeping those priorities straight :+1: