question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

problem formatting jsx

See original GitHub issue
  • Operating System (+Version): windows 10
  • VS Code Version: 1.11.2
  • beautify Version: 1.0.2

It seems that the beautify is not formatting those code in the render for react code.

e.g. import React, { Component } from ‘react’;

class Welcome3 extends Component { constructor(props) { super(props);

    this.state = {            data: 'initial data',
        test: 1
    }
}

render() {
    return (
        <div>              Welcome3 {this.props.name }                <button onClick=  {this.updateState}>Click to update data</button>
            <h4>state.data: {this.state.data}</h4>
        </div>
    );
}

}

after formatting import React, { Component } from ‘react’;

class Welcome3 extends Component { constructor(props) { super(props);

    this.state = {
        data: 'initial data',
        test: 1
    }
}

render() {
    return (
        <div>              Welcome3 {this.props.name }                <button onClick=  {this.updateState}>Click to update data</button>
            <h4>state.data: {this.state.data}</h4>
        </div>
    );
}

}

code in the render are not formatted. Any settings to solve the problem?

my .jsbeautifyrc { “e4x”: true, // Pass E4X xml literals through untouched // “brace_style”: “collapse-preserve-inline”, “brace_style”: “collapse,preserve-inline”, “break_chained_methods”: false, // Break chained method calls across subsequent lines “end_with_newline”: true, // End output with newline, default false // “indent_char”: " ", // Indentation character // “indent_level”: 0, // Initial indentation level // “indent_size”: 4, // Indentation size “indent_with_tabs”: false, // Indent with tabs, overrides indent_size and indent_char “jslint_happy”: false, // If true, then jslint-stricter mode is enforced “keep_function_indentation”: false, // Preserve function indentation “max_preserve_newlines”: 10, // Maximum number of line breaks to be preserved in one chunk (0 disables) “preserve_newlines”: true, // Whether existing line breaks should be preserved “space_after_anon_function”: false, // Should the space before an anonymous function’s parens be added, “function()” vs “function ()” “space_before_conditional”: true, // Should the space before conditional statement be added, “if(true)” vs “if (true)” “space_in_empty_paren”: false, // Add padding spaces within empty paren, “f()” vs “f( )” “space_in_paren”: false, // Add padding spaces within paren, ie. f( a, b ) “unescape_strings”: false, // Should printable characters in strings encoded in \xNN notation be unescaped, “example” vs “\x65\x78\x61\x6d\x70\x6c\x65” “wrap_line_length”: 0, // Lines should wrap at next opportunity after this number of characters (0 disables)

// common settings used by both jsbeautify and prettydiff
"keep_array_indentation": true // Preserve array indentation

}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

17reactions
leefernandescommented, May 16, 2017

adding a .jsbeautifyrc file with

{
    "e4x": true
}

fixed my issues where beautify was breaking jsx formats in my .js files.

4reactions
donpinkuscommented, Dec 3, 2017

Does not work for me.

1.18.1

Before: screen shot 2017-12-03 at 10 13 14 am

After: screen shot 2017-12-03 at 10 13 24 am

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does jsx code formatting not correctly - Stack Overflow
9 Answers 9 · Press Ctrl+Shift+P(Win) or Cmd+Shift+P(Mac) · Type Format Document With... · Then click Configure Default Formatter... and choose it from...
Read more >
Formatting problem jsx file for react - Genuitec
We were trying to reproduce this bad formatting, but were unable to do so – mostly it's only the JSX indentation that is...
Read more >
Broken JSX formatting when using Prettier as default formatter
This bug only appears when using built-in Webstorm support of Prettier, if i format file with terminal command everything works, the problem does...
Read more >
VS Code - Prettier not formatting HTML tags in JSX - Dirask
Why Prettier doesn't format HTML tags inside JSX? To open settings. json file use Ctrl + Shift + P and Search for "Open...
Read more >
Weird formatting after save in vs code - YouTube
Weird formatting after save in vs code | React Js Formatting problem. Watch later. Share. Copy link. Info. Shopping. Tap to unmute.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found