From a499a7cfd54808e71d612d2e54b17dd5b59340bf Mon Sep 17 00:00:00 2001 From: Mark Cavage Date: Tue, 24 Jan 2012 09:43:46 -0800 Subject: [PATCH] Addition of javascriptlint --- Makefile | 25 +++++--- lib/attribute.js | 3 +- lib/client.js | 34 ++++++----- lib/server.js | 10 ++-- tools/jsl.conf | 140 +++++++++++++++++++++++++++++++++++++++++++++ tst/change.test.js | 2 +- 6 files changed, 184 insertions(+), 30 deletions(-) create mode 100755 tools/jsl.conf diff --git a/Makefile b/Makefile index b3ed682..318c674 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,22 @@ -NAME=ldapjs ifeq ($(VERSION), "") @echo "Use gmake" endif +DOCPKGDIR = ./docs/pkg +HAVE_GJSLINT := $(shell which gjslint >/dev/null && echo yes || echo no) +LINT = ./node_modules/.javascriptlint/build/install/jsl --conf ./tools/jsl.conf +NAME=ldapjs +RESTDOWN_VERSION=1.2.13 SRC := $(shell pwd) TAR = tar UNAME := $(shell uname) ifeq ($(UNAME), SunOS) TAR = gtar endif - -HAVE_GJSLINT := $(shell which gjslint >/dev/null && echo yes || echo no) NPM := npm_config_tar=$(TAR) npm -RESTDOWN_VERSION=1.2.13 -DOCPKGDIR = ./docs/pkg - RESTDOWN = ./node_modules/.restdown/bin/restdown \ -b ./docs/branding \ -m ${DOCPKGDIR} \ @@ -34,7 +33,15 @@ node_modules/.ldapjs.npm.installed: else \ (cd node_modules/.restdown && git fetch origin); \ fi + + if [[ ! -d node_modules/.javascriptlint ]]; then \ + git clone https://github.com/davepacheco/javascriptlint node_modules/.javascriptlint; \ + else \ + (cd node_modules/.javascriptlint && git fetch origin); \ + fi + @(cd ./node_modules/.restdown && git checkout $(RESTDOWN_VERSION)) + @(cd ./node_modules/.javascriptlint && $(MAKE) install) @touch ./node_modules/.ldapjs.npm.installed dep: ./node_modules/.ldapjs.npm.installed @@ -44,13 +51,15 @@ gjslint: gjslint --nojsdoc -r lib -r tst ifeq ($(HAVE_GJSLINT), yes) -lint: gjslint +lint: install gjslint + ${LINT} --recurse lib/*.js else -lint: +lint: install @echo "* * *" @echo "* Warning: Cannot lint with gjslint. Install it from:" @echo "* http://code.google.com/closure/utilities/docs/linter_howto.html" @echo "* * *" + ${LINT} --recurse lib/*.js endif doc: dep diff --git a/lib/attribute.js b/lib/attribute.js index 8054f0b..5c5a7bd 100644 --- a/lib/attribute.js +++ b/lib/attribute.js @@ -148,9 +148,10 @@ Attribute.isAttribute = function(attr) { if (attr instanceof Attribute) return true; if (!attr.type || typeof(attr.type) !== 'string') return false; if (!attr.vals || !Array.isArray(attr.vals)) return false; - for (var i = 0; i < attr.vals.length; i++) + for (var i = 0; i < attr.vals.length; i++) { if (typeof(attr.vals[i]) !== 'string' && !Buffer.isBuffer(attr.vals[i])) return false; + } return true; }; diff --git a/lib/client.js b/lib/client.js index 9f0618f..22831cd 100644 --- a/lib/client.js +++ b/lib/client.js @@ -205,6 +205,8 @@ Client.prototype.connect = function(callback) { self.emit('connect'); return callback(); }); + + return false; }; @@ -227,7 +229,7 @@ Client.prototype.bind = function(name, credentials, controls, callback, conn) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -272,7 +274,7 @@ Client.prototype.abandon = function(messageID, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -308,7 +310,7 @@ Client.prototype.add = function(name, entry, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -366,7 +368,7 @@ Client.prototype.compare = function(name, attr, value, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -406,7 +408,7 @@ Client.prototype.del = function(name, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -447,7 +449,7 @@ Client.prototype.exop = function(name, value, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -520,7 +522,7 @@ Client.prototype.modify = function(name, change, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -558,7 +560,7 @@ Client.prototype.modifyDN = function(name, newName, controls, callback) { callback = controls; controls = []; } else { - control = validateControls(controls); + controls = validateControls(controls); } if (typeof(callback) !== 'function') throw new TypeError('callback (function) required'); @@ -672,11 +674,10 @@ Client.prototype.search = function(base, options, controls, callback) { // reconnected, and having thrown an error like "NotWriteable". Because // the event emitter logic will never block, we'll end up returning from // the event.on('error'), rather than "normally". - var self = this; var done = false; function errorIfNoConn(err) { if (done) - return; + return false; done = true; return callback(err); @@ -703,7 +704,7 @@ Client.prototype.unbind = function(callback) { if (callback && typeof(callback) !== 'function') throw new TypeError('callback must be a function'); if (!callback) - callback = function defUnbindCb() { self.log.trace('disconnected'); }; + callback = function() { self.log.trace('disconnected'); }; var self = this; this.reconnect = false; @@ -733,7 +734,7 @@ Client.prototype._send = function(message, expect, callback, connection) { if (timer) clearTimeout(timer); - var err = err || new ConnectionError('no connection'); + err = err || new ConnectionError('no connection'); if (typeof(callback) === 'function') { callback(err); @@ -751,7 +752,7 @@ Client.prototype._send = function(message, expect, callback, connection) { // Now set up the callback in the messages table message.messageID = conn.ldap.nextMessageID; if (expect !== 'abandon') { - conn.ldap.messages[message.messageID] = function _sendCallback(res) { + conn.ldap.messages[message.messageID] = function(res) { if (timer) clearTimeout(timer); @@ -798,6 +799,8 @@ Client.prototype._send = function(message, expect, callback, connection) { callback.emit('error', err); } + + return false; }; } @@ -806,7 +809,7 @@ Client.prototype._send = function(message, expect, callback, connection) { timer = setTimeout(function() { self.emit('timeout', message); if (conn.ldap.messages[message.messageID]) - return conn.ldap.messages[message.messageID](new LDAPResult({ + conn.ldap.messages[message.messageID](new LDAPResult({ status: 80, // LDAP_OTHER errorMessage: 'request timeout (client interrupt)' })); @@ -921,6 +924,7 @@ Client.prototype._newConnection = function() { delete c.ldap; delete c.parser; + return false; }); }); @@ -956,7 +960,7 @@ Client.prototype._newConnection = function() { if (!callback) { log.error('%s: unsolicited message: %j', c.ldap.id, message.json); - return; + return false; } return callback(message); diff --git a/lib/server.js b/lib/server.js index 9354fde..54fe285 100644 --- a/lib/server.js +++ b/lib/server.js @@ -349,7 +349,7 @@ function Server(options) { if (!res) { log.warn('Unimplemented server method: %s', req.type); c.destroy(); - return; + return false; } res.connection = c; @@ -417,7 +417,7 @@ function Server(options) { res.status = 0x02; // protocol error res.errorMessage = err.toString(); - c.end(res.toBer()); + return c.end(res.toBer()); }); c.on('data', function(data) { @@ -670,7 +670,7 @@ Server.prototype.listen = function(port, host, callback) { } if (typeof(callback) === 'function') - return callback(); + callback(); } if (typeof(port) === 'number') { @@ -680,8 +680,8 @@ Server.prototype.listen = function(port, host, callback) { } }; Server.prototype.listenFD = function(fd) { - self.host = 'unix-domain-socket'; - self.port = fd; + this.host = 'unix-domain-socket'; + this.port = fd; return this.server.listenFD(fd); }; Server.prototype.close = function() { diff --git a/tools/jsl.conf b/tools/jsl.conf new file mode 100755 index 0000000..119319e --- /dev/null +++ b/tools/jsl.conf @@ -0,0 +1,140 @@ +# +# Configuration File for JavaScript Lint 0.3.0 +# Developed by Matthias Miller (http://www.JavaScriptLint.com) +# +# This configuration file can be used to lint a collection of scripts, or to enable +# or disable warnings for scripts that are linted via the command line. +# + +### Warnings +# Enable or disable warnings based on requirements. +# Use "+WarningName" to display or "-WarningName" to suppress. +# ++no_return_value # function {0} does not always return a value ++duplicate_formal # duplicate formal argument {0} ++equal_as_assign # test for equality (==) mistyped as assignment (=)?{0} ++var_hides_arg # variable {0} hides argument ++redeclared_var # redeclaration of {0} {1} ++anon_no_return_value # anonymous function does not always return a value ++missing_semicolon # missing semicolon ++meaningless_block # meaningless block; curly braces have no impact ++comma_separated_stmts # multiple statements separated by commas (use semicolons?) +-unreachable_code # unreachable code ++missing_break # missing break statement ++missing_break_for_last_case # missing break statement for last case in switch ++comparison_type_conv # comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==) +-inc_dec_within_stmt # increment (++) and decrement (--) operators used as part of greater statement ++useless_void # use of the void type may be unnecessary (void is always undefined) +-useless_quotes # quotation marks are unnecessary ++multiple_plus_minus # unknown order of operations for successive plus (e.g. x+++y) or minus (e.g. x---y) signs ++use_of_label # use of label +-block_without_braces # block statement without curly braces ++leading_decimal_point # leading decimal point may indicate a number or an object member ++trailing_decimal_point # trailing decimal point may indicate a number or an object member +-octal_number # leading zeros make an octal number ++nested_comment # nested comment ++misplaced_regex # regular expressions should be preceded by a left parenthesis, assignment, colon, or comma ++ambiguous_newline # unexpected end of line; it is ambiguous whether these lines are part of the same statement ++empty_statement # empty statement or extra semicolon +-missing_option_explicit # the "option explicit" control comment is missing ++partial_option_explicit # the "option explicit" control comment, if used, must be in the first script tag ++dup_option_explicit # duplicate "option explicit" control comment ++useless_assign # useless assignment ++ambiguous_nested_stmt # block statements containing block statements should use curly braces to resolve ambiguity ++ambiguous_else_stmt # the else statement could be matched with one of multiple if statements (use curly braces to indicate intent) +-missing_default_case # missing default case in switch statement ++duplicate_case_in_switch # duplicate case in switch statements ++default_not_at_end # the default case is not at the end of the switch statement ++legacy_cc_not_understood # couldn't understand control comment using /*@keyword@*/ syntax ++jsl_cc_not_understood # couldn't understand control comment using /*jsl:keyword*/ syntax ++useless_comparison # useless comparison; comparing identical expressions ++with_statement # with statement hides undeclared variables; use temporary variable instead ++trailing_comma_in_array # extra comma is not recommended in array initializers ++assign_to_function_call # assignment to a function call ++parseint_missing_radix # parseInt missing radix parameter ++unreferenced_argument # argument declared but never referenced: {name} ++unreferenced_function # function declared but not referenced +-identifier_hides_another +-empty_statement + +### Output format +# Customize the format of the error message. +# __FILE__ indicates current file path +# __FILENAME__ indicates current file name +# __LINE__ indicates current line +# __ERROR__ indicates error message +# +# Visual Studio syntax (default): ++output-format __FILE__(__LINE__): __ERROR__ +# Alternative syntax: +#+output-format __FILE__:__LINE__: __ERROR__ + + +### Context +# Show the in-line position of the error. +# Use "+context" to display or "-context" to suppress. +# ++context + + +### Semicolons +# By default, assignments of an anonymous function to a variable or +# property (such as a function prototype) must be followed by a semicolon. +# +#+lambda_assign_requires_semicolon # deprecated setting + + +### Control Comments +# Both JavaScript Lint and the JScript interpreter confuse each other with the syntax for +# the /*@keyword@*/ control comments and JScript conditional comments. (The latter is +# enabled in JScript with @cc_on@). The /*jsl:keyword*/ syntax is preferred for this reason, +# although legacy control comments are enabled by default for backward compatibility. +# ++legacy_control_comments + + +### JScript Function Extensions +# JScript allows member functions to be defined like this: +# function MyObj() { /*constructor*/ } +# function MyObj.prototype.go() { /*member function*/ } +# +# It also allows events to be attached like this: +# function window::onload() { /*init page*/ } +# +# This is a Microsoft-only JavaScript extension. Enable this setting to allow them. +# +#-jscript_function_extensions # deprecated setting + + +### Defining identifiers +# By default, "option explicit" is enabled on a per-file basis. +# To enable this for all files, use "+always_use_option_explicit" +-always_use_option_explicit + +# Define certain identifiers of which the lint is not aware. +# (Use this in conjunction with the "undeclared identifier" warning.) +# +# Common uses for webpages might be: ++define global ++define process ++define require ++define exports ++define setTimeout ++define clearTimeout ++define setInterval ++define clearInterval ++define JSON ++define console ++define __dirname ++define __filename ++define Buffer ++define module + + +### Files +# Specify which files to lint +# Use "+recurse" to enable recursion (disabled by default). +# To add a set of files, use "+process FileName", "+process Folder\Path\*.js", +# or "+process Folder\Path\*.htm". +# +#+process jsl-test.js diff --git a/tst/change.test.js b/tst/change.test.js index 83af510..b2ec8be 100644 --- a/tst/change.test.js +++ b/tst/change.test.js @@ -52,7 +52,7 @@ test('new with args', function(t) { test('GH-31 (multiple attributes per Change)', function(t) { try { - var change = new Change({ + new Change({ operation: 'replace', modification: { cn: 'foo',