js-beautify
js-beautify copied to clipboard
Add minimum attributes option for attribute wrap
Description
- [x] Source branch in your fork has meaningful name (not
master
)
Fixes Issue: #1758
Usage:
Added a wrap_attributes_min_attrs
/ -M
option (default 2
).
It only affects force/force-aligned/force-expand-multiline
currently.
Does it make sense for the other non preserve
options to be affected as well?
if preferred, I could take a shot at https://github.com/beautify-web/js-beautify/issues/1404 before this. But since this is an extension to the spec proposed there, it should work out even if it's dealt with later
Implementation:
I simply moved the lookahead for force-expand-multiline
to handle_tag_open
, and changed the relevant parts accordingly. This might affect performance a little for force/force-aligned
options.
Alternatively, it could be done at the tokenizer level with an even smaller performance hit (since the read_attribute
handler has easy access to open_token
). I'm not sure if there's something against extending token
for separate beautifiers though
Before Merge Checklist
These items can be completed after PR is created.
(Check any items that are not applicable (NA) for this PR)
- [x] JavaScript implementation
- [x] Python implementation (NA if HTML beautifier)
- [x] Added Tests to data file(s)
- [x] Added command-line option(s) (NA if
- [x] README.md documents new feature/option(s)
@ang-zeyu
Sorry, you'll need to resolve your change against the new master
branch.
Done, thanks!
What do you think of the scope of the usage? Should it affect auto
and aligned-multiple
?
@ang-zeyu
I'm sorry, I have not had time to evaluate this change. I'm going to publish a new version without merging this. This is not comment on the quality of this change. I simply haven't had bandwidth to consider this change properly.
@ang-zeyu I'm sorry, I have not had time to evaluate this change. I'm going to publish a new version without merging this. This is not comment on the quality of this change. I simply haven't had bandwidth to consider this change properly.
Hi @bitwiseman, noted, no worries! We aren't under any schedule here 🙂
Can this be made to work with CSS as well? Would love to set this to -1 or an arbitrarily high number so I can get all CSS property rules on a single line
@probablyup The CSS beautifier is far behind the other beautifiers in development. The others tokenize the input and then beautify it. CSS is processed freeform, meaning it does benefit from most featured implemented for the other beautifiers.
I've changed the behaviour here a little since last (d8bcf29) for the force-expand-multiline
option - min_attrs=1
is now valid for it, e.g.
<input type="text" />
// now possible
<input
type="text"
/>
backward compatibility is still kept since the default min_attrs=2
.
I would love to see this feature in js-beautify as well as VS Code HTML formatter.
Yes, same here. I'm using https://github.com/shufo/blade-formatter and that repo also has multiple open issues for this same feature. Would be really awesome to have this.
Would love this!