I am using the visual studio JSLint plugin to keep my javascript in order, which seems to work really well apart from this one problem.
If I type in
x = (function () {
}())
And then put the semicolon on the end, Visual studio corrects it to:
x = (function () {
} ());
And then JSLint complains JS Lint: Unexpect开发者_StackOverflow中文版ed space between '}' and '('.
Obviously this is fixable by removing the space, but visual studio is very persistent in putting the space back. Putting a semicolon anywhere inside the function, which is most of the file, will cause VS to put the space back. This is starting to get annoying.
I've tried mucking about with the visual studio Javascript editor settings ('insert space after...'), but can't seem to stop it doing this.
Another way this could be expressed is
x = (function () {
})();
Which VS leaves alone, but JSLint says JS Lint: Move the invocation into the parens that contain the function.
So no dice there.
Any suggestions? I know I can turn bits of JSLint off, even just around this last line of the file, but that's going to look messy, I'd like to do a bit better.
UPDATED ANSWER FOR VS 2013:
In VS 2013, we seem to have more control. Go to Tools > Options window, then under Text Editor > Javascript > Formatting > Spacing you can deselect the second-to-last option that says "Insert space after function keyword for anonymous functions."
I had a pic but I can't post it :).
First of all you can make Visual Studio not so persistent if you switch off some default settings:
Another way is to follow not so exact the formatting rules of JSlint. You can just include
/*jslint white: true */
to switch off the white space formatting rule.
I don't have a better response than turning off whitespace formatting rule checking, but this is very unfortunate. As far as I can tell, this one situation described here is the only case were visual studio automatic formatting and jslint collide in a way you can't reasonable config your way out of.
Losing the entire whitespace checking for this source file, or losing the auto reformatting of the rest of your JavaScript, are both somewhat sledgehammer approaches to this problem. I'd love to see another creative option if anyone has one.
精彩评论