
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
prettier-plugin-ember-hbs-tag
Advanced tools
Prettier plugin to format hbs
tags
Until now, Ember developers had to use ember-template-lint-plugin-prettier
to format their *.hbs
files. This is a bit strange, because Prettier natively supports Handlebars since May 2021.
The plugin also comes with a few issues:
hbs
tag (i.e. wrong indentations in rendering tests, Storybook stories).prettier
and use a hook from ember-template-lint
to format *.hbs
. Due to strong coupling, it will fall behind if prettier
or ember-template-lint
makes a breaking change to their API.prettier
through a linter plugin. In January 2025, Ember CLI removed eslint-plugin-prettier
and stylelint-prettier
from its blueprints, in order to separate formatting and linting.In short, what we're missing is a Prettier plugin to format hbs
tags.
[!TIP]
Use
prettier-plugin-ember-template-tag
to format<template>
tags. You can find out below how to set up both plugins.
In package.json
, replace ember-template-lint-plugin-prettier
with prettier-plugin-ember-hbs-tag
.
package.json
eslint-plugin-prettier
and stylelint-prettier
are assumed to have been removed already. For more details, please see my blog post.
{
"devDependencies": {
"ember-template-lint": "...",
- "ember-template-lint-plugin-prettier": "...",
"prettier": "...",
+ "prettier-plugin-ember-hbs-tag": "...",
"prettier-plugin-ember-template-tag": "..."
}
}
Remove ember-template-lint-plugin-prettier
from the ember-template-lint
configuration.
.template-lintrc.cjs
'use strict';
module.exports = {
- plugins: ['ember-template-lint-plugin-prettier'],
- extends: ['recommended', 'ember-template-lint-plugin-prettier:recommended'],
- overrides: [
- {
- files: ['**/*.{gjs,gts}'],
- rules: {
- prettier: 'off',
- },
- },
- {
- files: ['tests/**/*-test.{js,ts}'],
- rules: {
- prettier: 'off',
- },
- },
- ],
+ extends: ['recommended'],
};
Add prettier-plugin-ember-hbs-tag
to the prettier
configuration.
prettier.config.mjs
Prettier's default parser for *.{js,ts}
is 'babel'
. To format *.{js,ts}
with an hbs
tag, set the parser to 'ember-hbs-tag'
.
export default {
plugins: [
'prettier-plugin-ember-hbs-tag',
'prettier-plugin-ember-template-tag',
],
overrides: [
{
files: ['*.{cjs,cts,js,mjs,mts,ts}'],
options: {
singleQuote: true,
},
},
{
files: ['tests/**/*-test.{js,ts}'],
options: {
parser: 'ember-hbs-tag',
singleQuote: true,
templateSingleQuote: false,
},
},
{
files: ['*.{gjs,gts}'],
options: {
singleQuote: true,
templateSingleQuote: false,
},
},
{
files: ['*.hbs'],
options: {
printWidth: 64,
singleQuote: false,
},
},
],
};
Finally, run install
to update your project dependencies. Run lint
and lint:fix
to check that hbs
tags can be formatted.
preserveTrailingWhitespace
By default, the plugin aims for prettiness.
If you need the trailing whitespace to remain unchanged (e.g. in tests), set preserveTrailingWhitespace
to true
.
/* prettier.config.mjs */
export default {
overrides: [
{
files: ['tests/**/*-test.{js,ts}'],
options: {
parser: 'ember-hbs-tag',
+ preserveTrailingWhitespace: true,
},
},
],
};
templateSingleQuote
By default, Prettier uses single quotes in *.{js,ts}
, and the plugin uses the global value of singleQuote
to decide whether to use single or double quotes in templates.
However, you will most likely want double quotes for templates. So set templateSingleQuote
to false
, just like you did it for prettier-plugin-ember-template-tag
.
/* prettier.config.mjs */
export default {
overrides: [
{
files: ['tests/**/*-test.{js,ts}'],
options: {
parser: 'ember-hbs-tag',
+ templateSingleQuote: false,
},
},
],
};
See the Contributing guide for details.
This project is licensed under the MIT License.
FAQs
Prettier plugin to format hbs tags
We found that prettier-plugin-ember-hbs-tag demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.