From 7c7a771b387c81635b15b3337938e46d887726dd Mon Sep 17 00:00:00 2001 From: Anton Kovalyov Date: Wed, 19 Jan 2011 02:08:13 -0800 Subject: [PATCH] Added a new option--oneline--to allow one-line for, if and while blocks --- fulljslint.html | 10 ++++++++-- fulljslint.js | 15 +++++++++------ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/fulljslint.html b/fulljslint.html index 4950273b2..9a1b6eb39 100755 --- a/fulljslint.html +++ b/fulljslint.html @@ -119,10 +119,14 @@ Enjoy The Good Parts.

---> + + + +
@@ -221,6 +225,8 @@
+
+
diff --git a/fulljslint.js b/fulljslint.js index 3fde890aa..37c3b2f06 100755 --- a/fulljslint.js +++ b/fulljslint.js @@ -335,6 +335,7 @@ var JSLINT = (function () { nomen : true, // if names should be checked on : true, // if HTML event handlers should be allowed onevar : true, // if only one var statement per function should be allowed + oneline : true, // if one-line blocks should be allowed passfail : true, // if the scan should stop on first error plusplus : true, // if increment/decrement should not be allowed regexp : true, // if the . should not be allowed in regexp literals @@ -2693,7 +2694,7 @@ loop: for (;;) { } - function block(ordinary) { + function block(ordinary, oneline) { // A block is a sequence of statements wrapped in braces. // ordinary is false for function bodies and try blocks. @@ -2721,8 +2722,10 @@ loop: for (;;) { error("Expected '{a}' and instead saw '{b}'.", nexttoken, '{', nexttoken.value); } else { - warning("Expected '{a}' and instead saw '{b}'.", - nexttoken, '{', nexttoken.value); + if (!oneline) + warning("Expected '{a}' and instead saw '{b}'.", + nexttoken, '{', nexttoken.value); + a = [statement()]; if (a[0].disrupt) { a.disrupt = true; @@ -3608,7 +3611,7 @@ loop: for (;;) { no_space(); advance(')', t); one_space_only(); - this.block = block(true); + this.block = block(true, option.oneline); if (nexttoken.id === 'else') { one_space(); advance('else'); @@ -3691,7 +3694,7 @@ loop: for (;;) { no_space(); advance(')', t); one_space_only(); - this.block = block(true); + this.block = block(true, option.oneline); if (this.block.disrupt) { warning("Strange loop.", prevtoken); } @@ -3879,7 +3882,7 @@ loop: for (;;) { no_space(); advance(')', t); one_space_only(); - s = block(true); + s = block(true, option.oneline); } if (s.disrupt) { warning("Strange loop.", prevtoken);