Visual Studio 2008 SP1 Adds JavaScript Formatting

Just a "two thumbs up" for the addition of JavaScript™/JScript® formatting in Visual Studio 2008 Service Pack 1. I don't like leaving messy-looking code - especially since JavaScript makes the trip all the way to the client.

My formatting preference is to show opening and closing braces on a new line, so here's what you need to do in VS 2008:

  1. From the Tools menu, click Options.
  2. In the Options dialogue box, check Show All Settings in the bottom left corner. (BTW, it makes no sense for Microsoft to hide so many excellent tools.)
  3. Expand the Text Editor node, expand JScript and select Formatting.
  4. In the New Lines group box, check both Place Open Brace On New Line For Functions and Place Open Brace On New Line For Control Blocks.
  5. Click OK to close the Options dialogue box.
  6. In a .js page, press Ctrl+K, Ctrl+D (or, From the Edit menu, click Format Document).

This is one of those productivity improvements that makes the IDE indispensable.

Ken

Published 13 August 2008 08:24 PM by Ken Cox [MVP]

Comments

# BrookeVigola said on 13 August, 2008 11:09 PM

I'd rather put it in a library and compact it. I'd rather not download your indentation and line returns Thank You.

# Dominic Pettifer said on 14 August, 2008 05:12 AM

Weren't they going to add Javascript Intellisence for various Javascript frameworks like JQuery? If they have, how do I enable it? I can't seem to get it work.

# Khurram Aziz said on 14 August, 2008 06:51 AM

Soma announced the availability of Visual Studio 2008 Service Pack 1 and .NET 3.5 Service Pack 1 . Installation

# WebLog of Ken Cox said on 14 August, 2008 01:23 PM

To get JavaScript IntelliSense working in VS 2008 SP1, you need to tell IntelliSense the location of

# Ken Cox [MVP] said on 14 August, 2008 02:07 PM

@Dominic: See this post for enabling JavaScript IntelliSense:

weblogs.asp.net/.../enabling-javascript-intellisense-in-external-libraries.aspx

Ken

# Edward Ng said on 18 August, 2008 10:46 PM

The VS2008 SP1 JScript formatter sucks !

# DarrenFieldhouse said on 07 October, 2008 03:16 PM

Despite the negative comments I think the formatting is great, although the default of open braces on the same line was annoying me until I found this post! Thanks.

# Melwin said on 08 November, 2009 02:49 AM

Javascript formatting was driving me crazy, until I did some search and found this post. Thanks a lot!

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Search

Go

This Blog

Web Links

Syndication