You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now in the docs it is recommended to import library packages with aliases:
package main
import (
g "github.com/maragudk/gomponents"
c "github.com/maragudk/gomponents/components"
. "github.com/maragudk/gomponents/html"
)
funcMyPage() g.Node {
returnh.Main(
// ...
)
}
The problem comes when the file is saved, if an import is not being used then go fmt deletes it.
This is a problem because to import packages with aliases there is usually no help from the editor, so you must memorize the import, copy and paste it or create snippets to import the packages.
As you can well imagine, this kills productivity and completely takes you out of the flow state.
Proposed solution:
My proposal to solve this problem is to simply re-export the functions of the 3 main packages so that our import looks like this:
package main
import (
"github.com/maragudk/gomponents/shortexport/g"// For main package"github.com/maragudk/gomponents/shortexport/c"// For components package"github.com/maragudk/gomponents/shortexport/h"// For html package
)
funcMyPage() g.Node {
returnh.Main( // auto imported when file is saved// ...
)
}
This would attack the problem directly by allowing our code editor tools to auto-import the package without having to write aliases or do it manually, which would be of great help to improve our productivity.
The text was updated successfully, but these errors were encountered:
Hi @eduardolat, thank you for taking the time to create an issue!
I think this is usually something you can set up in your editor. Either you could have it not delete unused imports, or use an editor that supports importing with aliases. GoLand (from Jetbrains) usually does this quite well, I don't know about other editors. Alternatively, wait with saving the file until you've used the import.
This isn't something I want to add to the library. If you editor doesn't support some of my proposed solutions, maybe you can file an issue with the makers of your editor?
I think I'll just use the imports without aliases (gomponents, html, components instead of g, h, c).
I'm going to find out about configurations for vscode that solve this in the best possible way, thank you very much for your contributions to the community.
The problem:
Right now in the docs it is recommended to import library packages with aliases:
The problem comes when the file is saved, if an import is not being used then go fmt deletes it.
This is a problem because to import packages with aliases there is usually no help from the editor, so you must memorize the import, copy and paste it or create snippets to import the packages.
As you can well imagine, this kills productivity and completely takes you out of the flow state.
Proposed solution:
My proposal to solve this problem is to simply re-export the functions of the 3 main packages so that our import looks like this:
This would attack the problem directly by allowing our code editor tools to auto-import the package without having to write aliases or do it manually, which would be of great help to improve our productivity.
The text was updated successfully, but these errors were encountered: