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

TypeScript oddly formatted with 1.5.3 #552

Closed
harlyq opened this issue Oct 3, 2014 · 6 comments
Closed

TypeScript oddly formatted with 1.5.3 #552

harlyq opened this issue Oct 3, 2014 · 6 comments
Milestone

Comments

@harlyq
Copy link

harlyq commented Oct 3, 2014

With library 1.5.3 TypeScript appears as (formatting settings listed below):

class Test {
    blah: string[];

    foo(): number {
        return 0;
    }

        bar(): number {  // <-- why is this indented?
        return 0;
    }
}

With an older version (Sublime-HTMLPrettify was using 1.5.0) the same code would appear as:

class Test {
    blah: string[];

    foo(): number {
        return 0;
    }

    bar(): number {
        return 0;
    }
}

Seems to be related to the presence of the : character, removing some of the type information will fix the formatting. Is there a different configuration that will work with TypeScript?

options (from Sublime-HTMLPrettify):

{
  // Details: https://github.com/victorporof/Sublime-HTMLPrettify#using-your-own-jsbeautifyrc-options
  // Documentation: https://github.com/einars/js-beautify/
  "html": {
    "allowed_file_extensions": ["htm", "html", "xhtml", "shtml", "xml", "svg"],
    "brace_style": "collapse", // "expand", "end-expand", "expand-strict"
    "indent_char": " ",
    "indent_handlebars": false, // e.g. {{#foo}}, {{/foo}}
    "indent_inner_html": false,
    "indent_scripts": "keep", // "separate", "normal"
    "indent_size": 4,
    "max_preserve_newlines": 10,
    "preserve_newlines": true,
    "unformatted": ["a", "sub", "sup", "b", "i", "u", "pre"],
    "wrap_line_length": 0
  },
  "css": {
    "allowed_file_extensions": ["css", "scss", "sass", "less"],
    "end_with_newline": false,
    "indent_char": " ",
    "indent_size": 4,
    "selector_separator": " ",
    "selector_separator_newline": false
  },
  "js": {
    "allowed_file_extensions": ["js", "json", "jshintrc", "ts"],
    "brace_style": "collapse", // "expand", "end-expand", "expand-strict"
    "break_chained_methods": false,
    "e4x": false,
    "eval_code": false,
    "indent_char": " ",
    "indent_level": 0,
    "indent_size": 4,
    "indent_with_tabs": false,
    "jslint_happy": false,
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "max_preserve_newlines": 10,
    "preserve_newlines": true,
    "space_before_conditional": true,
    "space_in_paren": false,
    "unescape_strings": false,
    "wrap_line_length": 0
  }
}
@harlyq
Copy link
Author

harlyq commented Oct 3, 2014

issue from victorporof/Sublime-HTMLPrettify#162

@bitwiseman
Copy link
Member

Because this is a javascript beautifier and you're passing it TypeScript. 😄

This a perfect example of how not fully parsing (#200) is a strength rather than a weakness.

The reason this bug showed up is that in javascript the : only appears in specific places. Until now, the beautifier did pay attention to this, which resulted in other bugs and limitations. Making the formatting of of javascript better required us to start looking at these when then resulted in that class declaration being viewed as a object literal, which has different semantics and indenting. 😱

This will work fine if you do this:

class Test {
    foo(): number {
        return 0;
    }
    blah: string[];

    bar(): number {
        return 0;
    }
}

But lets be honest, that sucks. I'll fix this shortly.

@bitwiseman
Copy link
Member

Any other oddness you want to tell me about? While I'm fixing and testing this one, I might as well wrap up an others.

@bitwiseman bitwiseman added this to the v1.6.0 milestone Oct 3, 2014
@bitwiseman bitwiseman modified the milestones: v1.6.0, v1.5.4 Oct 4, 2014
@harlyq
Copy link
Author

harlyq commented Oct 4, 2014

Thanks for the prompt fix.

The other oddifies I've seen introduce some unnecessary space into optional parameters:

blah ? : number // is better withouth the space between ? and : e.g. blah ?: number

and generics:

foo < T > (); // simpler without some of the spaces as foo() or foo< T >()

But they're not big problems.

bitwiseman added a commit that referenced this issue Oct 4, 2014
@bitwiseman
Copy link
Member

Yeah, saw those. Could you file these as a new issue. They won't be addressed anytime soon, but it would be good to have them tracked (and opened by someone other than me, so we know later on that it wasn't some whim of mine 😄 ).

@harlyq
Copy link
Author

harlyq commented Oct 5, 2014

Created #555

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