Formatting: indentation of Object fields

Bug Reports and Fixes
Post Reply
sksoft
Posts: 45
Joined: Fri Jan 04, 2008 1:36 pm
Contact:

Formatting: indentation of Object fields

Post by sksoft » Wed Sep 03, 2008 5:28 pm

Incorrect formatting:

Code: Select all

var v1 = {
	a: [{
			b: 1,
			c: 2
		}, {}]
};
But without second item in array it is correct:

Code: Select all

var v2 = {
	a: [{
		b: 1,
		c: 2
	}]
};
This bug distorted formatting in most of our sources, please, fix it ASAP!

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Post by eric_suen » Thu Sep 04, 2008 2:30 am

This is because ObjectLiteral, ArrayLiteral and FunctionExpression are special, for examples, code

Code: Select all

v1 = [a, //suppose line wrap happened
  b,
  c]
, if a, c are ObjectLiteral, it will looks like

Code: Select all

v1 = [{
  f1 : 1
},
  b,
  {
    f2 : 2
  }]
compare to

Code: Select all

v1 = [{
    f1 : 1
  },
  b,
  {
    f2 : 2
  }]
or

Code: Select all

v1 = [{
  f1 : 1
},
b,
{
  f2 : 2
}]
, which should be correct? any suggestion? or you can just turn off the indention for Array(that may not help, because indention happens in lot place)

sksoft
Posts: 45
Joined: Fri Jan 04, 2008 1:36 pm
Contact:

Clarification

Post by sksoft » Thu Sep 04, 2008 8:46 am

Why adding second item (in my second sample) alters indentation of first item? Compare two definitions, v1 and v2:

Code: Select all

		v1 = [{
			f: 1
		}];
		v2 = [{
				f: 1
			}, {
				p: 2
			}];
In both cases formatting should be consistent, and should looks like this:

Code: Select all

		v2 = [{
			f: 1
		}, {
			p: 2
		}];
This style of indentation was used in all previous versions of your editor and all our sources are formatted according to it. Now you changed this rule :(
The same behaviour you may see on function parameters:

Code: Select all

		v1 = f({
			p: 1
		});
		v2 = f({
				p: 1
			}, 2);

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Post by eric_suen » Thu Sep 04, 2008 9:01 am

but it is not consistent with more common code

Code: Select all

v1 = [a, //support a, b is longer enough to cause line wrap
  b, 
  c]
Maybe I should add an options like "do not indent for ObjectLiteral..."?

sksoft
Posts: 45
Joined: Fri Jan 04, 2008 1:36 pm
Contact:

Post by sksoft » Mon Sep 08, 2008 9:12 am

I need an option to preserve old-style formatting. Until that I have to use previous version (1.6.12).

eric_suen
Site Admin
Posts: 678
Joined: Wed Sep 28, 2005 7:00 am
Contact:

Post by eric_suen » Tue Sep 09, 2008 4:01 pm

I create a quick fix, choose the "Line Wrapping" page, you can change the option "Do not indent if contains" in category:

Function Calls
- Arguments
- Object allocation arguments
Expression
- Array initializers

http://www.agpad.com/downloads/spket-up ... 6.15.2.zip

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest