GithubHelp home page GithubHelp logo

Comments (15)

rinoldsimon avatar rinoldsimon commented on June 18, 2024 2

I'm using VScode and below is the config I wrote to omit the final newline in hbs

settings.json

"[handlebars]": {
    "files.insertFinalNewline": false
},

from ember-template-lint-plugin-prettier.

rinoldsimon avatar rinoldsimon commented on June 18, 2024 1

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

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

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 prettier/prettier#6243 but it would require more work to refine the approach.

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

Opened josephfrazier/editorconfig-to-prettier#8

from ember-template-lint-plugin-prettier.

jcardali avatar jcardali commented on June 18, 2024

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 :(

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

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. :)

from ember-template-lint-plugin-prettier.

jcardali avatar jcardali commented on June 18, 2024

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. :)

Yep, just did it out of curiousity.

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

Okay, then it doesn't work when you specify eol-last: "never" ? Or eol-last: "editorconfig"?

from ember-template-lint-plugin-prettier.

jcardali avatar jcardali commented on June 18, 2024

Okay, then it doesn't work when you specify eol-last: "never" ? Or eol-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.

from ember-template-lint-plugin-prettier.

jcardali avatar jcardali commented on June 18, 2024

Hi @dcyriller, any update on this?

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

editorconfig-to-prettier now supports the insert_final_newline option.

Next step would be to use the option in Prettier's handlebars printer.

from ember-template-lint-plugin-prettier.

jcardali avatar jcardali commented on June 18, 2024

Seems like there is support for that approach prettier/prettier#9067.

I looked at this a bit today, I am not seeing how exactly to achieve it without having minimist throw a warning...

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

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

from ember-template-lint-plugin-prettier.

dcyriller avatar dcyriller commented on June 18, 2024

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 prettier/prettier#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.

from ember-template-lint-plugin-prettier.

jelhan avatar jelhan commented on June 18, 2024

I would like to understand the use case better. Mainly to decide if this should be considered a blocker for emberjs/rfcs#777.

Why do you want to have a final new line in Ember / Glimmer templates?

from ember-template-lint-plugin-prettier.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.