From 103f1b1cdbe27d6cb768e709248d772b7943f257 Mon Sep 17 00:00:00 2001 From: Aleksey V Zapparov Date: Sun, 25 Dec 2011 02:00:57 +0100 Subject: [PATCH] Linted all sources including tests --- Makefile | 4 +-- test/functional-test.js | 3 +- test/functional/canonical.js | 42 ++++++++++++++----------- test/functional/functional-errors.js | 3 ++ test/functional/functional-resolver.js | 3 ++ test/functional/functional-structure.js | 3 ++ test/functional/functional-tokens.js | 3 ++ test/helper.js | 9 ++++-- test/issues-test.js | 3 +- test/issues/issue-17.js | 3 ++ test/issues/issue-19.js | 3 ++ test/issues/issue-26.js | 3 ++ test/issues/issue-33.js | 3 ++ test/issues/issue-8.js | 3 ++ test/issues/issue-9.js | 3 ++ 15 files changed, 65 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index bc11602d..ea13f502 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ CURR_HEAD := $(firstword $(shell git show-ref --hash HEAD | cut --bytes=-6) mas GITHUB_NAME := nodeca/js-yaml SRC_URL_FMT := https://github.com/${GITHUB_NAME}/blob/${CURR_HEAD}/{file}\#L{line} -JS_FILES := $(shell find ./lib -type f -name '*.js' -print) +JS_FILES := $(shell find ./bin ./lib ./test -type f -name '*.js' -print) lint: @if test ! `which jslint` ; then \ @@ -23,7 +23,7 @@ lint: # (nomen) -> tolerate underscores in identifiers (e.g. `var _val = 1`) # (bitwise) -> tolerate bitwise operators (used in base64) # (white) -> tolerate messy whitespace - jslint --node --nomen --bitwise --white --indent=2 ${JS_FILES} + jslint --node --nomen --bitwise --white --indent=2 ./index.js ${JS_FILES} test: lint @if test ! `which vows` ; then \ diff --git a/test/functional-test.js b/test/functional-test.js index da17bfa5..1debb863 100644 --- a/test/functional-test.js +++ b/test/functional-test.js @@ -1,3 +1,4 @@ +'use strict'; require(__dirname + '/helper') - .suite('Functional', __dirname + '/functional', /^functional-.+?\.js$/) + .suite('Functional', __dirname + '/functional', new RegExp("^functional-.+?\\.js$")) .export(module); diff --git a/test/functional/canonical.js b/test/functional/canonical.js index 893ebd83..5427038e 100644 --- a/test/functional/canonical.js +++ b/test/functional/canonical.js @@ -1,3 +1,5 @@ +'use strict'; + var fs = require('fs'), assert = require('assert'), jsyaml = require(__dirname + '/../../lib/js-yaml'), @@ -6,6 +8,7 @@ var fs = require('fs'), _errors = require(__dirname + '/../../lib/js-yaml/errors'), _composer = require(__dirname + '/../../lib/js-yaml/composer'), _constructor = require(__dirname + '/../../lib/js-yaml/construct'), + _tokens = require(__dirname + '/../../lib/js-yaml/tokens'), _resolver = require(__dirname + '/../../lib/js-yaml/resolver'); @@ -47,8 +50,8 @@ $$.inherits(CanonicalError, _errors.YAMLError); -function CanonicalScanner = (data) { - this.data = data + '\0'; +function CanonicalScanner(data) { + this.data = data + '\x00'; this.index = 0; this.tokens = []; this.scanned = false; @@ -66,7 +69,7 @@ CanonicalScanner.prototype.checkToken = function checkTokencheckToken() { return true; } - for (i = 0; i < arguments.length; i++) { + for (i = 0; i < arguments.length; i += 1) { if (this.tokens[0].isA(arguments[i])) { return true; } @@ -105,18 +108,20 @@ CanonicalScanner.prototype.getToken = function getToken(choice) { }; CanonicalScanner.prototype.scan = function scan() { + var ch; + this.tokens.push(new _tokens.StreamStartToken(null, null)); while (true) { this.find_token(); ch = this.data[this.index]; - if (ch === '\0') { + if (ch === '\x00') { this.tokens.push(new _tokens.StreamEndToken(null, null)); break; } else if (ch === '%') { this.tokens.push(this.scanDirective()); - } else if (ch === '-' and this.data.silce(this.index, this.index+3) === '---') { + } else if (ch === '-' && this.data.silce(this.index, this.index+3) === '---') { this.index += 3; this.tokens.push(new _tokens.DocumentStartToken(null, null)); } else if (ch === '[') { @@ -140,7 +145,7 @@ CanonicalScanner.prototype.scan = function scan() { } else if (ch === ',') { this.index += 1; this.tokens.push(new _tokens.FlowEntryToken(null, null)); - } else if (ch === '*' or ch === '&') { + } else if (ch === '*' || ch === '&') { this.tokens.push(this.scanAlias()); } else if (ch === '!') { this.tokens.push(this.scanTag()); @@ -156,9 +161,9 @@ CanonicalScanner.prototype.scan = function scan() { CanonicalScanner.prototype.scanDirective = function scanDirective() { if (this.data.slice(this.index, this.index + DIRECTIVE.length) === this.DIRECTIVE - && 0 <= ' \n\0'.indexOf(this.data.slice(this.index + DIRECTIVE.length))) { + && 0 <= ' \n\x00'.indexOf(this.data.slice(this.index + DIRECTIVE.length))) { this.index += this.DIRECTIVE.length; - return new _tokens.DirectiveToken('YAML', (1, 1), null, null); + return new _tokens.DirectiveToken('YAML', [1, 1], null, null); } throw new CanonicalError("invalid directive"); @@ -173,7 +178,7 @@ CanonicalScanner.prototype.scanAlias = function scanAlias() { this.index += 1; start = this.index; - while (-1 === ', \n\0'.indexOf(this.data[this.index])) { + while (-1 === ', \n\x00'.indexOf(this.data[this.index])) { this.index += 1; } @@ -187,7 +192,7 @@ CanonicalScanner.prototype.scanTag = function scanTag() { this.index += 1; start = this.index; - while (-1 === ' \n\0'.indexOf(this.data[this.index])) { + while (-1 === ' \n\x00'.indexOf(this.data[this.index])) { this.index += 1; } @@ -197,7 +202,7 @@ CanonicalScanner.prototype.scanTag = function scanTag() { value = '!'; } else if (value[0] === '!') { value = 'tag:yaml.org,2002:' + value.slice(1); - } else if (value[0] == '<' && value[value.length-1] == '>') { + } else if (value[0] === '<' && value[value.length-1] === '>') { value = value.slice(1, value.length-2); } else { value = '!' + value; @@ -207,12 +212,12 @@ CanonicalScanner.prototype.scanTag = function scanTag() { }; CanonicalScanner.prototype.scanScalar = function scanScalar() { - var chinks, start, ignoreSpaces, ch, code; + var chunks, start, ignoreSpaces, ch, code, length; this.index += 1; chunks = []; start = this.index; - ignore_spaces = false; + ignoreSpaces = false; while (this.data[this.index] !== '"') { if (this.data[this.index] === '\\') { @@ -224,13 +229,13 @@ CanonicalScanner.prototype.scanScalar = function scanScalar() { if (ch === '\n') { ignoreSpaces = true; - } else if (ch in QUOTE_CODES) { + } else if (0 <= QUOTE_CODES.indexOf(ch)) { length = QUOTE_CODES[ch]; code = parseInt(this.data.slice(this.index, this.index+length), 16); chunks.puush(String.fromCharCode(code)); this.index += length; } else { - if (!(ch in QUOTE_REPLACES)) { + if (-1 === QUOTE_REPLACES.indexOf(ch)) { throw new CanonicalError("invalid escape code"); } @@ -243,7 +248,7 @@ CanonicalScanner.prototype.scanScalar = function scanScalar() { chunks.push(' '); this.index += 1; start = this.index; - ignore_spaces = true; + ignoreSpaces = true; } else if (ignoreSpaces && this.data[this.index] === ' ') { this.index += 1; start = this.index; @@ -269,11 +274,11 @@ CanonicalScanner.prototype.findToken = function findToken() { if (this.data[this.index] === '#') { while (this.data[this.index] !== '\n') { - self.index += 1; + this.index += 1; } } - if (this.data[this.index] == '\n') { + if (this.data[this.index] === '\n') { this.index += 1; } else { found = true; @@ -284,7 +289,6 @@ CanonicalScanner.prototype.findToken = function findToken() { module.exports.CanonicalScanner = CanonicalScanner; - //////////////////////////////////////////////////////////////////////////////// // vim:ts=2:sw=2 //////////////////////////////////////////////////////////////////////////////// diff --git a/test/functional/functional-errors.js b/test/functional/functional-errors.js index 5dab3d70..83ba0fcf 100644 --- a/test/functional/functional-errors.js +++ b/test/functional/functional-errors.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var Fs = require('fs'); var JsYaml = require('../../lib/js-yaml'); diff --git a/test/functional/functional-resolver.js b/test/functional/functional-resolver.js index 996e80fd..fe70e7cf 100644 --- a/test/functional/functional-resolver.js +++ b/test/functional/functional-resolver.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var Fs = require('fs'); var JsYaml = require('../../lib/js-yaml'); diff --git a/test/functional/functional-structure.js b/test/functional/functional-structure.js index 82927e86..96d73bb9 100644 --- a/test/functional/functional-structure.js +++ b/test/functional/functional-structure.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var Fs = require('fs'); var JsYaml = require('../../lib/js-yaml'); diff --git a/test/functional/functional-tokens.js b/test/functional/functional-tokens.js index 67dfe6d8..e0f5e029 100644 --- a/test/functional/functional-tokens.js +++ b/test/functional/functional-tokens.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var Fs = require('fs'); var JsYaml = require('../../lib/js-yaml'); diff --git a/test/helper.js b/test/helper.js index f82bce5e..27446158 100644 --- a/test/helper.js +++ b/test/helper.js @@ -1,3 +1,6 @@ +'use strict'; + + var Vows = require('vows'); var Assert = require('assert'); var Path = require('path'); @@ -9,17 +12,17 @@ var Helper = module.exports = {}; Helper.suite = function suite(name, dirname, regexp) { - var suite = Vows.describe(name); + var obj = Vows.describe(name); Fs.readdirSync(dirname).forEach(function (filename) { var file = Path.join(dirname, filename); if (Fs.statSync(file).isFile() && regexp.test(filename)) { - suite.addBatch(require(file)); + obj.addBatch(require(file)); } }); - return suite; + return obj; }; diff --git a/test/issues-test.js b/test/issues-test.js index 5bbdb2f5..11b5e555 100644 --- a/test/issues-test.js +++ b/test/issues-test.js @@ -1,3 +1,4 @@ +'use strict'; require(__dirname + '/helper') - .suite('Issues', __dirname + '/issues', /^issue-\d+\.js$/) + .suite('Issues', __dirname + '/issues', new RegExp("^issue-[1-9][0-9]*\\.js$")) .export(module); diff --git a/test/issues/issue-17.js b/test/issues/issue-17.js index 162e9559..187150fa 100644 --- a/test/issues/issue-17.js +++ b/test/issues/issue-17.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var JsYaml = require('../../lib/js-yaml'); var source = __dirname + '/data/issue-17.yml'; diff --git a/test/issues/issue-19.js b/test/issues/issue-19.js index 76ee4c98..64410423 100644 --- a/test/issues/issue-19.js +++ b/test/issues/issue-19.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var JsYaml = require('../../lib/js-yaml'); var source = __dirname + '/data/issue-19.yml'; diff --git a/test/issues/issue-26.js b/test/issues/issue-26.js index 0b16029a..f5938c8a 100644 --- a/test/issues/issue-26.js +++ b/test/issues/issue-26.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var JsYaml = require('../../lib/js-yaml'); var source = __dirname + '/data/issue-26.yml'; diff --git a/test/issues/issue-33.js b/test/issues/issue-33.js index 2d0d2399..a1225be6 100644 --- a/test/issues/issue-33.js +++ b/test/issues/issue-33.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var JsYaml = require('../../lib/js-yaml'); var source = __dirname + '/data/issue-33.yml'; diff --git a/test/issues/issue-8.js b/test/issues/issue-8.js index 90180c62..468cbbdc 100644 --- a/test/issues/issue-8.js +++ b/test/issues/issue-8.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var JsYaml = require('../../lib/js-yaml'); var source = __dirname + '/data/issue-8.yml'; diff --git a/test/issues/issue-9.js b/test/issues/issue-9.js index c1c52853..c8e5e166 100644 --- a/test/issues/issue-9.js +++ b/test/issues/issue-9.js @@ -1,3 +1,6 @@ +'use strict'; + + var Assert = require('assert'); var JsYaml = require('../../lib/js-yaml'); var source = __dirname + '/data/issue-9.yml';