ember-template-lint-plugin-prettier
ember-template-lint-plugin-prettier copied to clipboard
--fix removes newline at EOF
"ember-template-lint": "^2.10.0"
"ember-template-lint-plugin-prettier": "^2.0.0"
"prettier": "^2.0.5"
Behavior:
ember-template-lint --fix [FILE] removes the newline at EOF
Expected behavior:
EOF newlines should at minimum be respected, or even added, since that is Prettier's behavior
I do not see this behavior if I remove prettier: true from .template-lintrc.js, which is what leads me to believe this is an issue with the plugin.
Line 29 is the last line with text, and Line 30 is a newline
Hey @jcardali,
This is actually an expected behavior of Prettier. Indeed, Prettier for handlebars does remove the newline at EOF. I made one attempt at changing that: see https://github.com/prettier/prettier/pull/6243 but it would require more work to refine the approach.
Opened https://github.com/josephfrazier/editorconfig-to-prettier/pull/8
Thanks for the quick response @dcyriller! Will definitely be keeping my eye on the PR you opened.
For the sake of completeness, I also investigated whether this issue was surmountable with ember-template-lint's eol-last rule, and sadly it was not :(
When you use Prettier to format your templates, it's recommended to turn ember-template-lint's stylistic preset off (eol-last rule belongs to that set). To do so, you would remove it from your .template-lintrc.js. :)
When you use Prettier to format your templates, it's recommended to turn ember-template-lint's
stylisticpreset off (eol-lastrule belongs to that set). To do so, you would remove it from your .template-lintrc.js. :)
Yep, just did it out of curiousity.
Okay, then it doesn't work when you specify eol-last: "never" ? Or eol-last: "editorconfig"?
Okay, then it doesn't work when you specify
eol-last: "never"? Oreol-last: "editorconfig"?
"never" only seemingly works because that is the default behavior of Pretter in this case. We have insert_final_newline = true at the top level of our repo, and "editorconfig" does not work.
Hi @dcyriller, any update on this?
editorconfig-to-prettier now supports the insert_final_newline option.
Next step would be to use the option in Prettier's handlebars printer.
Seems like there is support for that approach https://github.com/prettier/prettier/pull/9067.
I looked at this a bit today, I am not seeing how exactly to achieve it without having minimist throw a warning...
It will have to be probably implemented on this line: https://github.com/prettier/prettier/blob/2.1.2/src/language-handlebars/printer-glimmer.js#L51
the --fix still removes the newline at EOF. Any updates on this? We have configured our IDEs to auto insert new line at EOF. Running npm run lint:hbs throws error error Delete ⏎
Is there any way to not remove the newline at EOF while running npm run lint:hbs:fix
OR is there any way to ignore this error? error Delete ⏎
My .template-lintrc.js
'use strict';
module.exports = {
plugins: ['ember-template-lint-plugin-prettier'],
extends: ['octane', 'ember-template-lint-plugin-prettier:recommended'],
rules: {
"eol-last": "always"
}
};
I have explicitly mentioned "eol-last": "always". So now,
- when there is no new line it throws
error template must end with newline eol-last - when there is new line it throws
error Delete⏎prettier
Hi @rinoldsimon,
the --fix still removes the newline at EOF.
This is expected. Indeed, Prettier will always remove the last eol for now.
I have opened https://github.com/prettier/prettier/pull/10759 to read insert_final_newline from editorconfig and insert a final newline if insert_final_newline is true. You can follow there to see if the PR is accepted.
We have configured our IDEs to auto insert new line at EOF. Running npm run lint:hbs throws error error Delete ⏎
As a workaround, you could change your editor config to insert final newlines for all files but hbs.
I'm using VScode and below is the config I wrote to omit the final newline in hbs
settings.json
"[handlebars]": {
"files.insertFinalNewline": false
},
I would like to understand the use case better. Mainly to decide if this should be considered a blocker for https://github.com/emberjs/rfcs/issues/777.
Why do you want to have a final new line in Ember / Glimmer templates?