Skip to content

Commit

Permalink
documentation: Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
gitKrystan committed Nov 3, 2022
1 parent 7f90cb0 commit b8a9a9c
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 51 deletions.
2 changes: 0 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ dist-ssr
.npmrc

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
Expand Down
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/1-bug-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: 🐞 Bug report
about: Report a bug in the plugin. Before you create a new issue, please
search for similar issues. It's possible somebody has encountered this bug already.
title: '[Bug] Bug report'
labels: ''
assignees: ''
---

### 🐞 Describe the Bug

A clear and concise description of what the bug is.

### 🔬 Minimal Reproduction

Describe steps to reproduce. If possible, please create a PR with a failing test as described in `CONTRIBUTING.md`.

### 😕 Actual Behavior

A clear and concise description of what is happening.

### 🤔 Expected Behavior

A clear and concise description of what you expected to happen.

### 🌍 Environment

- prettier-plugin-ember-template-tag version: -
- ember-template-imports version: -

### ➕ Additional Context

Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/2-feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: 🚀 Feature request
about: Request a feature for the plugin. Before you create a new issue, please
search for similar issues.
title: '[Feature] Feature request'
labels: ''
assignees: ''
---

### 💬 Describe the Feature

A clear and concise description of what the feature is.

### 🔬 Use Case

Describe your use case.

### ➕ Additional Context

Add any other context about the problem here.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/3-other.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Other
about: Report an issue that does not fit any of the categories above.
title: ''
labels: ''
assignees: ''
---
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ dist-ssr
.npmrc

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
Expand Down
2 changes: 0 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ dist-ssr
.npmrc

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
Expand Down
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"visualstudioexptteam.vscodeintellicode"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/src/main.ts",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"sourceMaps": true
},
{
"type": "node",
"request": "launch",
"name": "Debug Current Test File",
"autoAttachChildProcesses": true,
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceRoot}/node_modules/vitest/vitest.mjs",
"args": ["run", "${relativeFile}"],
"smartStep": true,
"console": "integratedTerminal"
}
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"explorer.excludeGitIgnore": true,
"npm.packageManager": "pnpm",
"eslint.packageManager": "pnpm",

"editor.formatOnSave": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// Turn off this formatter so Prettier will be the only formatter and the user won't have to pick.
"javascript.format.enable": false
}
114 changes: 99 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,114 @@
## Try it out
# Contributing to prettier-plugin-ember-template-tag

1. Edit `example.gjs` or `example.gts` to make the ugliest component file you can think of.
1. Run `pnpm run example` or `pnpm run example-ts`
Thank you so much for your contributions!

## Bug Reports and Issues

If you find a bug, please [open an issue](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/new/choose) to describe it. If you can also open a PR with a failing test, that would be awesome.

Currently there are several `HACK`s and `FIXME`s in the code. If you happen to find a bug, it might be worthwhile to look through those to see if they might be the culprit.

Find me on the [Ember Discord](https://discord.com/invite/emberjs) at `hm_krystan#0533` if I don't respond to your issue in a timely manner.

## Development

1. Ensure you have the following set up in your development environment:

- [node](https://nodejs.org/en/download/)
- [pnpm](https://pnpm.io/)

1. [Fork this repo](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/fork) and pull.

1. Install dependencies:

```bash
pnpm install --recursive
```

1. Run the tests to ensure your development environment is working properly:

Watch mode:

```bash
pnpm test
```

Single run:

```bash
pnpm test:run
```

Watch mode with a cute UI in the browser:

```bash
pnpm test:ui
```

## Pull Requests

## Prior art and useful links
We love pull requests. Here's a quick guide:

https://prettier.io/docs/en/plugins.html#developing-plugins
1. Follow the [Development](#development) guide above to set up your environment.

https://medium.com/@fvictorio/how-to-write-a-plugin-for-prettier-a0d98c845e70
1. Add a test for your change. Only refactoring and documentation changes require no new tests. If you are adding functionality or fixing a bug, we need a test! The best tests will fail without your code and pass with it. See the [Tests](#tests) section below for tips on writing tests.

https://github.com/ember-template-imports/ember-template-imports/blob/master/src/preprocess-embedded-templates.ts#L180
1. Make the test pass. See the [Examples](#examples) section below for a useful development workflow.

https://github.com/ember-template-imports/ember-template-imports/blob/master/src/parse-templates.ts
1. Update the README, etc, as necessary if the documentation is affected by your change.

https://github.com/glimmerjs/glimmer-experimental/tree/master/packages/%40glimmerx/prettier-plugin-component-templates
1. Ensure that the linters and Prettier pass:

https://github.com/ember-template-lint/ember-template-lint/pull/2483/files
To lint:

https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLAtgBwgJxgAgGEItoECAzHE-AcgAEBzAGw3ThwHpJSpzaA3AB0oI-PgDaAfSkBxADIBJALLKAogCUpAFTXKACvICCugBQADEWPwAeABYBGAHzj8ACTjNmEfAHVczAAm+A7unt5+AcEOHl4+-jhBIbERCUkx4fFRyZmRidEpWfk5cXnphWXR4jacjk4i5gA0+MD4AM4wOKhgMMoQgXBI+J0ArnD4AL4AlAC6VlCQUB346CPMMKisfPgAvJIyCirqWroGxmaWolDVda4VacEATGGlD-iP99kfuW-fr1+fYp-VIAn5faq1ZwNZqtDpdHp9AZDUbjaZzK6cABUmLEmPwRmucAAHgBDLDMcayABSAGV8BRNuNoPgAO52bp2VnjMAk644EbXGB2cb6HBwGAbDj03D4al0zDMEaMVBQAB0uM4ImJ2Dw+AGFBJawIYGYJLabXwygAnsReORrMT4FBAhbbdg+LAWtZpHIlKpNDo9IYTGoLNYbs47mDigBmF4g2OApIxpPBFPR5Op-Dp-6JjNpiF1axNFrtTrdXr9QbDfmo2bzcRskkEPbmeDk5vjVjwHAk5jDOzN-CoC1QCAEEnDOAd+CXBuuBecTj4ABWI2Wk9Y-Z47FgIgmIEaIAgmA20DayFAJJw1BZ+mvCAvKD7LJJVovR4ARr2wABrcU0mScDyCqcDIAazBtHAX4-v+MA0pgJJgCqjDICiR7Tp+cCBAMgTyLyjAjCSjBwAAYrg6DNhsUCoc+IwwBAh4gHYMDoMwvjsvAbSIWAcA0o+qAbAAboJVrIOA5pMSqUF4KKxGUeBfZQUeK5tESNIoRSACKIzjmBSAQcpICITgMniZ+JJYcwTGYF0sC+KggRCsgAAcAAMR62RAUG+L2mDibZcAyUJYFHgAjrp8CiieT4gGaAC0fDYdhTFihFqBinJjAKQZSnQSAUHoKgaG1kebSaXAOl6YpkH5TAlkOU5djII8R6dCSmwobaOUgEFACsTHrnA2iWU+hn5UJYyKM65A0mAXSngSgQ0jAVoUjVUETBMQA
```bash
pnpm lint
```

https://github.com/prettier/prettier/blob/main/commands.md
To run autofix:

```bash
pnpm lint:fix
```

1. Commit your changes. Please include a [useful commit message](https://initialcommit.com/blog/git-commit-messages-best-practices). If your pull request fixes an issue, specify the issue number in the commit message (e.g. `FIXES #123`).

1. Push to your fork and submit a pull request. Please provide us with some explanation of why you made the changes you made. For new features make sure to explain a standard use case to us.

1. Find me on the [Ember Discord](https://discord.com/invite/emberjs) at `hm_krystan#0533` if I don't respond to your pull request in a timely manner.

NOTE: Partially copied from https://github.com/emberjs/ember.js/blob/master/CONTRIBUTING.md

## Examples

1. Follow the [Development](#development) guide above to set up your environment.

1. Edit `example.gjs` or `example.gts` to make the ugliest component file you can think of.

1. Run `pnpm run example` or `pnpm run example-ts` to prettify your ugly file. 😍 (Note that `run example` will also build the project, so it may take a second.)

1. Don't commit your changes to the example files.

## Tests

`pnpm test`
Most of the tests are generated by formatting example files from the `cases` directory and comparing the output to [Vitest snapshots](https://vitest.dev/guide/snapshot.html).

You can find the test file here: https://github.com/gitKrystan/prettier-plugin-ember-template-tag/blob/main/tests/format.test.ts

To add a new case, add your case file(s) in the appropriate place(s) here: https://github.com/gitKrystan/prettier-plugin-ember-template-tag/tree/main/tests/cases

New cases will be tested against a variety of configs. If you also want to test against for "ambiguous expressions" issues as described [here](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/1), you can include the comment `/*AMBIGUOUS*/` anywhere in your test cases and it will be replaced by the ambiguous cases listed [here](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/blob/de5722b476d83671fdf199a6a8097978fe245a46/tests/format.test.ts#L20-L29) in a variety of generated tests. If you find a new ambiguous case, add it to that list.

Once you make your changes and/or add new cases `pnpm test -u` to update the snapshots then carefully inspect the results to ensure the output matches your expecations.

## Prior Art and Useful Resources

[Prettier plugin development documentation](https://prettier.io/docs/en/plugins.html#developing-plugins)

[Prettier printer doc commands](https://github.com/prettier/prettier/blob/main/commands.md)

[Ember Template Imports method to preprocess embedded templates](https://github.com/ember-template-imports/ember-template-imports/blob/master/src/preprocess-embedded-templates.ts#L180)

## Bugs
[Sample AST and Prettier doc for preprocessed embedded templates](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLAtgBwgJxgAgGEItoECAzHE-AcgAEBzAGw3ThwHpJSpzaA3AB0oI-PgDaAfSkBxADIBJALLKAogCUpAFTXKACvICCugBQADEWPwAeABYBGAHzj8ACTjNmEfAHVczAAm+A7unt5+AcEOHl4+-jhBIbERCUkx4fFRyZmRidEpWfk5cXnphWXR4jacjk4i5gA0+MD4AM4wOKhgMMoQgXBI+J0ArnD4AL4AlAC6VlCQUB346CPMMKisfPgAvJIyCirqWroGxmaWolDVda4VacEATGGlD-iP99kfuW-fr1+fYp-VIAn5faq1ZwNZqtDpdHp9AZDUbjaZzK6cABUmLEmPwRmucAAHgBDLDMcayABSAGV8BRNuNoPgAO52bp2VnjMAk644EbXGB2cb6HBwGAbDj03D4al0zDMEaMVBQAB0uM4ImJ2Dw+AGFBJawIYGYJLabXwygAnsReORrMT4FBAhbbdg+LAWtZpHIlKpNDo9IYTGoLNYbs47mDigBmF4g2OApIxpPBFPR5Op-Dp-6JjNpiF1axNFrtTrdXr9QbDfmo2bzcRskkEPbmeDk5vjVjwHAk5jDOzN-CoC1QCAEEnDOAd+CXBuuBecTj4ABWI2Wk9Y-Z47FgIgmIEaIAgmA20DayFAJJw1BZ+mvCAvKD7LJJVovR4ARr2wABrcU0mScDyCqcDIAazBtHAX4-v+MA0pgJJgCqjDICiR7Tp+cCBAMgTyLyjAjCSjBwAAYrg6DNhsUCoc+IwwBAh4gHYMDoMwvjsvAbSIWAcA0o+qAbAAboJVrIOA5pMSqUF4KKxGUeBfZQUeK5tESNIoRSACKIzjmBSAQcpICITgMniZ+JJYcwAC0MAfsZXSwL4qCBEKyAABwAAxHpg1BQb4vaYOJvlwDJQlgUeACOunwKKJ5PiAZrWXw2HYUxYrRagYpyYwCkGUp0EgFB6CoGhtZHm0mlwDpemKZBhUwJZzmuXYyCPEenQkpsKG2nlIChQArEx65wNollPoZhVCWMijOuQNJgF0p4EoENIwFaFJ1VBEwTEAA)

HACKs and FIXMEs
[Prettier plugin for experimental hbs tagged expressions](https://github.com/glimmerjs/glimmer-experimental/tree/master/packages/%40glimmerx/prettier-plugin-component-templates)
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![npm](https://img.shields.io/npm/v/prettier-plugin-ember-template-tag.svg)](https://www.npmjs.com/package/prettier-plugin-ember-template-tag)
[![license](https://img.shields.io/npm/l/prettier-plugin-ember-template-tag.svg)](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/blob/main/LICENSE.md)

A [Prettier](https://prettier.io/) plugin for formatting [Ember template tags](https://rfcs.emberjs.com/id/0779-first-class-component-templates/).
A [Prettier](https://prettier.io/) plugin for formatting [Ember template tags](https://rfcs.emberjs.com/id/0779-first-class-component-templates/) in both `.gjs` and `.gts` files. See also [Ember Template Imports](https://github.com/ember-template-imports/ember-template-imports).

## Usage

Expand Down Expand Up @@ -40,6 +40,29 @@ A [Prettier](https://prettier.io/) plugin for formatting [Ember template tags](h

1. Run `npm prettier --write .`

## Opinions

This plugin works by weaving together Prettier's standard [babel-ts](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBLWcBOAzAhmOAAgFkBPASQx3yOAB0pDDsIIAKASiUIGcZN0AcwA0DJgCNcmbgEFMmXKQA8UAK4BbcVgB8oqAF8GDOAA8ADhEwxCucXwVhrYADa4ePQgDFWhVOrPOcOoIMB5klPDUBIT0jMysnDFiTCmpTAD06YQAKgDyACK53JhwMKqYjLiVjqq4zoQAbnWqRAAWWHDJaYQlZRWEAOTtzs4QA10phnGCpYSSmImxqb3ljADaTACMehNMAEzChADMeqkAuslTUwwwpGZEAEpwAI4tfNl3RAC8gwDiAKLZAaEAA+gwAEv8ZPlgWCBgAFXIAZSBoMG8IAqqi4bl4dlyLkAHJI2GDADCRMJ-zJ2MG+X+ABlAf9SQNsg8ZGSWSBhCAIGYYKhoDxkKApJgIAB3eFSBAilB1SWKEW88QOADWpSRuGCDPQcGQeGcPDgqo1WrM+CEyH4LV5QS0ABNHXBHQyqoJajNvJh1LgYIKoIJkCBcKoYBAeSBWjB1M4AOqtVDwHiWghIuXJ1ANZOkENgdxR9AmqzwhSCP2Guom3kAKx4JiRQkCAEVVBB4FXjaaQJbMCWQ5ItM4ALShKNmASweOoR0wVrIAAcAAZeZOICb4wozCHJ3ASw0DbzXh24GX+fLQzwR1A4K7XVGSq9UCUy7gK7guzWQCb1KgbZgdo-s2cBtqeX49jAtgznOC5IAcID8LgqDOEIZIQOolYoPuACsUaqCa2S2PKRrfg0LSUC6sBImAAgCjIUCOkityBBB+j6EAA) and [glimmer](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEACVAeAJgSwG7qFgA2AhgM7kC8AOiAjAE4CedhqAfDVOhgBYBGDsGDoYOGMTjsAvjIwB6QVx6ZcBdCQrU6AIwhZWIFe1OERhfYbOE53Reo6YFjkABoQEAA7jo5ZKCkjIwQAO4ACkEI-iikxKGkzP4euoykYADWcDAAyqQAtnAAMjhQcMgAZnHkcClpmdk5XumlAObITACutfT5unBYWANFpFCtnaStcABiEIz5pDDiY8ggpJ0wEO4gfDD5xADqfBJw5M1gcDnREvgSzKtglNulNYww4WmtC5XVPQBW5AAHjk2lIAIqdCDwH7EGoeZqMV6rVrEHD5QqMbZeRilGAHHBYGB8ZAADgADPCQjUDmkvKtsac4Iw8OUPABHSHwD7eGJrcgAWjKAwG20YcA5ODFH0m3yQVVhPRq+RwHUY3Q85FBcAhUPKct+HhgpF0+MJxKQACZDWkcKixgBhCDo0irU4AVm2nRqABVjTF5XCQHhugBJKBDWA5MA4nwAQXDORgzCkMJqciAA) parsers, so it doesn't have many opinions of its own.

With that said, I did have to make some decisions about when and where to include or omit semicolons. You can read more about and comment on my decision process [on this RFC](https://github.com/gitKrystan/prettier-plugin-ember-template-tag/issues/1).

## Configuration

The current version offers no configuration options but the plan is to allow the relevant [standard
config options for JavaScript files](https://prettier.io/docs/en/configuration.html) to be separately configured for the `<template>` portion of the file.

<!-- TODO: These configuration options are available in addition to [Prettier's standard
config for JavaScript files](https://prettier.io/docs/en/configuration.html).
| Name | Default | Description |
| --------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `templatePrintWidth` | `80` | [Same as in Prettier](https://prettier.io/docs/en/options.html#print-width) but affecting only template tags |
| `templateSingleQuote` | `false` | Same as in Prettier](https://prettier.io/docs/en/options.html#print-width) but affecting only template tags | -->

<!-- TODO: ## Editor integration
### VScode -->

## Ignoring code

Because gts/gjs files include both JavaScript and Glimmer template code, you'll need to use the appropriate prettier-ignore comment for the code you are ignoring:
Expand All @@ -55,7 +78,7 @@ export default class MyComponent extends Component {

<template>
{{! prettier-ignore }}
{{#each cells as |cell|}}{{cell.contents}}{{/each}}
{{#each this.cells as |cell|}}{{cell.contents}}{{/each}}
</template>
}
```
Expand All @@ -78,26 +101,4 @@ export default class MyComponent extends Component {

## Bugs

If there are errors, please file a bug report so that they can be fixed.

TODO: Process

## Opinions

TODO: link to RFC

<!-- TODO: ### Configuration
These configuration options are available in addition to [Prettier's standard
config for JavaScript files](https://prettier.io/docs/en/configuration.html).
| Name | Default | Description |
| --------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `templatePrintWidth` | `80` | [Same as in Prettier](https://prettier.io/docs/en/options.html#print-width) but affecting only template tags |
| `templateSingleQuote` | `false` | Same as in Prettier](https://prettier.io/docs/en/options.html#print-width) but affecting only template tags | -->

<!-- ## Editor integration
### VScode
TODO -->
If you find a bug, please file a bug report! See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "prettier-plugin-ember-template-tag",
"version": "0.0.0",
"version": "0.0.1",
"description": "A prettier plugin for formatting Ember template tags",
"keywords": [
"prettier",
"ember",
"template tag",
"ember template imports",
"gjs",
"gts",
"gjs"
"prettier",
"template tag"
],
"author": {
"email": "[email protected]",
Expand All @@ -28,7 +29,6 @@
"registry": "https://registry.npmjs.org"
},
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"example": "vite build && ./node_modules/.bin/prettier --plugin . --write examples/example.gjs",
"example-ts": "vite build && ./node_modules/.bin/prettier --plugin . --write examples/example.gts",
Expand Down

0 comments on commit b8a9a9c

Please sign in to comment.