Skip to content

Commit

Permalink
Added a new option--oneline--to allow one-line for, if and while blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
valueof committed Jan 19, 2011
1 parent 40e3f73 commit 7c7a771
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 8 additions & 2 deletions fulljslint.html
Expand Up @@ -119,10 +119,14 @@
<a href="http://www.amazon.com/exec/obidos/ASIN/0596517742/wrrrldwideweb"
target="_blank">Enjoy <i>The Good Parts</i>.</a></p>
</td></tr></table>
<script src="fullwebjslint.js">
<!--<script src="fullwebjslint.js">
// fullwebjslint.js is the concatenation of
// json2.js + fulljslint.js + adsafe.js + intercept.js
</script>
</script>-->

<script src="fulljslint.js"></script>
<script src="adsafe.js"></script>
<script src="intercept.js"></script>


<div id="JSLINT_">
Expand Down Expand Up @@ -221,6 +225,8 @@
<input type="checkbox" id="JSLINT_FRAGMENT" title="fragment"><label for="JSLINT_FRAGMENT" title="fragment">Tolerate <tt>HTML</tt> fragments</label>
<br>
<input type="checkbox" id="JSLINT_ESV" title="es5"><label for="JSLINT_ESV" title="es5">Tolerate ES5 syntax</label>
<br>
<input type="checkbox" id="JSLINT_ONELINE" title="oneline"><label for="JSLINT_ONELINE" title="oneline">Tolerate one-line blocks</label>
</div>
<div class="leftcolumn">
<input type="button" id="JSLINT_GOODPARTS" value="The Good Parts">
Expand Down
15 changes: 9 additions & 6 deletions fulljslint.js
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7c7a771

Please sign in to comment.