Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck at formating like default VS Code's formatting for JSON, JSX, JS and HTML files #2258

Open
Nefcanto opened this issue Mar 18, 2024 · 0 comments

Comments

@Nefcanto
Copy link

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/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant