-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added prettier-plugin for formatting glimmer component templates #117
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
caccfe0
Format all code before starting
ed4357e
prettier-plugin to format glimmer component templates
a732637
Bump prettier in all package.json to 2.3.1
08596c2
Update eslint; decouple printing
0b45a59
Format all code; Fix failing tests with .trim() of ouptut
28c3971
Updated yarn.lock
277d7aa
Increase timeout for prettier test suite
8a09e50
Added whitespace tests
63a7f6b
Added back --cache flag to eslint command
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
packages/@glimmerx/babel-preset/test/ | ||
packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/*/code.* | ||
packages/@glimmerx/prettier-plugin-component-templates/test/fixtures/*/output.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "es5", | ||
"printWidth": 100 | ||
"printWidth": 100, | ||
"plugins": ["./packages/@glimmerx/prettier-plugin-component-templates"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,17 @@ | |
], | ||
"scripts": { | ||
"build": "scripts/build.js", | ||
"format:check": "prettier --check 'packages/**/*.{js,ts}'", | ||
"format": "prettier --write 'packages/**/*.{js,ts}'", | ||
"lint": "eslint . --cache --ext .js,.ts", | ||
"prepublishOnly": "scripts/build.js", | ||
"problems": "tsc -p tsconfig.json --noEmit", | ||
"start": "webpack-dev-server", | ||
"storybook": "yarn build && yarn workspace basic-example-app storybook", | ||
"test": "yarn lint && testem ci && yarn test:babel-plugins", | ||
"test": "yarn format:check && yarn lint && testem ci && yarn test:babel-plugins && yarn test:prettier", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may not want this here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I respond to this in a comment by @chiragpat below. |
||
"test:babel-plugins": "mocha -r esm --timeout 5000 packages/@glimmerx/babel-preset/test packages/@glimmerx/eslint-plugin/test/lib/rules", | ||
"test:ember": "yarn workspace basic-addon ember try:one", | ||
"test:prettier": "mocha -r esm packages/@glimmerx/prettier-plugin-component-templates/test", | ||
"test:playground": "yarn workspace glimmerx-playground test", | ||
"test:watch": "testem" | ||
}, | ||
|
@@ -48,12 +50,10 @@ | |
"@typescript-eslint/eslint-plugin": "^4.18.0", | ||
"@typescript-eslint/parser": "^4.18.0", | ||
"babel-loader": "^8.0.6", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.1", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"eslint": "^7.29.0", | ||
"fs-extra": "^9.0.0", | ||
"lerna": "^3.20.2", | ||
"prettier": "^2.0.4", | ||
"prettier": "^2.3.1", | ||
"qunit": "^2.9.3", | ||
"release-it": "^13.5.1", | ||
"release-it-lerna-changelog": "^2.1.2", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/@glimmerx/prettier-plugin-component-templates/.prettierignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
test/fixtures/*/code.* | ||
test/fixtures/*/output.* |
63 changes: 63 additions & 0 deletions
63
packages/@glimmerx/prettier-plugin-component-templates/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# prettier-plugin-glimmer-experimental | ||
|
||
## Background | ||
|
||
[Prettier](https://prettier.io/docs/en/index.html) is an opinionated code formatter. In Prettier `>2.0` there is support for `*.hbs` glimmer files, but does not support the experimental syntaxes that `glimmerx` components are authored in. | ||
|
||
## Introduction | ||
|
||
This plugin extends the internal printers to add an embedded syntax for glimmer template in an `hbs` TaggedTemplateExpressions. | ||
|
||
## Installation and Usage | ||
|
||
```bash | ||
yarn add -D @glimmerx/prettier-plugin-component-templates | ||
``` | ||
|
||
Once added prettier will discover and use the plugin to format any `hbs` tagged template expression. | ||
|
||
### Options | ||
|
||
In your prettier config options (e.g. `.prettierrc`, `prettier.config.js`, etc.) | ||
|
||
`.prettierrc` | ||
|
||
```json | ||
{ | ||
"hbsSingleQuote": true | ||
} | ||
``` | ||
|
||
Defaults to `false` forcing double-quotes for all attributes in an hbs embed. When `true` will rewrite all quotes to single-quotes. | ||
|
||
## Development | ||
|
||
Generate a test case, add it to the tests file, | ||
|
||
Add `PRETTIER_DEBUG=true` to the environment when running the plugin in order to get complete stack traces on errors. | ||
|
||
### Debugging | ||
|
||
#### Debugging | ||
|
||
``` | ||
PRETTIER_DEBUG=true node --inspect-brk node_modules/.bin/prettier --config=./test/fixtures/basic/config.js ./test/fixtures/basic/code.js | ||
``` | ||
|
||
### Generate a snapshot | ||
|
||
``` | ||
node node_modules/.bin/prettier --ignore-path --config=./test/fixtures/simple-formatted/config.js ./test/fixtures/simple-formatted/code.js > ./test/fixtures/simple-formatted/output.js | ||
``` | ||
|
||
### Testing | ||
|
||
#### Run all tests | ||
|
||
``` | ||
yarn test | ||
``` | ||
|
||
## TODO | ||
|
||
- [ ] Add support for `<template>` tag semantics. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this just be done by the prettier plugin in eslint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When prettier and eslint both do formatting we get sometimes a double rewrite of a file, with the collision of rules being applied to a tagged template expression.
What we're doing now is simply using prettier to do a style-check format and do a check then use eslint lint for anti-patterns.