jiangmiao / simple-javascript-indenter

A vim javascript indent script
http://www.vim.org/scripts/script.php?script_id=3227
72 stars 8 forks source link

Multiline Indent, trailing comma offset #14

Closed ghost closed 11 years ago

ghost commented 11 years ago

I think this indentation plugin works great for JavaScript. Great work! I have noticed a few minor indentation problems:

// unexpected non-indent of variables after first object
var con = {
    prop: 5,
    madness: 7
},
list = [],
hash = {};
// expected multi-line indent
var con = {prop: 5, madness: 7},
    list = [],
    hash = {};
$(function(){
        // trailing comma after the last property value throws off indent
        // (it really shouldn't be there but I cannot change every legacy...)
        $('body').css({ 
                position:'absolute',
                top:'50px',
                left:'60px',
                height:'auto',
                width:'auto',
        });

        });
jiangmiao commented 11 years ago

Both of those case is hard to fixed. because script only can calculate the indentation for serveral continous lines nearby. eg: end with , then the line is continous.

for case

var con = {
    prop: 5,
    madness: 7
},
list = [],
hash = {};

assign to complex expression, script cannot know where we have left the block.

for second case, It's incompatible expression in IE, so I prefer to keep it let us know we have input an incompatible expression.

ghost commented 11 years ago

I understand. The first part is not a big issue. I might try tweaking the first case when I get a chance.