Improvements in line breaks
Using version 0.3.0, with printWidth: 140 and keySeparator: '=' configuration.
I'm not sure what rules could be inferred, but on these examples the properties before transformation are easier to read.
Before
sonar.cpd.exclusions=\
src/main/java/tech/jhipster/lite/error/infrastructure/primary/ArgumentsReplacer.java,\
src/main/java/tech/jhipster/lite/module/domain/file/ArgumentsReplacer.java
After
sonar.cpd.exclusions=src/main/java/tech/jhipster/lite/error/infrastructure/primary/ArgumentsReplacer.\
java,src/main/java/tech/jhipster/lite/module/domain/file/ArgumentsReplacer.java
Another example:
Before
sonar.exclusions=\
src/main/webapp/main.ts, \
src/main/webapp/app/main.ts, \
src/main/webapp/content/**/*.*, \
src/main/webapp/i18n/*.js, \
target/classes/static/**/*.*, \
src/main/resources/**, \
src/main/webapp/app/router/index.ts, \
src/main/glyph/css/**, \
src/main/webapp/app/common/primary/applicationlistener/WindowApplicationListener.ts
After
sonar.exclusions=src/main/webapp/main.ts, src/main/webapp/app/main.ts, src/main/webapp/content/**/*.*, src/main/webapp/i18n/*.js, \
target/classes/static/**/*.*, src/main/resources/**, src/main/webapp/app/router/index.ts, src/main/glyph/css/**, \
src/main/webapp/app/common/primary/applicationlistener/WindowApplicationListener.ts
Another example:
Before
assertion-error.STRING_TOO_LONG.detail=\
Content of {{ field }} is too long, must be less than {{ maxLength }} character(s) (was {{ currentLength }})
After
assertion-error.STRING_TOO_LONG.detail=Content of {{ field }} is too long, must be less than {{ maxLength }} character(s) (was {{ \
currentLength }})
Yeah, those are hard. One improvement that they do suggest to me is that when a value does not fit on the same line with the key, it might make sense to always (?) start it on the next line instead, using an escaped newline.
Or are there cases where that would be worse choice than the current one?
Yes, always starting on the next line when a value does not fit on the same line with the key sounds like a good and safe idea.
I was also thinking about other heuristics, but I'm not sure they always apply:
- split to a new line after each comma
, - avoid splitting a "word" around a dot
.if there's no space after of before the dot. This should avoid split e.g.src/main/webapp/app/router/index.tstosrc/main/webapp/app/router/index.andts.- or
https://github.com/eemeli/prettier-plugin-propertiestohttps://github.andcom/eemeli/prettier-plugin-properties
split to a new line after each comma
,
This would not really work for property values that are e.g. localizable text.
avoid splitting a "word" around a dot
.if there's no space after of before the dot.
In practice that would probably mean dropping this line, which should be pretty safe.
Or maybe replacing it with case ',':?
Note that the changes under consideration are required in dot-properties, rather than this repo.