JSX Formatting Breaks
See original GitHub issueWhen 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:
- Created 5 years ago
- Reactions:5
- Comments:9 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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!This may be an other formatter taking precedence. see #440 #439