Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Fix tests #9

Merged
merged 12 commits into from
Feb 25, 2016
Merged
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
language: node_js
script: "make lint && make test reporter=spec && make test-browser reporter=spec && make coverage cov-reporter=travis-cov"
node_js:
- "stable"
- "4.2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 💯

- "0.12"
- "0.10"
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ test-browser: FORCE clean browser/test/tests.js

files := $(shell find . -name '*.js' ! -path "./node_modules/*" ! -path "./dist/*" ! -path "./browser*" ! -path "./docs*" ! -path "./tmp*")
lint:
@${BIN}/nodelint ${files} --config=scripts/config-lint.js
@${BIN}/jslint ${files} --terse
@echo ""

out = tests/coverage.html
cov-reporter = html-cov
Expand Down
2 changes: 1 addition & 1 deletion bin/swig.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var command,
out = function (file, str) {
console.log(str);
},
efn = function () {},
efn = function () { return; },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to satisfy the linter? IMO this doesn't add clarity, it just seems crufty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, every instance in which I'm returning inside an empty function is to satisfy the linter.

anonymous,
files,
fn;
Expand Down
40 changes: 40 additions & 0 deletions jslint.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"adsafe": false,
"bitwise": true,
"browser": false,
"cap": false,
"confusion": false,
"continue": true,
"css": false,
"debug": false,
"devel": false,
"eqeq": false,
"es5": false,
"evil": true,
"forin": false,
"fragment": false,
"indent": 2,
"maxerr": 300,
"maxlen": 600,
"newcap": false,
"node": true,
"nomen": true,
"on": false,
"passfail": false,
"plusplus": false,
"predef": [
"describe", "it", "after", "afterEach", "before", "beforeEach"
],
"regexp": true,
"rhino": false,
"safe": false,
"sloppy": true,
"stupid": true,
"sub": false,
"undef": false,
"unparam": true,
"vars": false,
"white": false,
"widget": false,
"windows": false
}
2 changes: 1 addition & 1 deletion lib/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ exports.date = function (input, format, offset, abbr) {
* @return {*} `input` or `def` value.
*/
exports["default"] = function (input, def) {
return (typeof input !== 'undefined' && (input || typeof input === 'number')) ? input : def;
return (input !== undefined && (input || typeof input === 'number')) ? input : def;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/loaders/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = function (basepath, encoding) {
var ret = {};

encoding = encoding || 'utf8';
basepath = (basepath) ? path.normalize(basepath) : null;
basepath = basepath ? path.normalize(basepath) : null;

/**
* Resolves <var>to</var> to an absolute path or unique identifier. This is used for building correct, normalized, and absolute paths to a given template.
Expand All @@ -29,7 +29,7 @@ module.exports = function (basepath, encoding) {
if (basepath) {
from = basepath;
} else {
from = (from) ? path.dirname(from) : process.cwd();
from = from ? path.dirname(from) : process.cwd();
}
return path.resolve(from, to);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/loaders/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var path = require('path'),
module.exports = function (mapping, basepath) {
var ret = {};

basepath = (basepath) ? path.normalize(basepath) : null;
basepath = basepath ? path.normalize(basepath) : null;

/**
* Resolves <var>to</var> to an absolute path or unique identifier. This is used for building correct, normalized, and absolute paths to a given template.
Expand All @@ -30,7 +30,7 @@ module.exports = function (mapping, basepath) {
if (basepath) {
from = basepath;
} else {
from = (from) ? path.dirname(from) : '/';
from = from ? path.dirname(from) : '/';
}
return path.resolve(from, to);
};
Expand Down
14 changes: 7 additions & 7 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,11 @@ exports.parse = function (swig, source, opts, tags, filters) {
* @private
*/
function parseVariable(str, line) {
var tokens = lexer.read(utils.strip(str)),
var lexedTokens = lexer.read(utils.strip(str)),
parser,
out;

parser = new TokenParser(tokens, filters, escape, line, opts.filename);
parser = new TokenParser(lexedTokens, filters, escape, line, opts.filename);
out = parser.parse().join('');

if (parser.state.length) {
Expand Down Expand Up @@ -511,7 +511,7 @@ exports.parse = function (swig, source, opts, tags, filters) {
* @private
*/
function parseTag(str, line) {
var tokens, parser, chunks, tagName, tag, args, last;
var lexedTokens, parser, chunks, tagName, tag, args, last;

if (utils.startsWith(str, 'end')) {
last = stack[stack.length - 1];
Expand Down Expand Up @@ -544,8 +544,8 @@ exports.parse = function (swig, source, opts, tags, filters) {
utils.throwError('Unexpected tag "' + str + '"', line, opts.filename);
}

tokens = lexer.read(utils.strip(chunks.join(' ')));
parser = new TokenParser(tokens, filters, false, line, opts.filename);
lexedTokens = lexer.read(utils.strip(chunks.join(' ')));
parser = new TokenParser(lexedTokens, filters, false, line, opts.filename);
tag = tags[tagName];

/**
Expand Down Expand Up @@ -650,7 +650,7 @@ exports.parse = function (swig, source, opts, tags, filters) {
}
// Is a content string?
} else if (inRaw || (!utils.startsWith(chunk, cmtOpen) && !utils.endsWith(chunk, cmtClose))) {
token = (stripNext) ? chunk.replace(/^\s*/, '') : chunk;
token = stripNext ? chunk.replace(/^\s*/, '') : chunk;
stripNext = false;
} else if (utils.startsWith(chunk, cmtOpen) && utils.endsWith(chunk, cmtClose)) {
return;
Expand Down Expand Up @@ -686,7 +686,7 @@ exports.parse = function (swig, source, opts, tags, filters) {
}

lines = chunk.match(/\n/g);
line += (lines) ? lines.length : 0;
line += lines ? lines.length : 0;
});

return {
Expand Down
11 changes: 5 additions & 6 deletions lib/swig.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function validateOptions(options) {
}
utils.each(options[key], function (a, i) {
if (a.length < 2) {
throw new Error('Option "' + key + '" ' + ((i) ? 'open ' : 'close ') + 'control must be at least 2 characters. Saw "' + a + '" instead.');
throw new Error('Option "' + key + '" ' + (i ? 'open ' : 'close ') + 'control must be at least 2 characters. Saw "' + a + '" instead.');
}
});
});
Expand Down Expand Up @@ -339,16 +339,16 @@ exports.Swig = function (opts) {
validateOptions(options);

var locals = getLocals(options),
opts = {},
opt = {},
k;

for (k in options) {
if (options.hasOwnProperty(k) && k !== 'locals') {
opts[k] = options[k];
opt[k] = options[k];
}
}

options = utils.extend({}, self.options, opts);
options = utils.extend({}, self.options, opt);
options.locals = locals;

return parser.parse(this, source, options, tags, filters);
Expand Down Expand Up @@ -485,8 +485,7 @@ exports.Swig = function (opts) {
this.precompile = function (source, options) {
var tokens = self.parse(source, options),
parents = getParents(tokens, options),
tpl,
err;
tpl;

if (parents.length) {
// Remap the templates first-parent's tokens using this template's blocks.
Expand Down
2 changes: 1 addition & 1 deletion lib/tags/extends.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @param {string} parentFile Relative path to the file that this template extends.
*/
exports.compile = function () {};
exports.compile = function () { return; };

exports.parse = function () {
return true;
Expand Down
2 changes: 1 addition & 1 deletion lib/tags/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ exports.compile = function (compiler, args, content, parents, options, blockName
};

exports.parse = function (str, line, parser, types) {
if (typeof str === "undefined") {
if (str === undefined) {
throw new Error('No conditional statement provided on line ' + line + '.');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports.each = function (obj, fn) {
* @return {boolean}
*/
exports.isArray = isArray = (Array.hasOwnProperty('isArray')) ? Array.isArray : function (obj) {
return (obj) ? (typeof obj === 'object' && Object.prototype.toString.call(obj).indexOf() !== -1) : false;
return obj ? (typeof obj === 'object' && Object.prototype.toString.call(obj).indexOf() !== -1) : false;
};

/**
Expand All @@ -90,7 +90,7 @@ exports.some = function (obj, fn) {
} else {
exports.each(obj, function (value, index) {
result = fn(value, index, obj);
return !(result);
return !result;
});
}
return !!result;
Expand Down
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@
"optimist": "~0.6"
},
"devDependencies": {
"lodash": "~1.3.1",
"express": "~3",
"nodelint": "~0.6",
"mocha": "1.12.0",
"blanket": "~1.1",
"browserify": "~2",
"expect.js": "~0.2",
"still": "0.0.7",
"express": "~3",
"file": "~0.2",
"jsdoc": "3.2.0",
"jslint": "^0.9.6",
"less": "~1.4",
"lodash": "~1.3.1",
"mocha": "1.12.0",
"mocha-phantomjs": "~3.1",
"blanket": "~1.1",
"travis-cov": "~0.2",
"phantomjs": "~1.9.1",
"browserify": "~2",
"file": "~0.2",
"jsdoc": "3.2.0"
"rimraf": "^2.5.2",
"still": "0.0.7",
"travis-cov": "~0.2"
},
"license": "MIT",
"main": "index",
Expand Down
41 changes: 0 additions & 41 deletions scripts/config-lint.js

This file was deleted.

7 changes: 4 additions & 3 deletions scripts/githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,21 @@ for FILE in `exec git diff-index --check --cached $against -- | sed '/^[+-]/d' |
git add $FILE
done

echo ''
echo 'Running JSLint...'
result=$(make lint)
if ! egrep "(^|[^\d])0 errors" <<< "$result"; then
num=$(grep "[0-9]+ error" <<< "$result")
if grep -q Expected <<< "$result"; then
num=$(grep "Expected" <<< "$result" | wc -l)
testFail "JSLint: $num"
echo "$result"
echo ''
lintFailed=1
fi

if [[ $lint_errors -gt 0 ]]; then
failCommit "Lint Errors"
fi

echo ''
echo 'Running Tests...'
result=$(make test)
if grep -q FAILURES <<< $result; then
Expand Down
2 changes: 1 addition & 1 deletion tests/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('options', function () {
});

it('throws on anything else', function () {
expect(function () { var s = new Swig({ cache: 'dookie' }); })
expect(function () { return new Swig({ cache: 'dookie' }); })
.to.throwError();

expect(function () { swig.setDefaults({ cache: { a: 1, b: 2 } }); })
Expand Down
Loading