Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/NiklasPor/prettier-plugin-organize-attributes

Organize your HTML attributes automatically with Prettier 🧼
https://github.com/NiklasPor/prettier-plugin-organize-attributes

angular attributes html organize prettier sort vue

Last synced: about 2 months ago
JSON representation

Organize your HTML attributes automatically with Prettier 🧼

Awesome Lists containing this project

README

        

### prettier-plugin-organize-attributes [![npm](https://img.shields.io/npm/v/prettier-plugin-organize-attributes)](https://www.npmjs.com/package/prettier-plugin-organize-attributes)

## Organize your HTML attributes automatically with Prettier 🧼

```
npm i prettier prettier-plugin-organize-attributes -D
```

- Supports Angular, Vue & HTML with **0** configuration
- Groups are matched from top to bottom.
- Attributes are matched against RegExps or presets.
- A list of additional presets can be found [here](src/presets.ts).
- Attributes which are not matched are put into `$DEFAULT`.
- If `$DEFAULT` is not specified they are appended at the end.
- Attributes in each group can be ordered `ASC` and `DESC` by specifing `attributeSort`.
- Order inside groups remains the same if `attributeSort` is **not** used.

---

- [Usage](#usage)
- [Groups](#groups)
- [Sort](#sort)
- [Presets](#presets)
- [HTML](#html)
- [Angular](#angular)
- [Vue](#vue)
- [Angular Custom](#angular-custom)
- [Code-Guide by @mdo](#code-guide-by-mdo)

## Usage

The following files also work out of the box if the plugin is specified:

- `.html` – [HTML Example](#html)
- `.component.html` – [Angular Example](#angular)
- `.vue` – [Vue Example](#vue)

> Starting with Prettier 3 auto-discovery has been removed. Configuration is required ⬇️

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"]
}
```

Read below for writing custom attribute orders and configurations ⤵️

### Groups

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"],
"attributeGroups": ["^class$", "^(id|name)$", "$DEFAULT", "^aria-"]
}
```

```html


```

```html


```

---

### Sort

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"],
"attributeGroups": ["$DEFAULT", "^data-"],
"attributeSort": "ASC"
}
```

```html


```

```html


```

---

### Case-Sensitivity

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"],
"attributeGroups": ["^group-a$", "^group-b$", "^group-A$", "^group-B$"],
"attributeIgnoreCase": false
}
```

```html


```

```html


```

## Presets

### HTML

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"]
}
```

```html


```

```html


```

### Angular

```json
// .prettierrc
{}
```

```html


```

```html


```

---

### Angular Custom

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"],
"attributeGroups": [
"$ANGULAR_OUTPUT",
"$ANGULAR_TWO_WAY_BINDING",
"$ANGULAR_INPUT",
"$ANGULAR_STRUCTURAL_DIRECTIVE"
]
}
```

```html


```

```html


```

---

### Vue

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"]
}
```

```vue

```

```vue

```

---

### [Code-Guide by @mdo](https://codeguide.co/#html-attribute-order)

```json
// .prettierrc
{
"plugins": ["prettier-plugin-organize-attributes"],
"attributeGroups": ["$CODE_GUIDE"]
}
```

```html


```

```html


```