Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Issue #1123: Make checks for generator functions without yield optional

Signed-off-by: Anton Kovalyov <anton@kovalyov.net>
  • Loading branch information...
commit 85b5b59474d278a0afa85c3a0f0ff125038fcd05 1 parent c0785c0
@qubyte qubyte authored valueof committed
Showing with 19 additions and 5 deletions.
  1. +3 −2 src/jshint.js
  2. +3 −2 src/messages.js
  3. +13 −1 tests/unit/parser.js
View
5 src/jshint.js
@@ -148,6 +148,7 @@ var JSHINT = (function () {
wsh : true, // if the Windows Scripting Host environment globals
// should be predefined
yui : true, // YUI variables should be predefined
+ noyield : true, // allow generators without a yield
// Obsolete options
onecase : true, // if one case switch statements should be allowed
@@ -2977,8 +2978,8 @@ var JSHINT = (function () {
block(false, true, true, fatarrowparams ? true : false);
- if (generator && funct["(generator)"] !== "yielded") {
- error("E047", state.tokens.curr);
+ if (!state.option.noyield && generator && funct["(generator)"] !== "yielded") {
+ warning("W124", state.tokens.curr);
}
funct["(metrics)"].verifyMaxStatementsPerFunction();
View
5 src/messages.js
@@ -62,7 +62,7 @@ var errors = {
E044: null,
E045: "Invalid for each loop.",
E046: "A yield statement shall be within a generator function (with syntax: `function*`)",
- E047: "A generator function shall contain a yield statement.",
+ E047: null, // Vacant
E048: "Let declaration not directly within block.",
E049: "A {a} cannot be named '{b}'.",
E050: "Mozilla requires the yield expression to be parenthesized here.",
@@ -194,7 +194,8 @@ var warnings = {
W120: "You might be leaking a variable ({a}) here.",
W121: "Extending prototype of native object: '{a}'.",
W122: "Invalid typeof value '{a}'",
- W123: "'{a}' is already defined in outer scope."
+ W123: "'{a}' is already defined in outer scope.",
+ W124: "A generator function shall contain a yield statement."
};
var info = {
View
14 tests/unit/parser.js
@@ -2485,6 +2485,18 @@ exports["test: esnext generator without yield"] = function (test) {
test.done();
};
+exports["test: esnext generator without yield and check turned off"] = function (test) {
+ var code = [
+ "function* emptyGenerator() {}",
+
+ "emptyGenerator();"
+ ];
+ TestRun(test)
+ .test(code, {esnext: true, noyield: true, unused: true, undef: true, predef: ["print"]});
+
+ test.done();
+};
+
exports["test: mozilla generator"] = function (test) {
// example taken from https://developer.mozilla.org/en-US/docs/JavaScript/New_in_JavaScript/1.7
var code = [
@@ -4099,4 +4111,4 @@ exports["regression test for GH-1431"] = function (test) {
.test("for (i=0; (arr[i])!=null); i++);");
test.done();
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.