Skip to content

Commit

Permalink
chore: improve handlebars support in extension (#2246)
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart authored Jan 3, 2022
1 parent 2822726 commit 9a17a70
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
· Vue
· Angular
</em>
<em>
HANDLEBARS
· Ember
· Glimmer
</em>
<br />
<em>
GraphQL
Expand Down Expand Up @@ -187,6 +192,7 @@ typescript
typescriptreact
json
graphql
handlebars
```

### Format Document (Forced)
Expand Down
16 changes: 14 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"prettier",
"formatter",
"javascript",
"handlebars",
"js",
"jsx",
"flow",
Expand All @@ -47,6 +48,8 @@
"swift",
"html",
"vue",
"ember",
"glimmer",
"angular",
"graphql",
"yaml",
Expand All @@ -65,7 +68,7 @@
"clean": "node ./scripts/clean.js",
"lint": "eslint -c .eslintrc.js --ext .ts .",
"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",
"prettier": "prettier --write '**/*.{ts,json,md,yml,js}'",
"prettier": "prettier --write '**/*.{ts,json,md,hbs,yml,js}'",
"test-compile": "yarn clean && tsc -p ./ && yarn webpack",
"test": "node ./out/test/runTests.js",
"version": "node ./scripts/version.js && git add CHANGELOG.md",
Expand All @@ -77,7 +80,7 @@
"chrome": "yarn webpack && vscode-test-web --browserType=chromium --extensionDevelopmentPath=. ."
},
"lint-staged": {
"**/*.{ts,json,md,yml,js}": [
"**/*.{ts,json,md,yml,hbs,js}": [
"prettier --write"
],
"src/**/*.ts": [
Expand Down Expand Up @@ -411,6 +414,15 @@
"extensions": [
".vue"
]
},
{
"id": "handlebars",
"extensions": [
".hbs",
".gjs",
".gts",
".handlebars"
]
}
],
"commands": [
Expand Down
1 change: 1 addition & 0 deletions src/PrettierEditService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default class PrettierEditService implements Disposable {
"typescriptreact",
"json",
"graphql",
"handlebars",
];

constructor(
Expand Down
5 changes: 5 additions & 0 deletions src/test/suite/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ suite("Test configurations", function () {
/* cspell: disable-next-line */
testConfig("jsfile/test.js", "jsfile/test.result.js")
);
test(
"it uses config from .prettierrc.js file for hbs files",
/* cspell: disable-next-line */
testConfig("hbsfile/test.hbs", "hbsfile/test.result.hbs")
);
test(
"it uses config from .editorconfig file ",
testConfig("editorconfig/test.js", "editorconfig/test.result.js")
Expand Down
1 change: 1 addition & 0 deletions src/test/suite/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,5 @@ suite("Test format Document", function () {
test("it formats HTML with literals", () =>
formatSameAsPrettier("formatTest/htmlWithLiterals.html"));
test("it formats Vue", () => formatSameAsPrettier("formatTest/ugly.vue"));
test("it formats HBS", () => formatSameAsPrettier("formatTest/ugly.hbs"));
});
5 changes: 5 additions & 0 deletions test-fixtures/config/hbsfile/prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
singleQuote: false,
useTabs: false,
tabWidth: 3
}
5 changes: 5 additions & 0 deletions test-fixtures/config/hbsfile/test.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{my-component}}

<MyTemplate @foo="bar">
{{@foo.bar.baz}}
</MyTemplate>
5 changes: 5 additions & 0 deletions test-fixtures/config/hbsfile/test.result.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{my-component}}

<MyTemplate @foo="bar">
{{@foo.bar.baz}}
</MyTemplate>
6 changes: 6 additions & 0 deletions test-fixtures/project/formatTest/ugly.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<p>Hello</p>



</template>
5 changes: 4 additions & 1 deletion test-fixtures/test.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[handlebars]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -93,4 +96,4 @@
"**/*.abc"
],
}
}
}

0 comments on commit 9a17a70

Please sign in to comment.