vscode-react-native icon indicating copy to clipboard operation
vscode-react-native copied to clipboard

View tag JS breaks vscode code formatting

Open mns-garethg opened this issue 9 years ago • 21 comments

Actual Behavior

  1. File save on JS files breaks the formatting :
import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";

class Footer extends Component {
    render() {
        return ( <
            View / >

        );
    }
}

export default Footer;

Expected Behavior

  1. Should be saved as:
import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";

class Footer extends Component {
    render() {
        return (
            <View />
        );
    }
}

export default Footer;

Software versions

  • React-Native VS Code extension version: 0.2.5
  • VSCode version: Version 1.8.1
  • OS platform and version: Mac OSX 10.12.2
  • NodeJS version: 6.2.0
  • React Native version: 0.40.0

mns-garethg avatar Jan 16 '17 16:01 mns-garethg

Can you please clarify: Do you mean that you wrote the code in the second snippet, but when you saved it was converted to the first? Or you wrote the first and expected save to fix the formatting?

MSLaguana avatar Jan 16 '17 19:01 MSLaguana

Hello,

I wrote it as the expected behaviour like this:

import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";

class Footer extends Component {
    render() {
        return (
            <View />
        );
    }
}

export default Footer;

But when i saved the file the formatting was like this:

import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";

class Footer extends Component {
    render() {
        return ( <
            View / >

        );
    }
}

export default Footer;

mns-garethg avatar Jan 16 '17 20:01 mns-garethg

I suspect that you may have installed JS-CSS-HTML Formatter plug-in effects, try to remove it or disable it

y2kbug avatar Jan 17 '17 06:01 y2kbug

@ggomersall, react-native extension doesn't performa any automatic code formatting - try to look for JS-CSS-HTML Formatter (or perhaps any other code formatting extension) in the list of installed extensions, as @y2kbug mentioned, and disable it to see if that solve the problem

vladimir-kotikov avatar Jan 17 '17 20:01 vladimir-kotikov

That's exactly what the issue was. I was using JS-CSS-HTML Formatter extension, deleted it and now it works fine. Thanks for the help guys

mns-garethg avatar Jan 25 '17 07:01 mns-garethg

Thank for help

buildwithdubey avatar Jun 14 '17 12:06 buildwithdubey

Thanks for the help. I was also facing the same issue.

diwakarsingh avatar Aug 25 '17 06:08 diwakarsingh

It's work. Thanks for the help. Disabled JS-CSS-HTML Formatter.

a3pelawi avatar Oct 23 '17 03:10 a3pelawi

Interesting... I uninstalled JS-CSS-HTML Formatter as suggested above, but was still getting the same behavior (which I've noticed in all the React projects I've opened in the past.) I went through and disabled all the plugins I thought could possibly matter, and it looks like the one that's still causing the issue for me is Beautify (The HookyQR one with over 1.5M downloads....) That's a bit of a pain because disabling it will probably mean none of my other Javascript files will be beautified.

bschwartz757 avatar Jan 07 '18 06:01 bschwartz757

@bschwartz757 have you found an alternative? I'm running into the same issue

IonCaza avatar Jan 11 '18 15:01 IonCaza

@IonCaza No, not yet. I haven't experimented much since posting (I don't usually work in React, just doing a tutorial) but after disabling Beautify for that workspace I still seem to get formatting ok. I would guess that's courtesy of editor configs not specific to Beautify. The plugin doesn't seem to remember that I turned it off for that workspace though so if I were to re-open a large file and hit save without remembering to disable it first I'd have to go through and manually fix everything - not exactly an ideal "developer experience" (much as I cringe at using that term.)

bschwartz757 avatar Jan 11 '18 17:01 bschwartz757

@bschwartz757 I am having the same issue. Did you find any solution? or any alternative React code formatter that does well.

neetin avatar Mar 30 '18 04:03 neetin

No sir, I apologize for the late reply... I ended up giving up on the tech stack.

On Fri, Mar 30, 2018 at 12:37 AM, Neetin Sharma [email protected] wrote:

@bschwartz757 https://github.com/bschwartz757 I am having the same issue. Did you find any solution? or any alternative React code formatter that does well.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/vscode-react-native/issues/381#issuecomment-377443195, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCAvl4HYmA-txG4MHap6VUMV7LDOjEgks5tjbaGgaJpZM4LkvlT .

IonCaza avatar Apr 09 '18 15:04 IonCaza

To solve this , search for "JS-CSS-HTML Formatter" and "Beautify" in your visual studio code extensions , if any of them is enabled , disable and uninstall them

sanyamnn avatar Apr 10 '18 13:04 sanyamnn

Try searching for prettier or beautify and disable them or any other js code formatter you have installed.

PolymathWhiz avatar Apr 04 '19 16:04 PolymathWhiz

@ggomersall, react-native extension doesn't performa any automatic code formatting - try to look for JS-CSS-HTML Formatter (or perhaps any other code formatting extension) in the list of installed extensions, as @y2kbug mentioned, and disable it to see if that solve the problem

I was having same issue and solve it using this trick thanks :)

kalpeshasuthar avatar Sep 03 '19 18:09 kalpeshasuthar

I suspect that you may have installed JS-CSS-HTML Formatter plug-in effects, try to remove it or disable it

Thank you It worked <3

Nahi3an avatar Mar 29 '20 09:03 Nahi3an

I did all the steps but could not solve

nayakakashjit avatar Jun 03 '20 19:06 nayakakashjit

thanks for helps

wntdhananjay avatar Aug 07 '20 04:08 wntdhananjay

uninstall JS-CSS-HTML Formatter , beautify or any other formatting extension. Use only Prettier

ahmedsgit avatar Aug 15 '20 09:08 ahmedsgit