Bug 268488 - Formatting a json file brings wrong output and is slow
Formatting a json file brings wrong output and is slow
Status: RESOLVED FIXED
Product: javascript
Classification: Unclassified
Component: JSON
8.2
PC Other
: P2 (vote)
: TBD
Assigned To: arusinha
issues@javascript
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2016-10-12 13:48 UTC by ChrisLE
Modified: 2017-09-12 03:35 UTC (History)
0 users

See Also:
Issue Type: DEFECT
:


Attachments
jsonFormatting problam. (171.05 KB, image/gif)
2016-10-12 13:48 UTC, ChrisLE
Details
Tabs options (126.55 KB, image/png)
2017-05-02 11:32 UTC, ChrisLE
Details
Blank lines options (122.80 KB, image/png)
2017-05-02 11:33 UTC, ChrisLE
Details
Spaces option (131.49 KB, image/png)
2017-05-02 11:33 UTC, ChrisLE
Details
Wrapping option (121.78 KB, image/png)
2017-05-02 11:34 UTC, ChrisLE
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ChrisLE 2016-10-12 13:48:49 UTC
Created attachment 162470 [details]
jsonFormatting problam.

Before I switched from 8.1 to 8.2, when I hit my shortcut to format the source inside a JSON file, which has only 2 spaces, everything was fine, it sets the spaces to 3 and did not so much other formatting stuff, if not needed. Now, as you can see in my screen capture, in NB 8.2 first it tooks very long time to format the JSON file and the format is broken as you can see. All options that I set are fine and untouched.


Cheers

Chris
Comment 1 arusinha 2017-04-11 06:15:06 UTC
Not able to reproduce the issue in NetBeans IDE 8.2 (Build 201609300101).
Formatting is happening properly.Please find below the Json file used for the test

{
    "name": "requirements.js",
    "version": "1.0.0",
    "keywords": ["util", "functional", "server", "client", "browser"],
    "description": "A fluent API for enforcing design contracts with automatic message generation.",
    "author": "Gili",
    "contributors": [
    ],
    "dependencies": {

    },
    "devDependencies": {
        "gulp": "^3.9.1"
    }
}


Request you to attach the json file where the bug is reproducible and also the steps to reproduce( if any)
Comment 2 ChrisLE 2017-05-02 11:32:08 UTC
Same NetBeans version, happens with your json example too.

See my attachments for the JSON options, which I didn't change after updating from 8.1 to 8.2
Comment 3 ChrisLE 2017-05-02 11:32:46 UTC
Created attachment 164219 [details]
Tabs options
Comment 4 ChrisLE 2017-05-02 11:33:25 UTC
Created attachment 164220 [details]
Blank lines options
Comment 5 ChrisLE 2017-05-02 11:33:51 UTC
Created attachment 164221 [details]
Spaces option
Comment 6 ChrisLE 2017-05-02 11:34:14 UTC
Created attachment 164222 [details]
Wrapping option
Comment 7 Reema 2017-05-05 12:07:57 UTC
Hi, Is the issue related to wrapping of Array items and Objects properties, i.e. with below wrapping option set to Always for all options, Source: Format changes json

{
    "name": "requirements.js",
    "version": "1.0.0",
    "keywords": ["util", "functional", "server", "client", "browser"],
    "description": "A fluent API for enforcing design contracts with automatic message generation.",
    "author": "Gili",
    "contributors": [
    ],
    "dependencies": {"util": "ss", "functional": "ss"},
    "devDependencies": {
        "gulp": "^3.9.1"
    }
}

to 

{
    "name": "requirements.js",
    "version": "1.0.0",
    "keywords": [
        "util",
        "functional",
        "server",
        "client",
        "browser"
    ],
    "description": "A fluent API for enforcing design contracts with automatic message generation.",
    "author": "Gili",
    "contributors": [
    ],
    "dependencies": {
        "util": "ss",
        "functional": "ss"
    },
    "devDependencies": {
        "gulp": "^3.9.1"
    }
}


This behavior seems to correct. As seen in the Tools: Options: Formatting: Preview, with Wrapping set to Always, the Object properties and Array items are added in new lines. Can you try change the respective wrapping option to Never in this case.
Comment 8 ChrisLE 2017-06-15 08:44:16 UTC
I know, that I didn't change it for months. But ok I tried it and set everything to never. Same problem here. This is package.json:

https://pastebin.com/R59gKdPv

as you can see, that the spaces are 2 and I expect 4. So when I change it to Never and have 4 (which is default for all my languages) the code looks like this again:

https://pastebin.com/tVLs14cM

and it has still 2 spaces for the indentation.
Comment 9 ChrisLE 2017-06-15 08:46:08 UTC
I think I figured it out, the problem only happens with package.json and bower.json. When I reformat a locale file or a new created file named Tester.json, with the same data from the last comment, everything is fine.
Comment 10 Quality Engineering 2017-07-20 17:51:31 UTC
Integrated into 'main-silver', will be available in build *201707201608* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/21a82d4d570f
User: Arusinha <arusinha@netbeans.org>
Log: #268488 : Fixing formatting for bower.json and package.json files


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo