all classNames should wrap at 50, but code should allow 160
Is your feature request related to a problem? Please describe
Currently, the prettier-plugin-classnames uses the global printWidth setting from Prettier. This makes it impossible to enforce different line lengths for className attributes compared to the rest of the code. For example, I want to allow long lines (e.g., printWidth: 160) for most code but enforce shorter wrapping (e.g., 50 characters) for class names to improve readability and diff clarity.
Describe the solution you'd like
I would like the plugin to support a new option, perhaps called classnamesPrintWidth, that would control the wrapping width specifically for className (or other specified attributes) independently of the global printWidth.
{
"printWidth": 160,
"classnamesPrintWidth": 50
}
Describe alternatives you've considered
- Using prettier-ignore comments for long class names (which is tedious and defeats the purpose of automated formatting).
Hi, there have been similar suggestions in the past (#21, #32), but I would like to avoid adding a custom width option if possible.
Can you explain to me why the className property should have a different line length than the rest of the code?
Hi, and thanks for your reply. I just like long classes of classNames to be on multiple lines because it is easier to read. But functions and other to be longer (also because it is easier to read, as they follow a pattern rather than tailwind words).
I checked other similar posts, but I didn't find a solution to it. If there is, please let me know.
Thank you, and wish you a productive day!
Unfortunately, there is currently no way to configure the length of the class name independently from the printWidth.
However, since the numbers 160 and 50 given as an example are somewhat distant, I thought about in what cases this configuration would be valid. As a result, I've verified that this configuration might work when using a relative endingPosition, and contrary to what I said before, it might be worth considering adding a custom width option.
Specifying a relative endingPosition and a small width for classes sounds like a good idea.
Since relative is the default value for endingPosition, I initially thought it was a bug that the wrapping started at column 144 instead of the specified printWidth of 120.