Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lines are not un-indented correctly when attributes are wrapped #1103

Closed
HookyQR opened this issue Jan 5, 2017 · 23 comments
Closed

Lines are not un-indented correctly when attributes are wrapped #1103

HookyQR opened this issue Jan 5, 2017 · 23 comments

Comments

@HookyQR
Copy link
Contributor

HookyQR commented Jan 5, 2017

Description

Indenting is broken whenever attribute wrapping happens.

Using js-beautify v1.6.8.

Input

The code looked like this before beautification:

<div first second>content</div>
<div>content</div>

Expected Output

The code should have looked like this after beautification:

<div first 
     second>content</div>
<div>content</div>

Actual Output

The code actually looked like this after beautification:

<div first
     second>content</div>
    <div>content</div>

Steps to Reproduce

Beautify the code

Environment

OS: MacOS

Settings

Example:

{
    "wrap_attributes": "force-aligned"
}

Note: wrap_attributes doesn't have to be set to force-aligned. Any wrapping (excluding "force-expand-multiline") introduces, including if "auto" caused the wrapping will demonstrate this issue.

@starstuffharvestingstarlight

I'm experiencing the same issue (via atom-beautify #735 )

<p attr1 attr2 attr3>
  text
</p>

turns into

<p attr1
    attr2
    attr3>
  text
  </p>

my force wrap is on

@chenasraf
Copy link

Same here, the code just keeps getting more and more indented up until the last moment. It's impossible to use this beautifier anymore like this, I have to manually format the code :/

<nav id="header"
  class="navbar navbar-default">
  <div class="header-container container-fluid">
    <div class="logo-container navbar-header">
      <a ui-sref="stats"
        class="navbar-brand pws-icon pws-pws"></a>
    </div>
    <div class="header-contents collapse navbar-collapse">
      <ul class="tab-list nav navbar-nav">
        <li class="tab tab-prospects"
          ui-sref-active="active">
          <a ui-sref="stats">
            Stats
          </a>
          </li>
          <li class="tab tab-prospects"
            ui-sref-active="active">
            <a ui-sref="upload">
              Importer
            </a>
            </li>
            <li class="tab tab-prospects"
              ui-sref-active="active">
              <a ui-sref="territories">
                Territory Assignment
              </a>
              </li>

      </ul>
    </div>
  </div>
  </nav>

@renatoaraujoc
Copy link

renatoaraujoc commented Jan 10, 2017

I can confirm this bug, randomly started happening.
Whenever a tag' attributes wraps, the inner content starts to indent incorrectly.

[edit]
I had to disable this plugin to resume my work until a fix is delivered =/

@matheusdavidson
Copy link

same here! =/

@chenasraf
Copy link

@bitwiseman Is anyone working on this? This is a pretty popular package and this is a pretty big issue... I'd love to see it fixed :( unfortunately I'm not sure I know what to change to contribute the code myself. Maybe some pointers?

@matheusdavidson
Copy link

matheusdavidson commented Jan 31, 2017

seems like removing "wrap_attributes": "force" in html from the .jsbeautifyrc file solves the problem

@bitwiseman
Copy link
Member

@chenasraf - I would love to see this fixed. See Contributing.md for instructions on building locally.
Pull request #1104 shows what a good change looks like: add entries totest/data/html/tests.js, update the product code, and build (the changes to the generated files are done automatically).

@bitwiseman
Copy link
Member

@matheusdavidson - that is good to know. @chenasraf - you'll want to add test to the matrix that already tests the wrap_attributes option.

@kf-ireneuszpatalas
Copy link

Anyone actually working on this? Too many forks to check them all. Maybe I can help.

@bitwiseman
Copy link
Member

@kf-ireneuszpatalas I have not had time to work on it, and @chenasraf is the only other person who has expressed interest.

@chenasraf
Copy link

@bitwiseman Seems that adding multi_parser.unindent() after js/lib/beautify-html.js:980 fixes this issue, though I'm not sure if this fits there logic-wise, what conditions to add, etc... If you still want me to take care of it it will take a few days 'til I get enough free time to go over the basics of what goes on in the package. Either that or maybe someone else want to take the reins

@bitwiseman
Copy link
Member

@chenasraf - that causes multiple tests to fail before I even do anything else. Yes, I still want you to address this if you can.

@HookyQR
Copy link
Contributor Author

HookyQR commented Feb 10, 2017

@chenasraf, @bitwiseman. I have some time to take a look tomorrow.

@HookyQR
Copy link
Contributor Author

HookyQR commented Feb 10, 2017

Found the problem. Fixing now.

HookyQR added a commit to HookyQR/js-beautify that referenced this issue Feb 10, 2017
@HookyQR
Copy link
Contributor Author

HookyQR commented Feb 10, 2017

PR submitted

bitwiseman added a commit that referenced this issue Feb 11, 2017
@bitwiseman bitwiseman modified the milestones: v1.7.x, v1.6.9 Feb 11, 2017
@bitwiseman
Copy link
Member

@HookyQR - Thanks much! Merged and published.

0-wiz-0 pushed a commit to NetBSD/pkgsrc-wip that referenced this issue Apr 14, 2017
pkgsrc changes:
 - Use ALTERNATIVES in order to permit multi-pkgs to coexists and adjust
   PLIST and introduce Makefile post-install target accordingly

Changes:
* CSS: Preserve Newlines ([#537](beautifier/js-beautify#537))

Reverted #1117 - Preserve newlines broken

* On beautify, new line before next CSS selector ([#1142](beautifier/js-beautify#1142))

Added `preserver_newlines` to css beautifier

* Fixed html formatting issue with attribute wrap (Thanks, @HookyQR!)
* Fixed python package publishing

* Wrong HTML beautification starting with v1.6.5 ([#1115](beautifier/js-beautify#1115))
* Ignore linebreak when meet handlebar ([#1104](beautifier/js-beautify#1104))
* Lines are not un-indented correctly when attributes are wrapped ([#1103](beautifier/js-beautify#1103))
* force-aligned is not aligned when indenting with tabs ([#1102](beautifier/js-beautify#1102))
* Python package fails to publish  ([#1101](beautifier/js-beautify#1101))
* Explaination of 'operator_position' is absent from README.md ([#1047](beautifier/js-beautify#1047))

* Fixed a batch of comment and semicolon-less code bugs

* Incorrect indentation after loop with comment ([#1090](beautifier/js-beautify#1090))
* Extra newline is inserted after beautifying code with anonymous function ([#1085](beautifier/js-beautify#1085))
* end brace with next comment line make bad indent ([#1043](beautifier/js-beautify#1043))
* Javascript comment in last line doesn't beautify well ([#964](beautifier/js-beautify#964))
* indent doesn't work with comment (jsdoc) ([#913](beautifier/js-beautify#913))
* Wrong indentation, when new line between chained methods ([#892](beautifier/js-beautify#892))
* Comments in a non-semicolon style have extra indent ([#815](beautifier/js-beautify#815))
* [bug] Incorrect indentation due to commented line(s) following a function call with a function argument. ([#713](beautifier/js-beautify#713))
* Wrong indent formatting ([#569](beautifier/js-beautify#569))

Added `content_unformatted` option (Thanks @arai-a)

* HTML pre code indentation ([#928](beautifier/js-beautify#928))
* Beautify script/style tags but ignore their inner JS/CSS content ([#906](beautifier/js-beautify#906))

* Added support for editorconfig from stdin
* Added js-beautify to cdnjs
* Fixed CRLF to LF for HTML and CSS on windows
* Added inheritance/overriding to config format (Thanks @DaniGuardiola and @HookyQR)
* Added `force-align` to `wrap-attributes` (Thanks @LukinoS)
* Added `force-expand-multiline` to `wrap-attributes` (Thanks @tobias-zucali)
* Added `preserve-inline` as independent brace setting (Thanks @Coburn37)
* Fixed handlebars with angle-braces (Thanks @mmsqe)

* Wrong indentation for comment after nested unbraced control constructs ([#1079](beautifier/js-beautify#1079))
* Should prefer breaking the line after operator ? instead of before operator < ([#1073](beautifier/js-beautify#1073))
* New option "force-expand-multiline" for "wrap_attributes" ([#1070](beautifier/js-beautify#1070))
* Breaks if html file starts with comment ([#1068](beautifier/js-beautify#1068))
* collapse-preserve-inline restricts users to collapse brace_style ([#1057](beautifier/js-beautify#1057))
* Parsing failure on numbers with "e" ([#1054](beautifier/js-beautify#1054))
* Issue with Browser Instructions ([#1053](beautifier/js-beautify#1053))
* Add preserve inline function for expand style braces ([#1052](beautifier/js-beautify#1052))
* Update years in LICENSE ([#1038](beautifier/js-beautify#1038))
* JS. Switch with template literals. Unexpected indentation. ([#1030](beautifier/js-beautify#1030))
* The object with spread object formatted not correctly ([#1023](beautifier/js-beautify#1023))
* Bad output generator function in class ([#1013](beautifier/js-beautify#1013))
* Support editorconfig for stdin ([#1012](beautifier/js-beautify#1012))
* Publish to cdnjs ([#992](beautifier/js-beautify#992))
* breaks if handlebars comments contain handlebars tags ([#930](beautifier/js-beautify#930))
* Using jsbeautifyrc is broken ([#929](beautifier/js-beautify#929))
* Option to put HTML attributes on their own lines, aligned ([#916](beautifier/js-beautify#916))
* Erroneously changes CRLF to LF on Windows in HTML and CSS ([#899](beautifier/js-beautify#899))
* Weird space in {get } vs { normal } ([#888](beautifier/js-beautify#888))
* Bad for-of formatting with constant Array ([#875](beautifier/js-beautify#875))
* Problems with filter property in css and scss ([#755](beautifier/js-beautify#755))
* Add "collapse-one-line" option for non-collapse brace styles  ([#487](beautifier/js-beautify#487))
@Montago
Copy link

Montago commented Jun 8, 2017

Would it be possible to extend the options of wrapping with "auto-align" ??

"force-align" will force wrapping + aligning them...

but let say i don't want to wrap EVERY SINGLE HTML ELEMENT, but only the long ones - and then do them manually ..

so, "auto-align" would only align those that are already wrapped.

@bitwiseman
Copy link
Member

@Montago - Please open a new issue describing what you want, including inputs, outputs, etc.

@Montago
Copy link

Montago commented Jun 9, 2017

@bitwiseman

there's already one open with the functionality i seek: #1125

@blemaire
Copy link

blemaire commented Feb 2, 2018

I have just installed this and I'm getting the indentation issue with grunt and the following option: wrapAttributes: 'force-expand-multiline'
I'm running v1.7.5
Thanks

@affanshahid
Copy link

Also getting this issue with 'force-expand-multiline' any updates?

@0xVesion
Copy link

Also getting this issue with 'force-expand-multiline'

@bitwiseman
Copy link
Member

@affanshahid @vedev
Have you tried this with 1.8.0-rc2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests