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.

JSX Formatting Breaks

See original GitHub issue

When I use Format Document command in VSCode with prettier-vscode, the formatting of my JSX file breaks.

It looks like prettier-vscode is not reading my configuration also.

P.S. When I try the command-line version of the prettier tool, the output is correct.

VSCode version - 1.23.0 prettier-vscode version - 1.3.1 OS - Linux Mint 18.3 Cinnamon 64-bit (Kernel - 4.13.0-39-generic)

Original File: HelloButton.jsx

const { Component } = require('react')

class HelloButton extends Component {
  render() {
    const {
      caption,
      className
    } = this.props

    return (<button className={className}>{caption}</button>)
  }
}

module.exports = HelloButton

After Formatting: HelloButton.jsx

const {
  Component
} = require('react')

class HelloButton extends Component {
  render() {
    const {
      caption,
      className
    } = this.props

    return ( < button className = {
        className
      } > {
        caption
      } < /button>)
    }
  }

  module.exports = HelloButton

.prettierrc

{
  "printWidth": 120,
  "semi": false,
  "singleQuote": true,
  "trailingComma": "all",
  "bracketSpacing": false,
  "jsxBracketSameLine": true,
  "arrowParens": "avoid",
  "insertPragma": true,
  "tabWidth": 2,
  "useTabs": false
}

package.json

{
  "name": "web-client",
  "version": "1.0.0",
  "description": "Web Client",
  "main": "index.js",
  "author": "codematix@codematix.me",
  "license": "SEE LICENSE IN LICENSE",
  "private": true,
  "scripts": {
    "build": "webpack --mode=development --env=development",
    "build:prod": "webpack --mode=production --env=production -p",
    "start": "webpack-dev-server --mode=development --env=development --content-base=public"
  },
  "babel": {
    "presets": [
      "env",
      "react"
    ],
    "plugins": [
      "react-require"
    ]
  },
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-plugin-react-require": "^3.0.0",
    "babel-preset-env": "^1.6.1",
    "babel-preset-react": "^6.24.1",
    "clean-webpack-plugin": "^0.1.19",
    "copy-webpack-plugin": "^4.5.1",
    "cpy-cli": "^1.0.1",
    "css-loader": "^0.28.11",
    "extract-text-webpack-plugin": "^4.0.0-beta.0",
    "file-loader": "^1.1.11",
    "node-sass": "^4.9.0",
    "prettier": "^1.12.1",
    "sass-loader": "^7.0.1",
    "style-loader": "^0.21.0",
    "url-loader": "^1.0.1",
    "webpack": "^4.7.0",
    "webpack-cli": "^2.1.2",
    "webpack-dev-server": "^3.1.4"
  },
  "dependencies": {
    "normalize-scss": "^7.0.1",
    "react": "^16.3.2",
    "react-dom": "^16.3.2"
  }
}

Output from prettier CLI

yarn run prettier src/js/components/HelloButton.jsx
yarn run v1.6.0
$ /home/codematix/Projects/cadencebox/web-client/node_modules/.bin/prettier src/js/components/HelloButton.jsx
/** @format */

const { Component } = require('react')

class HelloButton extends Component {
  render() {
    const { caption, className } = this.props

    return <button className={className}>{caption}</button>
  }
}

module.exports = HelloButton
Done in 0.27s.

Issue Analytics

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

github_iconTop GitHub Comments

116reactions
codematixcommented, May 9, 2018

@CiGit You are right-on. It was VS Code Beautify. I uninstalled it and restarted VSCode and now prettier-vscode runs great! Thanks a lot!

39reactions
CiGitcommented, May 9, 2018

This may be an other formatter taking precedence. see #440 #439

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 >
Broken JSX formatting when using Prettier as default formatter
Sometimes I experience very annoying prettier behavior(of formatting React, JSX), which is shown in the attached screenshots.
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 >
Weird formatting after save in vs code | React Js ... - YouTube
How to solve the formatting problem in vs code? ... Weird formatting after save in vs code | React Js Formatting problem.
Read more >
Make line breaks work when you render text in a React or Vue ...
Make line breaks work when you render text in a React or Vue component · Replace \n with <br /> · Use CSS...
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