<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jeldrik Hanschke</title>
    <description>The latest articles on DEV Community by Jeldrik Hanschke (@jelhan).</description>
    <link>https://dev.to/jelhan</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F452333%2Fef76d620-5b44-4c76-94f5-0203a86862b7.jpeg</url>
      <title>DEV Community: Jeldrik Hanschke</title>
      <link>https://dev.to/jelhan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jelhan"/>
    <language>en</language>
    <item>
      <title>Format Glimmer templates with Prettier</title>
      <dc:creator>Jeldrik Hanschke</dc:creator>
      <pubDate>Sun, 07 Feb 2021 22:04:27 +0000</pubDate>
      <link>https://dev.to/jelhan/format-glimmer-templates-with-prettier-ipa</link>
      <guid>https://dev.to/jelhan/format-glimmer-templates-with-prettier-ipa</guid>
      <description>&lt;p&gt;&lt;a href="https://prettier.io/" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; is an opinionated code formatter. It helps developers and teams to stop worry about coding style. Prettier allows developers to write code without manually formatting it for readability. Instead Prettier takes over after the developer has implemented the feature and rewrites the code with a set of opinionated rules tested by many applications in production.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://emberjs.com/" rel="noopener noreferrer"&gt;Ember&lt;/a&gt; projects get a ready to be used Prettier configuration out of the box. Ember CLI &lt;a href="https://blog.emberjs.com/ember-3-24-released" rel="noopener noreferrer"&gt;v3.24&lt;/a&gt;, which was released in the first days of this year, include Prettier in the blueprints for applications and addons. New projects use it from day one. Existing projects can adopt prettier by updating the blueprints using &lt;a href="https://cli.emberjs.com/release/basic-use/upgrading/" rel="noopener noreferrer"&gt;Ember CLI Update&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By default Prettier is only enabled for JavaScript files. Prettier is not enabled for Glimmer templates. The glimmer parser included in Prettier is not yet officially released. It still includes some minor bugs. But many projects are already using it successfully nevertheless.&lt;/p&gt;

&lt;p&gt;This blog post describes how Prettier can be configured to format Glimmer templates as well. Additionally it describes how VSCode needs to be configured to format Glimmer templates with Prettier on save.&lt;/p&gt;

&lt;h2&gt;
  
  
  Linting Glimmer templates with Prettier
&lt;/h2&gt;

&lt;p&gt;Ember CLI configures Prettier to run as an ESLint plugin. But ESLint is not used for Glimmer templates. The Ember ecosystem has it's developed a dedicated linter for Glimmer templates: &lt;a href="https://github.com/ember-template-lint/ember-template-lint" rel="noopener noreferrer"&gt;Ember Template Lint&lt;/a&gt; Both ESLint and Ember Template Lint are included, configured and enabled for Ember projects by default.&lt;/p&gt;

&lt;p&gt;Similar to how Prettier is run as ESLint plugin for JavaScript files it could be run as a plugin for Ember Template Lint. Ember community provides an official plugin to do so: &lt;a href="https://github.com/ember-template-lint/ember-template-lint-plugin-prettier" rel="noopener noreferrer"&gt;ember-template-lint-plugin-prettier&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The plugin adds Prettier as a template lint rule. The rule ensures that template linting fails if any Glimmer template (&lt;code&gt;*.hbs&lt;/code&gt;) is not formatted with Prettier.&lt;/p&gt;

&lt;p&gt;It is installed with as any other dependency with the package manager used by your project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;# if using yarn&lt;/span&gt;
yarn add &lt;span class="nt"&gt;-D&lt;/span&gt; prettier ember-template-lint-plugin-prettier

&lt;span class="c"&gt;# if using NPM&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save-dev&lt;/span&gt; ember-template-lint-plugin-prettier


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Additionally it needs to be configured in template lint configuration of your project:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="gh"&gt;diff --git a/.template-lintrc.js b/.template-lintrc.js
index 3b0b9af..73c6c78 100644
&lt;/span&gt;&lt;span class="gd"&gt;--- a/.template-lintrc.js
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/.template-lintrc.js
&lt;/span&gt;&lt;span class="p"&gt;@@ -1,5 +1,6 @@&lt;/span&gt;
 'use strict';
&lt;span class="err"&gt;
&lt;/span&gt; module.exports = {
&lt;span class="gd"&gt;-  extends: 'octane',
&lt;/span&gt;&lt;span class="gi"&gt;+  plugins: ['ember-template-lint-plugin-prettier'],
+  extends: ['octane', 'ember-template-lint-plugin-prettier:recommended'],
&lt;/span&gt; };
&lt;span class="err"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Afterwards &lt;code&gt;yarn lint:hbs&lt;/code&gt; will complain if any Glimmer template is not formatted with Prettier.&lt;/p&gt;

&lt;p&gt;The application template created by Ember CLI is not formatted with Prettier. If you configured the Prettier plugin for Ember Template Lint successfully, you will see the following linting violation for a new application created with Ember CLI v3.24:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;yarn lint:hbs
yarn run v1.22.5
&lt;span class="nv"&gt;$ &lt;/span&gt;ember-template-lint &lt;span class="nb"&gt;.&lt;/span&gt;
app/templates/application.hbs
  1:13  error  Replace &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="s2"&gt;"EmberProjectUsingPrettierForTemplates"&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt; with &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="s1"&gt;'EmberProjectUsingPrettierForTemplates'&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;  prettier
  3:3  error  Replace &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;·The·following·component·displays·Ember&lt;span class="s1"&gt;'s·default·welcome·message.·--` with ` The following component displays Ember'&lt;/span&gt;s default welcome message. &lt;span class="sb"&gt;`&lt;/span&gt;  prettier
  5:3  error  Replace &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;·Feel·free·to·remove·this!·--&lt;span class="sb"&gt;`&lt;/span&gt; with &lt;span class="sb"&gt;`&lt;/span&gt; Feel free to remove this! &lt;span class="sb"&gt;`&lt;/span&gt;  prettier

✖ 3 problems &lt;span class="o"&gt;(&lt;/span&gt;3 errors, 0 warnings&lt;span class="o"&gt;)&lt;/span&gt;
  3 errors and 0 warnings potentially fixable with the &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--fix&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt; option.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Using double quotes in Glimmer templates but single quotes in JavaScript files
&lt;/h2&gt;

&lt;p&gt;The Ember community has an informal convention to use single quotes in JavaScript files but double quotes in Glimmer templates. It is reflected in official guides and used by new projects.&lt;/p&gt;

&lt;p&gt;Prettier is configured to use single quotes in a new Ember project. This is controlled by &lt;code&gt;.prettierrc.js&lt;/code&gt; created by Ember CLI blueprints:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;singleQuote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Prettier follows that configuration and also complains about double quotes used in Glimmer templates. We need to update the Prettier configuration to follow the Ember community convention and use single quotes in JavaScript files but double quotes in Glimmer templates.&lt;/p&gt;

&lt;p&gt;We can do so adding an override of the default configuration for &lt;code&gt;*.hbs&lt;/code&gt; files.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="gh"&gt;diff --git a/.prettierrc.js b/.prettierrc.js
index 534e6d3..09f6af7 100644
&lt;/span&gt;&lt;span class="gd"&gt;--- a/.prettierrc.js
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/.prettierrc.js
&lt;/span&gt;&lt;span class="p"&gt;@@ -2,4 +2,12 @@&lt;/span&gt;
&lt;span class="err"&gt;
&lt;/span&gt; module.exports = {
   singleQuote: true,
&lt;span class="gi"&gt;+  overrides: [
+    {
+      files: '*.hbs',
+      options: {
+        singleQuote: false,
+      },
+    },
+  ],
&lt;/span&gt; };
&lt;span class="err"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Running &lt;code&gt;yarn lint:hbs&lt;/code&gt; again on our new project it stops complaining about double quotes being used. 💪&lt;/p&gt;

&lt;p&gt;But it still complains about using wrong comment style at two places:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;yarn lint:hbs
yarn run v1.22.5
&lt;span class="nv"&gt;$ &lt;/span&gt;ember-template-lint &lt;span class="nb"&gt;.&lt;/span&gt;
app/templates/application.hbs
  3:3  error  Replace &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;·The·following·component·displays·Ember&lt;span class="s1"&gt;'s·default·welcome·message.·--` with ` The following component displays Ember'&lt;/span&gt;s default welcome message. &lt;span class="sb"&gt;`&lt;/span&gt;  prettier
  5:3  error  Replace &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--&lt;/span&gt;·Feel·free·to·remove·this!·--&lt;span class="sb"&gt;`&lt;/span&gt; with &lt;span class="sb"&gt;`&lt;/span&gt; Feel free to remove this! &lt;span class="sb"&gt;`&lt;/span&gt;  prettier

✖ 2 problems &lt;span class="o"&gt;(&lt;/span&gt;2 errors, 0 warnings&lt;span class="o"&gt;)&lt;/span&gt;
  2 errors and 0 warnings potentially fixable with the &lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nt"&gt;--fix&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt; option.
error Command failed with &lt;span class="nb"&gt;exit &lt;/span&gt;code 1.
info Visit https://yarnpkg.com/en/docs/cli/run &lt;span class="k"&gt;for &lt;/span&gt;documentation about this command.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let's find out how we can run Prettier to fix that violations automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Formatting Glimmer templates with Prettier
&lt;/h2&gt;

&lt;p&gt;JavaScript files can be formatted with Prettier running &lt;code&gt;yarn lint:js:fix&lt;/code&gt;. This executes &lt;code&gt;eslint&lt;/code&gt; with &lt;code&gt;--fix&lt;/code&gt; flag. As described above ESLint runs Prettier as a plugin and formats the JavaScript files with it.&lt;/p&gt;

&lt;p&gt;Similar Ember projects support &lt;code&gt;yarn lint:hbs:fix&lt;/code&gt; command to fix linting errors in Glimmer templates. It executes &lt;code&gt;ember-template-lint&lt;/code&gt; with &lt;code&gt;--fix&lt;/code&gt; flag. And as thanks to Prettier plugin for Ember Template Lint, which we added earlier, that command tells Prettier to format the Glimmer templates.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="nv"&gt;$ &lt;/span&gt;yarn lint:hbs:fix
yarn run v1.22.5
&lt;span class="nv"&gt;$ &lt;/span&gt;ember-template-lint &lt;span class="nb"&gt;.&lt;/span&gt; &lt;span class="nt"&gt;--fix&lt;/span&gt;
Done &lt;span class="k"&gt;in &lt;/span&gt;0.43s.


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After running it the &lt;code&gt;app/templates/application.hbs&lt;/code&gt; is formatted with Prettier. 🎉&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;$ git diff app/templates/application.hbs
&lt;span class="gh"&gt;diff --git a/app/templates/application.hbs b/app/templates/application.hbs
index 6f0ea67..298858c 100644
&lt;/span&gt;&lt;span class="gd"&gt;--- a/app/templates/application.hbs
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/app/templates/application.hbs
&lt;/span&gt;&lt;span class="p"&gt;@@ -1,7 +1,7 @@&lt;/span&gt;
 {{page-title "EmberProjectUsingPrettierForTemplates"}}
&lt;span class="err"&gt;
&lt;/span&gt;&lt;span class="gd"&gt;-{{!-- The following component displays Ember's default welcome message. -}}&lt;/span&gt;&lt;span class="gi"&gt;+{{! The following component displays Ember's default welcome message. }}
&lt;/span&gt; &amp;lt;WelcomePage /&amp;gt;
&lt;span class="gd"&gt;-{{!-- Feel free to remove this! -}}&lt;/span&gt;&lt;span class="gi"&gt;+{{! Feel free to remove this! }}
&lt;/span&gt;&lt;span class="err"&gt;
&lt;/span&gt; {{outlet}}
\ No newline at end of file
&lt;span class="err"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Format JavaScript files with Prettier on save in VSCode
&lt;/h2&gt;

&lt;p&gt;I'm lazy. I don't want to run &lt;code&gt;yarn lint:js:fix&lt;/code&gt; manually. Therefore I configured VSCode to fix ESLint violations automatically when I save a file. I guess I'm not the only lazy developer. So let me explain you how that could be done.&lt;/p&gt;

&lt;p&gt;First of all we need to install &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;ESLint extension for VSCode&lt;/a&gt;. Out of the box that extension will show ESLint violates in VSCode while you are typing.&lt;/p&gt;

&lt;p&gt;By default it does not fix linting errors on save automatically. To do so the configuration needs to be adjusted. To do so open the VSCode settings and add the following configuration:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"editor.codeActionsOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"source.fixAll.eslint"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Please refer to &lt;a href="https://github.com/Microsoft/vscode-eslint#settings-options" rel="noopener noreferrer"&gt;official documentation&lt;/a&gt; for ESLint extension for VSCode for details.&lt;/p&gt;

&lt;p&gt;How to do the same for Glimmer Templates?&lt;/p&gt;

&lt;h2&gt;
  
  
  Format Glimmer templates with Prettier in VSCode
&lt;/h2&gt;

&lt;p&gt;There is no official VSCode extension for Ember Template Lint as far as I know. But we can use &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" rel="noopener noreferrer"&gt;Prettier for VSCode&lt;/a&gt; to achieve the same.&lt;/p&gt;

&lt;p&gt;After installing the extension it needs to be configured to format Glimmer templates. As the Glimmer parser is not officially released yet, Prettier disables it by default. Therefore we need to tell Prettier explicitly to use it for Glimmer templates. To do so we need to update the Prettier configuration:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="err"&gt;

&lt;/span&gt;&lt;span class="gh"&gt;diff --git a/.prettierrc.js b/.prettierrc.js
index 09f6af7..919bd65 100644
&lt;/span&gt;&lt;span class="gd"&gt;--- a/.prettierrc.js
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/.prettierrc.js
&lt;/span&gt;&lt;span class="p"&gt;@@ -6,6 +6,7 @@&lt;/span&gt; module.exports = {
     {
       files: '*.hbs',
       options: {
&lt;span class="gi"&gt;+        parser: 'glimmer',
&lt;/span&gt;         singleQuote: false,
       },
     },
&lt;span class="err"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Additionally we need to configure the VSCode extension for Prettier to be active for &lt;code&gt;.hbs&lt;/code&gt; files. We can do so by setting &lt;a href="https://github.com/prettier/prettier-vscode#prettierdocumentselectors" rel="noopener noreferrer"&gt;&lt;code&gt;prettier.documentSelectors&lt;/code&gt;&lt;/a&gt; configuration option in VSCode settings.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"prettier.documentSelectors"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"**/*.hbs"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Afterwards Prettier is available as a formatter for Glimmer templates in VSCode.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0irkm68x2b5bw0up1533.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F0irkm68x2b5bw0up1533.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But we need to trigger the formatting manually. We also need to select Prettier formatter explicitly. These are way more manually steps than I want to do as the lazy developer that I am.&lt;/p&gt;

&lt;p&gt;Let's configure VSCode to format Glimmer templates with Prettier on save as we already have it for JavaScript files. As a first step we tell VSCode to use Prettier as default formatter for Glimmer templates. To do so we need to add another line to  VSCode settings:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"[handlebars]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
   &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esbenp.prettier-vscode"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffxcdz1x1owod9qi2zzqx.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffxcdz1x1owod9qi2zzqx.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We don't need to select Prettier formatter explicitly anymore. But we still need to run the formatting manually. Let's additonally enable format on save for Glimmer templates:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nl"&gt;"[handlebars]"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.defaultFormatter"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"esbenp.prettier-vscode"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"editor.formatOnSave"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As JavaScript files are formatted by ESLint with a code action on save we don't want to enable &lt;code&gt;editor.formatOnSave&lt;/code&gt; globally.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Glimmer templates of our project are now formatted with Prettier. We can run it manually with &lt;code&gt;yarn lint:hbs:fix&lt;/code&gt;. But Prettier is also run automatically when saving a template in VSCode. Additionally Ember Template Lint complains if for whatever reason a template is not formatted with Prettier. 🎉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpz3akg3ozpapl96d22f2.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpz3akg3ozpapl96d22f2.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks a lot to Georgii Dolzhykov (&lt;a href="https://github.com/thorn0" rel="noopener noreferrer"&gt;@thornO&lt;/a&gt;) who &lt;a href="https://github.com/prettier/prettier/issues/10263#issuecomment-774745393" rel="noopener noreferrer"&gt;showed me&lt;/a&gt; how to configure Prettier and VSCode extension for Prettier to format Glimmer templates. And of course to all the great people both from Ember and Prettier community, who created the great tool and worked on adding Glimmer support &lt;a href="https://github.com/prettier/prettier/issues/4908" rel="noopener noreferrer"&gt;over the last three years&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you have any question, know a potential improvement or found an error please do not hesitate to reach out to me either via comment here or in #topic-editors channel on &lt;a href="https://discord.gg/emberjs" rel="noopener noreferrer"&gt;Ember Discord&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ember</category>
      <category>prettier</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Setup GitHub Actions as CI for Ember addons</title>
      <dc:creator>Jeldrik Hanschke</dc:creator>
      <pubDate>Mon, 04 Jan 2021 10:00:04 +0000</pubDate>
      <link>https://dev.to/jelhan/setup-github-actions-as-ci-for-ember-addons-5c33</link>
      <guid>https://dev.to/jelhan/setup-github-actions-as-ci-for-ember-addons-5c33</guid>
      <description>&lt;p&gt;Developers creating Ember Addons did not need to care about CI setup when starting a new addon for a long time. Ember CLI generated a ready to be used TravisCI configuration automatically. One click in Travis dashboard to enable it for the new project was enough to get continuous integration up and running.&lt;/p&gt;

&lt;p&gt;Sadly TravisCI recently changed their plan for open source projects dramatically. Runners for travis.org were cut. Pipelines stayed in pending state for days. A few weeks later Travis enforced a limit on CI minutes per month for open source projects running on travis.com. The limit is too small for many projects. Long story short: Travis basically dropped their free plan for open source projects.&lt;/p&gt;

&lt;p&gt;Luckly GitHub provides a great replacement: GitHub Actions. It is free for open source projects and doesn't have a limit on CI minutes. It doesn't even require the maintainer to manual enable it. Push the configuration file to the repository and you are done. 🚀&lt;/p&gt;

&lt;p&gt;But who wants to write such configuration himself? I want to focus on the addon I'm building. Needing to learn more about GitHub Actions might be interesting. But not when I'm trying to build the next great addon for our ecosystem!&lt;/p&gt;

&lt;p&gt;If you feel the same I have something for you: &lt;a href="https://github.com/jelhan/create-github-actions-setup-for-ember-addon#create-github-actions-setup-for-ember-addon" rel="noopener noreferrer"&gt;create-github-actions-setup-for-ember-addon&lt;/a&gt;. 🎉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuv4u7018kvyfkntuez0v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuv4u7018kvyfkntuez0v.png" alt="Command to run the script"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is a small node.js script, which creates a GitHub Actions setup for Ember addons automatically. Run &lt;code&gt;yarn create github-actions-setup-for-ember-addon&lt;/code&gt; if using yarn or &lt;code&gt;npm init github-actions-setup-for-ember-addons&lt;/code&gt; if using NPM in your project folder. Commit the created &lt;code&gt;.github/workflows/ci.yml&lt;/code&gt;. And you are done. 🥳&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Switch to project folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run the script:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# in a yarn repo&lt;/span&gt;
yarn create github-actions-setup-for-ember-addon

&lt;span class="c"&gt;# in an npm repo&lt;/span&gt;
npm init github-actions-setup-for-ember-addon
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Commit the created &lt;code&gt;.github/workflows/ci.yml&lt;/code&gt; file.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;See the CI pipeline running.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The script analyzes an existing &lt;code&gt;.travis.yml&lt;/code&gt; to determine the CI configuration to be used. As Ember CLI still creates a TravisCI configuration the created GitHub Actions workflow will follow the recommendations for the Ember version used by your project.&lt;/p&gt;

&lt;p&gt;Create-github-actions-setup-for-ember-addon is still alpha software. It tries to follow latest best practices. But some questions are not finally resolved yet.&lt;/p&gt;

&lt;p&gt;But you do no need to worry. It supports later upgrades of the generated GitHub Actions workflow. All you need to do is running &lt;code&gt;yarn create github-actions-setup-for-ember-addons&lt;/code&gt; and your project will be upgraded to latest blueprints. 💪&lt;/p&gt;

&lt;p&gt;Try it out right now!&lt;/p&gt;

</description>
      <category>ember</category>
      <category>github</category>
      <category>travisci</category>
    </item>
  </channel>
</rss>
