bundles/org.eclipse.orion.client.javascript/web/javascript/quickFixes.js
function(editorContext, context, astManager) {
	            return astManager.getAST(editorContext).then(function(ast) {
	                var node = Finder.findNode(context.annotation.start, ast, {parents:true});
	                if(node && node.type === 'ArrayExpression') {
	                    var model = new TextModel.TextModel(ast.sourceFile.text.slice(context.annotation.start, context.annotation.end));
	                    var len = node.elements.length;
	                    var idx = len-1;
	                    var item = node.elements[idx];
	                    if(item === null) {
	                        var end = Finder.findToken(node.range[1], ast.tokens);
	                        if(end.value !== ']') {
	                            //for a follow-on token we want the previous - i.e. a token immediately following the ']' that has no space
	                            end = ast.tokens[end.index-1];
	                        }
	                        //wipe all trailing entries first using the ']' token start as the end
	                        for(; idx > -1; idx--) {
	                            item = node.elements[idx];
	                            if(item !== null) {
	                                break;
	                            }
	                        }
	                        if(item === null) {
	                            //whole array is sparse - wipe it
	                            return editorContext.setText('', context.annotation.start+1, context.annotation.end-1);
	                        }
	                        model.setText('', item.range[1]-context.annotation.start, end.range[0]-context.annotation.start);
	                    }
	                    var prev = item;
	                    for(; idx > -1; idx--) {
	                        item = node.elements[idx];
	                        if(item === null || item.range[0] === prev.range[0]) {
	                            continue;
	                        }
	                        model.setText(', ', item.range[1]-context.annotation.start, prev.range[0]-context.annotation.start); //$NON-NLS-1$
	                        prev = item;
	                    }
	                    if(item === null && prev !== null) {
	                        //need to wipe the front of the array
	                        model.setText('', node.range[0]+1-context.annotation.start, prev.range[0]-context.annotation.start);
	                    }
	                    return editorContext.setText(model.getText(), context.annotation.start, context.annotation.end);
	                }
	                return null;
	            });
	        }
function(editorContext, context, astManager) {
	            return astManager.getAST(editorContext).then(function(ast) {
	                var node = Finder.findNode(context.annotation.start, ast, {parents:true});
	                if(node && node.type === 'ArrayExpression') {
	                    var model = new TextModel.TextModel(ast.sourceFile.text.slice(context.annotation.start, context.annotation.end));
	                    var len = node.elements.length;
	                    var idx = len-1;
	                    var item = node.elements[idx];
	                    if(item === null) {
	                        var end = Finder.findToken(node.range[1], ast.tokens);
	                        if(end.value !== ']') {
	                            //for a follow-on token we want the previous - i.e. a token immediately following the ']' that has no space
	                            end = ast.tokens[end.index-1];
	                        }
	                        //wipe all trailing entries first using the ']' token start as the end
	                        for(; idx > -1; idx--) {
	                            item = node.elements[idx];
	                            if(item !== null) {
	                                break;
	                            }
	                        }
	                        if(item === null) {
	                            //whole array is sparse - wipe it
	                            return editorContext.setText('', context.annotation.start+1, context.annotation.end-1);
	                        }
	                        model.setText('', item.range[1]-context.annotation.start, end.range[0]-context.annotation.start);
	                    }
	                    var prev = item;
	                    for(; idx > -1; idx--) {
	                        item = node.elements[idx];
	                        if(item === null || item.range[0] === prev.range[0]) {
	                            continue;
	                        }
	                        model.setText(', ', item.range[1]-context.annotation.start, prev.range[0]-context.annotation.start); //$NON-NLS-1$
	                        prev = item;
	                    }
	                    if(item === null && prev !== null) {
	                        //need to wipe the front of the array
	                        model.setText('', node.range[0]+1-context.annotation.start, prev.range[0]-context.annotation.start);
	                    }
	                    return editorContext.setText(model.getText(), context.annotation.start, context.annotation.end);
	                }
	                return null;
	            });
	        }
function ( editorContext , context , astManager ) { return astManager . getAST ( editorContext ) . then ( function ( ast ) { var node = Finder . findNode ( context . annotation . start , ast , { parents : true } ) ; if ( node && node . type === 'ArrayExpression' ) { var model = new TextModel . TextModel ( ast . sourceFile . text . slice ( context . annotation . start , context . annotation . end ) ) ; var len = node . elements . length ; var idx = len - 1 ; var item = node . elements [ idx ] ; if ( item === null ) { var end = Finder . findToken ( node . range [ 1 ] , ast . tokens ) ; if ( end . value !== ']' ) { //for a follow-on token we want the previous - i.e. a token immediately following the ']' that has no space end = ast . tokens [ end . index - 1 ] ; } //wipe all trailing entries first using the ']' token start as the end for ( ; idx > - 1 ; idx -- ) { item = node . elements [ idx ] ; if ( item !== null ) { break ; } } if ( item === null ) { //whole array is sparse - wipe it return editorContext . setText ( '' , context . annotation . start + 1 , context . annotation . end - 1 ) ; } model . setText ( '' , item . range [ 1 ] - context . annotation . start , end . range [ 0 ] - context . annotation . start ) ; } var prev = item ; for ( ; idx > - 1 ; idx -- ) { item = node . elements [ idx ] ; if ( item === null || item . range [ 0 ] === prev . range [ 0 ] ) { continue ; } model . setText ( ', ' , item . range [ 1 ] - context . annotation . start , prev . range [ 0 ] - context . annotation . start ) ; //$NON-NLS-1$ prev = item ; } if ( item === null && prev !== null ) { //need to wipe the front of the array model . setText ( '' , node . range [ 0 ] + 1 - context . annotation . start , prev . range [ 0 ] - context . annotation . start ) ; } return editorContext . setText ( model . getText ( ) , context . annotation . start , context . annotation . end ) ; } return null ; } ) ; }
fix for the no-sparse-arrays linting rule
@callback
fix for the no - sparse - arrays linting rule