You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve handling of whitespace and duplicate class removal (#276)
* Add tests
* Be more careful about whitespace removal in concat expressions
* Detect liquid concat expressions in newer ASTs
* Make sure string splicing handles changing string length
* Add option to preserve duplicate classes
This is important when using templating languages
* Disable whitespace removal in Svelte
We’d have to modify the start/end locations of many nodes in the AST. Technically, only AST nodes appearing _after_ the string on the same line but that might actually be sibling nodes and ancestor nodes. It’s a better option for now to disable it.
* Disable whitespace removal in Liquid
* Disable duplicate removal in Liquid and Svelte
* Update changelog
* Update readme
* Update CHANGELOG.md
* Update README.md
---------
Co-authored-by: Jonathan Reinink <[email protected]>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+9-1
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
-
- Nothing yet!
10
+
### Added
11
+
12
+
- Add new `tailwindPreserveDuplicates` option to disable removal of duplicate classes ([#276](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/276))
13
+
14
+
### Fixed
15
+
16
+
- Improve handling of whitespace removal when concatenating strings ([#276](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/276))
17
+
- Fix a bug where Angular expressions may produce invalid code after sorting ([#276](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/276))
18
+
- Disabled whitespace and duplicate class removal for Liquid and Svelte ([#276](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/276))
This plugin automatically removes unnecessary whitespace between classes to ensure consistent formatting. If you prefer to preserve whitespace, you can use the `tailwindPreserveWhitespace` option:
147
+
148
+
```json5
149
+
// .prettierrc
150
+
{
151
+
"tailwindPreserveWhitespace":true,
152
+
}
153
+
```
154
+
155
+
With this configuration, any whitespace surrounding classes will be preserved:
This plugin automatically removes duplicate classes from your class lists. However, this can cause issues in some templating languages, like Fluid or Blade, where we can't distinguish between classes and the templating syntax.
172
+
173
+
If removing duplicate classes is causing issues in your project, you can use the `tailwindPreserveDuplicates` option to disable this behavior:
174
+
175
+
```json5
176
+
// .prettierrc
177
+
{
178
+
"tailwindPreserveDuplicates":true,
179
+
}
180
+
```
181
+
182
+
With this configuration, anything we perceive as duplicate classes will be preserved:
This plugin uses Prettier APIs that can only be used by one plugin at a time, making it incompatible with other Prettier plugins implemented the same way. To solve this we've added explicit per-plugin workarounds that enable compatibility with the following Prettier plugins:
0 commit comments