Page 1 of 1

Formatting: indentation of Object fields

Posted: Wed Sep 03, 2008 5:28 pm
by sksoft
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!

Posted: Thu Sep 04, 2008 2:30 am
by eric_suen
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)

Clarification

Posted: Thu Sep 04, 2008 8:46 am
by sksoft
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);

Posted: Thu Sep 04, 2008 9:01 am
by eric_suen
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..."?

Posted: Mon Sep 08, 2008 9:12 am
by sksoft
I need an option to preserve old-style formatting. Until that I have to use previous version (1.6.12).

Posted: Tue Sep 09, 2008 4:01 pm
by eric_suen
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