Stuck at formating like default VS Code's formatting for JSON, JSX, JS and HTML files
Nefcanto opened this issue · 0 comments
Nefcanto commented
Description
I want to format my codes similarly to the default VS Code (without any extensions installed). I can't. There are some minute differences that prevent me from automating formatting.
Input
The code looked like this before beautification:
{
"name":"Recipes",
"entityTypes":[
{"name":"Recipes",
"hasGuid":true,
"hasTitle":true,
"properties":[
{
"name":"Title",
"type": "nvarchar"
},
{
"name":"PreparationTimeInMinutes",
"type":"int",
"nullable": true
},
{
"name":"CookingTimeInMinutes",
"type":"int",
"nullable": true
},
{
"name":"TotalTimeInMinutes",
"type":"int",
"nullable": true
},
{
"name":"Servings",
"type":"int",
"nullable": true
},
{
"name":"Calories",
"type":"decimal",
"nullable": true
},
{
"name":"RatingAverage",
"type":"decimal",
"nullable": true
},
{
"name":"RatingCount",
"type":"decimal",
"nullable": true
},
{
"name":"Difficulty",
"type":"decimal",
"nullable": true
},
{
"name":"IngredientsCount",
"type":"int",
"nullable": true
},
{
"name":"DirectionsCount",
"type":"int",
"nullable": true
},
{
"name":"MadeCount",
"type":"int",
"nullable": true
},
{
"name":"ReviewsCount",
"type":"int",
"nullable": true
},
{
"name":"PhotosCount",
"type":"int",
"nullable": true
},
{
"name":"CategoryTokensCsv",
"type":"varchar",
"nullable": true
}
]
}
]
}
Expected Output
The code should have looked like this after beautification:
{
"name": "Recipes",
"entityTypes": [
{
"name": "Recipes",
"hasGuid": true,
"hasTitle": true,
"properties": [
{
"name": "Title",
"type": "nvarchar"
},
{
"name": "PreparationTimeInMinutes",
"type": "int",
"nullable": true
},
{
"name": "CookingTimeInMinutes",
"type": "int",
"nullable": true
},
{
"name": "TotalTimeInMinutes",
"type": "int",
"nullable": true
},
{
"name": "Servings",
"type": "int",
"nullable": true
},
{
"name": "Calories",
"type": "decimal",
"nullable": true
},
{
"name": "RatingAverage",
"type": "decimal",
"nullable": true
},
{
"name": "RatingCount",
"type": "decimal",
"nullable": true
},
{
"name": "Difficulty",
"type": "decimal",
"nullable": true
},
{
"name": "IngredientsCount",
"type": "int",
"nullable": true
},
{
"name": "DirectionsCount",
"type": "int",
"nullable": true
},
{
"name": "MadeCount",
"type": "int",
"nullable": true
},
{
"name": "ReviewsCount",
"type": "int",
"nullable": true
},
{
"name": "PhotosCount",
"type": "int",
"nullable": true
},
{
"name": "CategoryTokensCsv",
"type": "varchar",
"nullable": true
}
]
}
]
}
Actual Output
The code actually looked like this after beautification:
{
"name": "Recipes",
"entityTypes": [
{
"name": "Recipes",
"hasGuid": true,
"hasTitle": true,
"properties": [
{
"name": "Title",
"type": "nvarchar"
},
{
"name": "PreparationTimeInMinutes",
"type": "int",
"nullable": true
},
{
"name": "CookingTimeInMinutes",
"type": "int",
"nullable": true
},
{
"name": "TotalTimeInMinutes",
"type": "int",
"nullable": true
},
{
"name": "Servings",
"type": "int",
"nullable": true
},
{
"name": "Calories",
"type": "decimal",
"nullable": true
},
{
"name": "RatingAverage",
"type": "decimal",
"nullable": true
},
{
"name": "RatingCount",
"type": "decimal",
"nullable": true
},
{
"name": "Difficulty",
"type": "decimal",
"nullable": true
},
{
"name": "IngredientsCount",
"type": "int",
"nullable": true
},
{
"name": "DirectionsCount",
"type": "int",
"nullable": true
},
{
"name": "MadeCount",
"type": "int",
"nullable": true
},
{
"name": "ReviewsCount",
"type": "int",
"nullable": true
},
{
"name": "PhotosCount",
"type": "int",
"nullable": true
},
{
"name": "CategoryTokensCsv",
"type": "varchar",
"nullable": true
}]
}]
}
Steps to Reproduce
Run this command for that code:
js-beautify --brace-style expand --end-with-newline /path/to/json
Environment
OS:
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"