Comments (14)
If anyone is still interested in using it globally (without installing it to each repository), you'll need to:
- Have node & npm installed
- Run
npm i -g prettier prettier-plugin-go-template
- Find where your node modules are by running
npm root -g
➡️/Users/niklaspor/.nvm/versions/node/v16.13.2/lib/node_modules
- Configure your VSCode settings to use your global prettier:
"prettier.prettierPath": "/Users/niklaspor/.nvm/versions/node/v16.13.2/lib/node_modules/prettier"
- Setup your
.prettierrc
as it's described inside theREADME.md
I'm still considering publishing a VSCode extension for the users who're not interested in the node cosmos at all. Especially as the setup above is more than just a click 😁
from prettier-plugin-go-template.
@cameronelliott there are now examples in the README.md
and you can play with the plugin on the playground 🚀
from prettier-plugin-go-template.
from prettier-plugin-go-template.
One last edit:
I have now installed both prettier and the go template plugin directly in my project folder, to see if I could get it working like that. Now, however, I am getting this error:
["ERROR" - 12:41:44] Error formatting document. ["ERROR" - 12:41:44] An error occured during printing. Found invalid node root. Error: An error occured during printing. Found invalid node root. at Object.print (/fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier-plugin-go-template/lib/index.js:65:19) at callPluginPrintFunction (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17846:20) at printAstToDoc (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17801:22) at async coreFormat (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18111:14) at async formatWithCursor (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18309:14) at async Module.format2 (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:21504:25)
I am not entirely sure what that means unfortunately.
I can confirm the above mentioned error is still present on the following:
Environment:
- VSCode: 1.88.1
- Prettier: 3.2.5
- Plugin: 0.0.15
It seems to be something related to the way the GoTemplate AST is being generated or interpreted by Prettier. Maybe an API change?
@NiklasPor any hopes on feedback on this, or is the project no longer maintained?
Thanks
from prettier-plugin-go-template.
When I attempt this, I get:
["INFO" - 12:20:11] Extension Name: esbenp.prettier-vscode.
["INFO" - 12:20:11] Extension Version: 10.1.0.
["INFO" - 12:20:20] Attempted to load Prettier module from /usr/lib/node_modules/prettier/
["ERROR" - 12:20:20] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 12:20:20] Cannot find Prettier package.json
I have tried this with /usr/lib/node_modules/prettier
(no trailing slash) which made no difference. Going to that directory, I can see prettier is right there, along with a package.json. Not sure how to address this. Any ideas? This is on Manjaro, if that helps.
Quick edit:
It would appear that the first part of this issue can be addressed by doing this:
"prettier.prettierPath": "/usr/lib/node_modules/prettier/index.cjs"
However, the following issue now occurs:
["ERROR" - 12:36:50] Error resolve node module 'prettier-plugin-go-template'
Error: Error resolve node module 'prettier-plugin-go-template'
Despite this also having been installed via npm i -g
and sitting right next to prettier in /usr/lib/node_modules
One last edit:
I have now installed both prettier and the go template plugin directly in my project folder, to see if I could get it working like that. Now, however, I am getting this error:
["ERROR" - 12:41:44] Error formatting document.
["ERROR" - 12:41:44] An error occured during printing. Found invalid node root.
Error: An error occured during printing. Found invalid node root.
at Object.print (/fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier-plugin-go-template/lib/index.js:65:19)
at callPluginPrintFunction (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17846:20)
at printAstToDoc (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:17801:22)
at async coreFormat (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18111:14)
at async formatWithCursor (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:18309:14)
at async Module.format2 (file:///fast_ssd/Projects/pink_pigeon/defaultsitestructure/node_modules/prettier/index.mjs:21504:25)
I am not entirely sure what that means unfortunately.
from prettier-plugin-go-template.
Same error as user above.
from prettier-plugin-go-template.
I'm also having this problem
from prettier-plugin-go-template.
One more thought, an example of a test-case in the README that shows a before & after example,
so users unfamiliar with prettier-plugin-go-template
can see if they have installed it correctly would be super helpful.
For example, in my case, I did:
And if I now run:
npx prettier sample.html
with the input: sample.html
<html>
<script>
{{if }}
Whatever.
{{else }}
Psych.
{{end }}
</script>
</html>
I get the following on Stdout:
<html>
<script>
{{if }}
Whatever.
{{else }}
Psych.
{{end }}
</script>
</html>
Which seems wrong, (it is unindented to start) but I am so unfamiliar with npm/npx, I don't know the issue.
from prettier-plugin-go-template.
I just found this: prettier/prettier#6034
😢
from prettier-plugin-go-template.
Okay, I guess my test cases are failing because the {{foo}} inside the <script> block causes the formatter to abort formatting.
from prettier-plugin-go-template.
@NiklasPor I don't think I'm using this enough to justify me asking you to do that, but maybe if other people come along and want it to it makes sense.
I'm just kind of thrilled this exists for go templates in the first place.
from prettier-plugin-go-template.
Regarding VSCode, I could consider publishing the plugin as an additional VSCode extension.
Please, do!
I.e. Grafana Unified Alerting Templates are currently using Golang Template language, and it would be really useful.
Currently, no golang-template formatter available for VS Code in Marketplace.
from prettier-plugin-go-template.
I'm still considering publishing a VSCode extension for the users who're not interested in the node cosmos at all. Especially as the setup above is more than just a click 😁
Never used node.js before, and had it all installed just for this pretty software piece of yours. It was interesting, but having the prettier plugin go template live next to the other vscode extensions would be smoother for sure
Cheers !
from prettier-plugin-go-template.
I'm still considering publishing a VSCode extension for the users who're not interested in the node cosmos at all. Especially as the setup above is more than just a click 😁
Never used node.js before, and had it all installed just for this pretty software piece of yours. It was interesting, but having the prettier plugin go template live next to the other vscode extensions would be smoother for sure
Cheers !
Agree with this 100% -- Love the plugin, but would love it even more without having to install node. Great work regardless!
from prettier-plugin-go-template.
Related Issues (20)
- Can't make it work in VSCode on gohtml with pnpm HOT 1
- Unintended whitespace is inserted into the value of an HTML attribute
- Upgrade prettier peer dependency to `^3.0.0` HOT 3
- Closing tag is spit on log tags and log lines HOT 2
- Nvim support check HOT 1
- support for Templ files HOT 1
- .prettierrc format problem in documentation HOT 2
- Unable to remove extra spaces
- Different formatting result after formatting once HOT 2
- Idempotency bug w/ unclosed multiline string
- Error - Found invalid node block HOT 5
- Formatting fails for HTML custom elements HOT 5
- Error thrown when formatting dynamic HTML tag like `<h{{ .Level }}></h{{ .Level }}>`
- prettier print/embed are async now
- Lines containing variable definitions cause double-empty lines HOT 2
- confused by multiline comments containing syntax HOT 1
- prettier-ignore comments don't work for html fragments HOT 3
- fails on html tags using if/else HOT 2
- Migrate to Prettier v3 HOT 2
- Use With Pre-commit hooks HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettier-plugin-go-template.