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

wrong indent for unclosed <? - need to support disabling templating #1647

Closed
junstyle opened this issue Mar 22, 2019 · 2 comments
Closed

wrong indent for unclosed <? - need to support disabling templating #1647

junstyle opened this issue Mar 22, 2019 · 2 comments
Milestone

Comments

@junstyle
Copy link

Description

wrong indent

Input

The code looked like this before beautification:

class Class {
    init1() {
        let code = "<?php $a='1'";
    }

    init2() {
      let code = "<?php $a='1';?>";
    }

    init3() {
            let code = "<?php $a='1'";
    }
  
 init4() {
            let code = "<php $a='1'";
    }
}

Expected Output

The code should have looked like this after beautification:

class Class {
  init1() {
    let code = "<?php $a='1'";
  }

  init2() {
    let code = "<?php $a='1';?>";
  }

  init3() {
    let code = "<?php $a='1'";
  }
  
  init4() {
    let code = "<php $a='1'";
  }
}

Actual Output

The code actually looked like this after beautification:

class Class {
    init1() {
        let code = "<?php $a='1'";
  }

  init2() {
    let code = "<?php $a='1';?>";
    }

    init3() {
            let code = "<?php $a='1'";
  }
  
  init4() {
    let code = "<php $a='1'";
  }
}

Steps to Reproduce

Environment

OS:
window10

Settings

Example:

{
  "indent_size": "4",
  "indent_char": " ",
  "max_preserve_newlines": "5",
  "preserve_newlines": true,
  "keep_array_indentation": false,
  "break_chained_methods": false,
  "indent_scripts": "normal",
  "brace_style": "collapse",
  "space_before_conditional": true,
  "unescape_strings": false,
  "jslint_happy": false,
  "end_with_newline": false,
  "wrap_line_length": "0",
  "indent_inner_html": false,
  "comma_first": false,
  "e4x": false
}
@bitwiseman
Copy link
Member

bitwiseman commented Mar 22, 2019

@junstyle of course.
Improved support for templating, but I didn't add a way to disable it via options.

https://github.com/beautify-web/js-beautify/blob/master/js/src/javascript/tokenizer.js#L111-L113

Adding this to v1.9.x - coming soon.

@bitwiseman bitwiseman added this to the v1.9.x milestone Mar 22, 2019
@bitwiseman bitwiseman changed the title wrong indent when a string has unclosed <? wrong indent for unclosed <? - need to support disabling templating Apr 16, 2019
@bitwiseman
Copy link
Member

In 1.9.0 we improved the processing of templating languages such as php and turned them on by default. Unfortunately, that causes issues for some users who were no using templating (See #1647 for details).

So, there is a new setting added in 1.10.0: templating.

values: (auto,django,erb,handlebars,php) [default: "auto"] auto = none in JavaScript, all in html

Even though this is html, the area inside the script is treated as Javascript and so by default does not handle php. To fix this, set "templating": "php" (in your .jsbeautifyrc file).

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

2 participants