From 7184bc5fa5a49273335b1b89f5cdfea3cb2afce2 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 9 Dec 2011 16:34:02 +0000 Subject: [PATCH] Lots of JSHint induced tweaks Still not spotless --- js/ArgParser.js | 6 +++--- js/FileRetriever.js | 2 +- js/Recipe.js | 4 ++-- js/Tiddler.js | 2 +- js/TiddlerInput.js | 8 ++++---- js/TiddlerOutput.js | 2 +- js/Utils.js | 6 +++--- js/WikiStore.js | 2 +- js/WikiTextMacros.js | 8 ++++---- js/WikiTextParser.js | 7 ++++--- js/WikiTextRules.js | 4 ++-- readme.md | 4 ++-- test.sh | 11 +++++++++-- tiddlywiki.js | 13 ++++++------- wikitest.js | 2 ++ 15 files changed, 45 insertions(+), 36 deletions(-) diff --git a/js/ArgParser.js b/js/ArgParser.js index c59f16c13..f3cfae735 100755 --- a/js/ArgParser.js +++ b/js/ArgParser.js @@ -17,7 +17,7 @@ Options and their defaults are: */ -/*global require: false, exports: false */ +/*jslint node: true */ "use strict"; var ArgParser = function(argString,options) { @@ -56,10 +56,10 @@ var ArgParser = function(argString,options) { this.byPos.push({n:"", v:n}); } else { v = parseToken(match,8); - if(v == null && options.defaultName) { + if(v === undefined && options.defaultName) { v = n; n = options.defaultName; - } else if(v == null && options.defaultValue) { + } else if(v === undefined && options.defaultValue) { v = options.defaultValue; } this.byPos.push({n:n, v:v}); diff --git a/js/FileRetriever.js b/js/FileRetriever.js index 46a21c298..17847fc70 100644 --- a/js/FileRetriever.js +++ b/js/FileRetriever.js @@ -3,7 +3,7 @@ FileRetriever can asynchronously retrieve files from HTTP URLs or the local file throttling so that we don't get error EMFILE "Too many open files". */ -/*global require: false, exports: false */ +/*jslint node: true */ "use strict"; var fs = require("fs"), diff --git a/js/Recipe.js b/js/Recipe.js index 5e325692e..7a521729e 100755 --- a/js/Recipe.js +++ b/js/Recipe.js @@ -46,7 +46,7 @@ At this point tiddlers are placed in the store so that they can be referenced by */ -/*global require: false, exports: false, process: false */ +/*jslint node: true */ "use strict"; var Tiddler = require("./Tiddler.js").Tiddler, @@ -347,7 +347,7 @@ Recipe.prototype.cookRss = function() s.push(""); // Save it all return s.join("\n"); -} +}; exports.Recipe = Recipe; diff --git a/js/Tiddler.js b/js/Tiddler.js index 399def2a7..57d144d8a 100755 --- a/js/Tiddler.js +++ b/js/Tiddler.js @@ -33,7 +33,7 @@ as a TiddlyWiki quoted string (eg, "one [[two three]]"). */ -/*global require: false, exports: false */ +/*jslint node: true */ "use strict"; var utils = require("./Utils.js"), diff --git a/js/TiddlerInput.js b/js/TiddlerInput.js index c684f9fa7..d409be702 100755 --- a/js/TiddlerInput.js +++ b/js/TiddlerInput.js @@ -2,7 +2,7 @@ Functions concerned with parsing representations of tiddlers */ -/*global require: false, exports: false */ +/*jslint node: true */ "use strict"; var utils = require("./Utils.js"), @@ -91,9 +91,9 @@ tiddlerInput.parseTiddlerFileByMimeType = { var match = endOfDivRegExp.exec(text); while(match && startPos < storeAreaPos[1]) { var endPos = endOfDivRegExp.lastIndex, - fields = tiddlerInput.parseTiddlerDiv(text.substring(startPos,endPos)); - fields.text = utils.htmlDecode(fields.text); - results.push(fields); + tiddlerFields = tiddlerInput.parseTiddlerDiv(text.substring(startPos,endPos),fields); + tiddlerFields.text = utils.htmlDecode(tiddlerFields.text); + results.push(tiddlerFields); startPos = endPos; match = endOfDivRegExp.exec(text); } diff --git a/js/TiddlerOutput.js b/js/TiddlerOutput.js index c8918e9c1..2688650ad 100755 --- a/js/TiddlerOutput.js +++ b/js/TiddlerOutput.js @@ -2,7 +2,7 @@ Functions concerned with parsing representations of tiddlers */ -/*global require: false, exports: false */ +/*jslint node: true */ "use strict"; var utils = require("./Utils.js"); diff --git a/js/Utils.js b/js/Utils.js index 4ef6647cd..8743ab2a3 100755 --- a/js/Utils.js +++ b/js/Utils.js @@ -4,7 +4,7 @@ Various static utility functions. This file is a bit of a dumping ground; the expectation is that most of these functions will be refactored. */ -/*global require: false, exports: false, process: false */ +/*jslint node: true */ "use strict"; var utils = exports; @@ -131,7 +131,7 @@ utils.getDaySuffix = function(date) { utils.getWeek = function(date) { var dt = new Date(date.getTime()); var d = dt.getDay(); - if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7 + if(d === 0) d=7;// JavaScript Sun=0, ISO Sun=7 dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week to calculate weekNo var n = Math.floor((dt.getTime()-new Date(dt.getFullYear(),0,1)+3600000)/86400000); return Math.floor(n/7)+1; @@ -140,7 +140,7 @@ utils.getWeek = function(date) { utils.getYearForWeekNo = function(date) { var dt = new Date(date.getTime()); var d = dt.getDay(); - if(d==0) d=7;// JavaScript Sun=0, ISO Sun=7 + if(d === 0) d=7;// JavaScript Sun=0, ISO Sun=7 dt.setTime(dt.getTime()+(4-d)*86400000);// shift day to Thurs of same week return dt.getFullYear(); }; diff --git a/js/WikiStore.js b/js/WikiStore.js index 80b289ae3..d50e3979c 100755 --- a/js/WikiStore.js +++ b/js/WikiStore.js @@ -1,4 +1,4 @@ -/*global require: false, exports: false, console: false */ +/*jslint node: true */ "use strict"; var Tiddler = require("./Tiddler.js").Tiddler, diff --git a/js/WikiTextMacros.js b/js/WikiTextMacros.js index 489b574d6..6ae7822f3 100644 --- a/js/WikiTextMacros.js +++ b/js/WikiTextMacros.js @@ -2,8 +2,7 @@ Wiki text macro implementation */ - -/*global require: false, exports: false */ +/*jslint node: true */ "use strict"; var ArgParser = require("./ArgParser.js").ArgParser, @@ -74,13 +73,14 @@ wikiTextMacros.macros = { var args = new ArgParser(macroNode.params,{defaultName:"name"}), targetTitle = args.getValueByName("name",null), withTokens = args.getValuesByName("with",[]), - text = store.getTiddlerText(targetTitle,""); + text = store.getTiddlerText(targetTitle,""), + t; for(t=0; t"); } }; - var renderSubTree = function(tree) { + renderSubTree = function(tree) { for(var t=0; t tmp/newcooked.html || exit 1 +mkdir -p tmp/newcooked +node tiddlywiki.js --recipe $PWD/test/tiddlywiki.2.6.5/source/tiddlywiki.com/index.html.recipe --savewiki tmp/newcooked || exit 1 # compare the two -opendiff tmp/newcooked.html test/tiddlywiki.2.6.5/target/index.2.6.5.html +opendiff tmp/newcooked/index.html test/tiddlywiki.2.6.5/target/index.2.6.5.html # split the newly cooked tiddlywiki into tiddlers, first with the new ginsu #mkdir -p tmp/newtiddlers @@ -17,3 +18,9 @@ opendiff tmp/newcooked.html test/tiddlywiki.2.6.5/target/index.2.6.5.html # now cook those tiddlers back again with the respective versions of cook #cook $PWD/test/data/recipes/oldtiddlers.recipe -d $PWD -o tmp/oldrecooked.html || exit 1 #node cook.js $PWD/test/data/recipes/newtiddlers.recipe > tmp/newrecooked.html || exit 1 + +# Run the wikification tests +node wikitest.js test/wikitests/ + +jshint *.js +jshint js diff --git a/tiddlywiki.js b/tiddlywiki.js index 91fd8afbd..fa7b6d45d 100644 --- a/tiddlywiki.js +++ b/tiddlywiki.js @@ -2,7 +2,7 @@ TiddlyWiki command line interface */ -/*global require: false, exports: false, process: false */ +/*jslint node: true */ "use strict"; var WikiStore = require("./js/WikiStore.js").WikiStore, @@ -33,9 +33,9 @@ var parseOptions = function(args,defaultSwitch) { switchArgs.push(args[a++]); switchRegExp.lastIndex = 0; } - result.push({switch: m[1], args: switchArgs}); + result.push({switchName: m[1], args: switchArgs}); } else { - result.push({switch: defaultSwitch, args: [args[a++]]}); + result.push({switchName: defaultSwitch, args: [args[a++]]}); } } return result; @@ -80,16 +80,15 @@ for(var t=0; t csw.args.max) { - throw "Command line switch --" + s.switch + " should have a maximum of " + csw.args.max + " arguments" + throw "Command line switch --" + s.switchName + " should have a maximum of " + csw.args.max + " arguments"; } csw.handler(s.args,function (err) { if(err) { diff --git a/wikitest.js b/wikitest.js index 7f1c2c856..f736fd3b3 100644 --- a/wikitest.js +++ b/wikitest.js @@ -9,6 +9,8 @@ verifying that the output matches `.html` and `.txt`. */ +/*jslint node: true */ +"use strict"; var Tiddler = require("./js/Tiddler.js").Tiddler, WikiStore = require("./js/WikiStore.js").WikiStore,