Skip to content
Browse files

Linted all sources including tests

  • Loading branch information...
1 parent f1a22c0 commit 103f1b1cdbe27d6cb768e709248d772b7943f257 @ixti ixti committed Dec 25, 2011
View
4 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 \
View
3 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);
View
42 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
////////////////////////////////////////////////////////////////////////////////
View
3 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');
View
3 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');
View
3 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');
View
3 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');
View
9 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;
};
View
3 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);
View
3 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';
View
3 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';
View
3 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';
View
3 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';
View
3 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';
View
3 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';

0 comments on commit 103f1b1

Please sign in to comment.
Something went wrong with that request. Please try again.