Formatting: indentation of Object fields

Bug Reports and Fixes

Formatting: indentation of Object fields

Postby 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!
sksoft
 
Posts: 45
Joined: Fri Jan 04, 2008 1:36 pm

Postby 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)
eric_suen
Site Admin
 
Posts: 487
Joined: Wed Sep 28, 2005 7:00 am

Clarification

Postby 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);
sksoft
 
Posts: 45
Joined: Fri Jan 04, 2008 1:36 pm

Postby 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..."?
eric_suen
Site Admin
 
Posts: 487
Joined: Wed Sep 28, 2005 7:00 am

Postby 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).
sksoft
 
Posts: 45
Joined: Fri Jan 04, 2008 1:36 pm

Postby 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
eric_suen
Site Admin
 
Posts: 487
Joined: Wed Sep 28, 2005 7:00 am


Return to Bugs

Who is online

Users browsing this forum: No registered users and 0 guests

cron