Skip to content

Commit

Permalink
Removes a bad advise by JSHint to remove unnecessary semicolons.
Browse files Browse the repository at this point in the history
Fixes GH-344
  • Loading branch information
goatslacker authored and valueof committed Dec 9, 2011
1 parent 96ea5c5 commit 4274cb1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
7 changes: 2 additions & 5 deletions jshint.js
Original file line number Diff line number Diff line change
Expand Up @@ -2343,11 +2343,8 @@ loop: for (;;) {
function statement(noindent) {
var i = indent, r, s = scope, t = nexttoken;

// We don't like the empty statement.

if (t.id === ';') {
warning("Unnecessary semicolon.", t);
advance(';');
if (t.id === ";") {
advance(";");
return;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,20 @@ exports.testRawOnError = function () {
assert.equal(JSHINT.errors[1].raw, 'Too many errors.');
assert.equal(JSHINT.errors[2], null);
};

exports.yesEmptyStmt = function () {
var src = fs.readFileSync(__dirname + '/fixtures/emptystmt.js', 'utf8');

TestRun()
.addError(1, "Expected an identifier and instead saw ';'.")
.addError(6, "Expected an assignment or function call and instead saw an expression.")
.addError(10, "Unnecessary semicolon.")
.addError(17, "Unnecessary semicolon.")
.test(src, { curly: false });

TestRun()
.addError(1, "Expected an identifier and instead saw ';'.")
.addError(10, "Unnecessary semicolon.")
.addError(17, "Unnecessary semicolon.")
.test(src, { curly: false, expr: true });
};
23 changes: 23 additions & 0 deletions tests/fixtures/emptystmt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var;

var i = 0;
while (++i < 10);

foo;

function foo() {
return;
};

if (true);

for (var i = 0; i < 10; i += 1);

for (var i = 0; i < 10; i += 1) {
foo();;
break;
}

for (var i = 0; i < 10; i += 1) {
continue;
}

0 comments on commit 4274cb1

Please sign in to comment.