Skip to content

Commit 9a17a70

Browse files
authored
chore: improve handlebars support in extension (#2246)
1 parent 2822726 commit 9a17a70

File tree

10 files changed

+52
-3
lines changed

10 files changed

+52
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
· Vue
2323
· Angular
2424
</em>
25+
<em>
26+
HANDLEBARS
27+
· Ember
28+
· Glimmer
29+
</em>
2530
<br />
2631
<em>
2732
GraphQL
@@ -187,6 +192,7 @@ typescript
187192
typescriptreact
188193
json
189194
graphql
195+
handlebars
190196
```
191197

192198
### Format Document (Forced)

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"prettier",
2727
"formatter",
2828
"javascript",
29+
"handlebars",
2930
"js",
3031
"jsx",
3132
"flow",
@@ -47,6 +48,8 @@
4748
"swift",
4849
"html",
4950
"vue",
51+
"ember",
52+
"glimmer",
5053
"angular",
5154
"graphql",
5255
"yaml",
@@ -65,7 +68,7 @@
6568
"clean": "node ./scripts/clean.js",
6669
"lint": "eslint -c .eslintrc.js --ext .ts .",
6770
"pretest": "yarn test-compile && cd test-fixtures/plugins && yarn install && cd ../outdated && yarn install && cd ../module && yarn install && cd ../specific-version && yarn install && cd ../explicit-dep && yarn install && cd implicit-dep && yarn install",
68-
"prettier": "prettier --write '**/*.{ts,json,md,yml,js}'",
71+
"prettier": "prettier --write '**/*.{ts,json,md,hbs,yml,js}'",
6972
"test-compile": "yarn clean && tsc -p ./ && yarn webpack",
7073
"test": "node ./out/test/runTests.js",
7174
"version": "node ./scripts/version.js && git add CHANGELOG.md",
@@ -77,7 +80,7 @@
7780
"chrome": "yarn webpack && vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ."
7881
},
7982
"lint-staged": {
80-
"**/*.{ts,json,md,yml,js}": [
83+
"**/*.{ts,json,md,yml,hbs,js}": [
8184
"prettier --write"
8285
],
8386
"src/**/*.ts": [
@@ -411,6 +414,15 @@
411414
"extensions": [
412415
".vue"
413416
]
417+
},
418+
{
419+
"id": "handlebars",
420+
"extensions": [
421+
".hbs",
422+
".gjs",
423+
".gts",
424+
".handlebars"
425+
]
414426
}
415427
],
416428
"commands": [

src/PrettierEditService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default class PrettierEditService implements Disposable {
6363
"typescriptreact",
6464
"json",
6565
"graphql",
66+
"handlebars",
6667
];
6768

6869
constructor(

src/test/suite/config.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ suite("Test configurations", function () {
3333
/* cspell: disable-next-line */
3434
testConfig("jsfile/test.js", "jsfile/test.result.js")
3535
);
36+
test(
37+
"it uses config from .prettierrc.js file for hbs files",
38+
/* cspell: disable-next-line */
39+
testConfig("hbsfile/test.hbs", "hbsfile/test.result.hbs")
40+
);
3641
test(
3742
"it uses config from .editorconfig file ",
3843
testConfig("editorconfig/test.js", "editorconfig/test.result.js")

src/test/suite/format.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,5 @@ suite("Test format Document", function () {
120120
test("it formats HTML with literals", () =>
121121
formatSameAsPrettier("formatTest/htmlWithLiterals.html"));
122122
test("it formats Vue", () => formatSameAsPrettier("formatTest/ugly.vue"));
123+
test("it formats HBS", () => formatSameAsPrettier("formatTest/ugly.hbs"));
123124
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
singleQuote: false,
3+
useTabs: false,
4+
tabWidth: 3
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{my-component}}
2+
3+
<MyTemplate @foo="bar">
4+
{{@foo.bar.baz}}
5+
</MyTemplate>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{my-component}}
2+
3+
<MyTemplate @foo="bar">
4+
{{@foo.bar.baz}}
5+
</MyTemplate>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<template>
2+
<p>Hello</p>
3+
4+
5+
6+
</template>

test-fixtures/test.code-workspace

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
"[html]": {
7979
"editor.defaultFormatter": "esbenp.prettier-vscode"
8080
},
81+
"[handlebars]": {
82+
"editor.defaultFormatter": "esbenp.prettier-vscode"
83+
},
8184
"[vue]": {
8285
"editor.defaultFormatter": "esbenp.prettier-vscode"
8386
},
@@ -93,4 +96,4 @@
9396
"**/*.abc"
9497
],
9598
}
96-
}
99+
}

0 commit comments

Comments
 (0)