This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 269417 - Code-format makes package.json unreadable
Summary: Code-format makes package.json unreadable
Status: REOPENED
Alias: None
Product: javascript
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 8.2
Hardware: PC Windows 10 x64
: P2 normal (vote)
Assignee: arusinha
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-23 03:34 UTC by _ gtzabari
Modified: 2017-11-24 05:43 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ gtzabari 2016-12-23 03:34:57 UTC
Product Version: NetBeans IDE Dev (Build 201612200001)
Java: 1.8.0_112; Java HotSpot(TM) 64-Bit Server VM 25.112-b15
Runtime: Java(TM) SE Runtime Environment 1.8.0_112-b15
System: Windows 10 version 10.0 running on amd64; Cp1252; en_CA (nb)
User directory: C:\Users\Gili\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\Gili\AppData\Local\NetBeans\Cache\dev

Netbeans 8.2 also experiences the same bug.

1. When I apply code-format on the following package.json it leaves the file unchanged:

{
	"name": "requirements.js",
	"version": "1.0.0",
	"keywords": ["util", "functional", "server", "client", "browser"],
	"author": "Gili",
	"contributors": [],
	"dependencies": {}
}

2. If I insert:

  "description": "test",

between "keywords" and "author", code-format removes all newlines and results in the following formatting:

{
	"name": "requirements.js", "version": "1.0.0", "keywords": ["util", "functional", "server", "client", "browser"], "description": "test.", "author": "Gili", "contributors": [], "dependencies": {}
}


3. If I place #2 in foo.json (anything JSON file that is not named packages.json) it formats fine.

This issue is reproducible 100% of the time.
Comment 1 _ gtzabari 2016-12-23 03:39:15 UTC
I just noticed that if I hit SHIFT+ALT+F (code-format) over and over again, the code alternates from formatting all the text on a single line (bug) to proper formatting.

So it looks like Netbeans *does* know how to format the code properly, but code-format is broken every second time it is run.

If you have "On save -> Code-format" enabled, Netbeans will always save the file in the wrong format so this functionality is unusable.
Comment 2 _ gtzabari 2016-12-23 03:42:23 UTC
If you change package.json 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": {

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

then it never formats correctly, no matter how many times it is invoked. All the text before "dependencies" is missing newlines. Everything from "dependencies" onward seems to be fine.
Comment 3 arusinha 2017-03-24 04:33:08 UTC
Code formatting(alt+Shft+F) is happening properly in .json files. 
Tested in NetBeans IDE Dev (Build 20170315-aebe3408a1cd)
Closing the bug as it is non existent now
Comment 4 emerino 2017-11-24 05:40:45 UTC
Hello, I'm reopening this bug since it still happens with netbeans 8.2. It is not that netbeans doesn't know how to properly format JSON text, but specifically with package.json files if you include "description" it will not format it accordingly.

I've tested with other json files, including "description" as a key has no effect, but very oddly it does with package.json files, perhaps netbeans is doing something with this file that prevents correct formatting?
Comment 5 _ gtzabari 2017-11-24 05:43:23 UTC
emerino,

Please try the latest nightly build. If the bug is fixed there, please close this issue as RESOLVED - FIXED.