@herb-tools/formatter 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,11 +35,6 @@ bun add -g @herb-tools/formatter
35
35
 
36
36
  :::
37
37
 
38
- Then run directly:
39
- ```bash
40
- herb-format template.html.erb
41
- ```
42
-
43
38
  ### One-time Usage
44
39
  For occasional use without installing:
45
40
 
@@ -69,8 +64,30 @@ bun add -D @herb-tools/formatter
69
64
 
70
65
  :::
71
66
 
72
- After installing as a dev dependency, add format scripts to your `package.json`:
73
- ```json
67
+ After installing as a dev dependency, initialize the configuration:
68
+
69
+ :::code-group
70
+
71
+ ```shell [npm]
72
+ npx herb-format --init
73
+ ```
74
+
75
+ ```shell [pnpm]
76
+ pnpm herb-format --init
77
+ ```
78
+
79
+ ```shell [yarn]
80
+ yarn herb-format --init
81
+ ```
82
+
83
+ ```shell [bun]
84
+ bunx herb-format --init
85
+ ```
86
+
87
+ :::
88
+
89
+ Then add format scripts to your `package.json`:
90
+ ```json [package.json]
74
91
  {
75
92
  "scripts": {
76
93
  "herb:format": "herb-format",
@@ -116,6 +133,12 @@ herb-format template.html.erb
116
133
  herb-format templates/
117
134
  ```
118
135
 
136
+ **Initialize configuration:**
137
+ ```bash
138
+ # Create a .herb.yml configuration file
139
+ herb-format --init
140
+ ```
141
+
119
142
  #### Options
120
143
 
121
144
  **Check Mode:**
@@ -151,10 +174,92 @@ herb-format --help
151
174
  herb-format --version
152
175
  ```
153
176
 
154
- <!-- #### Configuration Options -->
177
+ ## Configuration
178
+
179
+ Create a `.herb.yml` file in your project root to configure the formatter:
180
+
181
+ ```bash
182
+ herb-format --init
183
+ ```
184
+
185
+ ### Basic Configuration
186
+
187
+ ```yaml [.herb.yml]
188
+ formatter:
189
+ enabled: true # Must be enabled for formatting to work
190
+ indentWidth: 2
191
+ maxLineLength: 80
192
+
193
+ # Additional glob patterns to include (additive to defaults)
194
+ include:
195
+ - '**/*.xml.erb'
196
+
197
+ # Glob patterns to exclude from formatting
198
+ exclude:
199
+ - 'vendor/**/*'
200
+ - 'node_modules/**/*'
201
+ - 'app/views/generated/**/*'
202
+ ```
203
+
204
+ ### Default File Patterns
205
+
206
+ By default, the formatter processes:
207
+ - `**/*.html`
208
+ - `**/*.rhtml`
209
+ - `**/*.html.erb`
210
+ - `**/*.html+*.erb`
211
+ - `**/*.turbo_stream.erb`
212
+
213
+ The `include` patterns are **additive** - they add to the defaults.
214
+
215
+ ### Configuration Options
216
+
217
+ - **`enabled`**: `true` or `false` - Must be `true` to enable formatting
218
+ - **`indentWidth`**: Number (default: `2`) - Spaces per indentation level
219
+ - **`maxLineLength`**: Number (default: `80`) - Maximum line length before wrapping
220
+ - **`include`**: Array of glob patterns - Additional patterns to format (additive to defaults)
221
+ - **`exclude`**: Array of glob patterns - Patterns to exclude from formatting
222
+
223
+ ### Force Flag
224
+
225
+ Format files even when formatter is disabled:
226
+
227
+ ```bash
228
+ # Force formatting when disabled in config
229
+ herb-format --force
230
+
231
+ # Force formatting on an excluded file
232
+ herb-format --force app/views/excluded-file.html.erb
233
+ ```
234
+
235
+ When using `--force` on an excluded file, the formatter will show a warning but proceed with formatting.
236
+
237
+ ## Rewriters
238
+
239
+ The formatter supports **rewriters** that allow you to transform templates before and after formatting.
240
+
241
+ Configure rewriters in your `.herb.yml`:
242
+
243
+ ```yaml [.herb.yml]
244
+ formatter:
245
+ enabled: true
246
+ indentWidth: 2
247
+
248
+ rewriter:
249
+ # Pre-format rewriters (run before formatting)
250
+ pre:
251
+ - tailwind-class-sorter
252
+
253
+ # Post-format rewriters (run after formatting)
254
+ post: []
255
+ ```
256
+
257
+ ### Built-in Rewriters
258
+
259
+ - **`tailwind-class-sorter`** - Automatically sorts Tailwind CSS classes according to the recommended order
155
260
 
156
- <!-- TODO -->
261
+ ### Custom Rewriters
157
262
 
158
- <!-- #### CLI Usage -->
263
+ You can create custom rewriters by placing them in `.herb/rewriters/` and referencing them in your config.
159
264
 
160
- <!-- TODO -->
265
+ For detailed documentation on creating and using rewriters, see the [Rewriter Documentation](/projects/rewriter).