js-beautify icon indicating copy to clipboard operation
js-beautify copied to clipboard

Add minimum attributes option for attribute wrap

Open ang-zeyu opened this issue 3 years ago • 7 comments

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 avatar Jul 18 '20 17:07 ang-zeyu

@ang-zeyu Sorry, you'll need to resolve your change against the new master branch.

bitwiseman avatar Jul 21 '20 07:07 bitwiseman

Done, thanks!

What do you think of the scope of the usage? Should it affect auto and aligned-multiple?

ang-zeyu avatar Jul 21 '20 15:07 ang-zeyu

@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.

bitwiseman avatar Aug 13 '20 02:08 bitwiseman

@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 🙂

ang-zeyu avatar Aug 13 '20 16:08 ang-zeyu

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

quantizor avatar Aug 30 '20 18:08 quantizor

@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.

bitwiseman avatar Sep 01 '20 00:09 bitwiseman

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.

ang-zeyu avatar Apr 20 '21 07:04 ang-zeyu

I would love to see this feature in js-beautify as well as VS Code HTML formatter.

bumbummen99 avatar Feb 14 '23 23:02 bumbummen99

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.

Ahrengot avatar Feb 16 '23 19:02 Ahrengot

Would love this!

savaonepunch avatar May 06 '23 00:05 savaonepunch