From f22d7aabb5b9cb0276baee9e26e7f96b228c0f79 Mon Sep 17 00:00:00 2001 From: David Majda Date: Sat, 14 Dec 2013 21:26:25 +0100 Subject: [PATCH] Fix JSHint errors in bin/pegjs Fixes the following JSHint errors: bin/pegjs: line 66, col 14, 'extraOptions' used out of scope. bin/pegjs: line 70, col 19, 'extraOptions' used out of scope. bin/pegjs: line 71, col 20, 'extraOptions' used out of scope. bin/pegjs: line 80, col 10, Wrap the /regexp/ literal in parens to disambiguate the slash operator. bin/pegjs: line 128, col 43, Missing semicolon. bin/pegjs: line 128, col 45, Don't make functions within a loop. bin/pegjs: line 150, col 13, Redefinition of 'module'. bin/pegjs: line 217, col 34, Expected '===' and instead saw '=='. bin/pegjs: line 243, col 44, 'source' used out of scope. bin/pegjs: line 243, col 61, 'source' used out of scope. --- bin/pegjs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/bin/pegjs b/bin/pegjs index 8d76fbe..3275d22 100755 --- a/bin/pegjs +++ b/bin/pegjs @@ -56,8 +56,10 @@ function abort(message) { } function addExtraOptions(options, json) { + var extraOptions; + try { - var extraOptions = JSON.parse(json); + extraOptions = JSON.parse(json); } catch (e) { if (!(e instanceof SyntaxError)) { throw e; } @@ -72,12 +74,20 @@ function addExtraOptions(options, json) { } } +/* + * Extracted into a function just to silence JSHint complaining about creating + * functions in a loop. + */ +function trim(s) { + return s.trim(); +} + /* Arguments */ var args = process.argv.slice(2); // Trim "node" and the script path. function isOption(arg) { - return /^-/.test(arg); + return (/^-/).test(arg); } function nextArg() { @@ -125,7 +135,7 @@ while (args.length > 0 && isOption(args[0])) { } options.allowedStartRules = args[0] .split(",") - .map(function(s) { return s.trim() }); + .map(trim); break; case "-o": @@ -146,14 +156,15 @@ while (args.length > 0 && isOption(args[0])) { abort("Missing parameter of the --plugin option."); } var id = /^(\.\/|\.\.\/)/.test(args[0]) ? path.resolve(args[0]) : args[0]; + var mod; try { - var module = require(id); + mod = require(id); } catch (e) { if (e.code !== "MODULE_NOT_FOUND") { throw e; } abort("Can't load module \"" + id + "\"."); } - options.plugins.push(module); + options.plugins.push(mod); break; case "--extra-options": @@ -214,7 +225,7 @@ switch (args.length) { abort("Can't read from file \"" + inputFile + "\"."); }); - var outputFile = args.length == 1 + var outputFile = args.length === 1 ? args[0].replace(/\.[^.]*$/, ".js") : args[1]; var outputStream = fs.createWriteStream(outputFile); @@ -229,8 +240,10 @@ switch (args.length) { } readStream(inputStream, function(input) { + var source; + try { - var source = PEG.buildParser(input, options); + source = PEG.buildParser(input, options); } catch (e) { if (e.line !== undefined && e.column !== undefined) { abort(e.line + ":" + e.column + ": " + e.message);