2012-10-04 19:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2012-10-04 07:45:44 +02:00
|
|
|
// Global variables, categorized by place of definition.
|
|
|
|
var globals =
|
|
|
|
// Third-party libraries
|
2013-04-03 22:30:36 +02:00
|
|
|
' $ jQuery Spinner Handlebars XDate zxcvbn'
|
2012-10-04 07:45:44 +02:00
|
|
|
|
|
|
|
// index.html
|
2013-03-25 23:26:14 +01:00
|
|
|
+ ' page_params'
|
2012-10-04 07:45:44 +02:00
|
|
|
|
2012-10-18 20:29:16 +02:00
|
|
|
// common.js
|
2013-04-03 22:30:36 +02:00
|
|
|
+ ' status_classes password_quality'
|
2012-10-18 20:29:16 +02:00
|
|
|
|
2012-10-04 07:45:44 +02:00
|
|
|
// setup.js
|
2013-02-16 10:45:32 +01:00
|
|
|
+ ' csrf_token'
|
2012-10-04 07:45:44 +02:00
|
|
|
|
2013-02-19 05:11:13 +01:00
|
|
|
// Modules, defined in their respective files.
|
|
|
|
+ ' compose rows hotkeys narrow reload notifications_bar search subs'
|
|
|
|
+ ' composebox_typeahead typeahead_helper notifications hashchange'
|
2013-03-11 17:25:46 +01:00
|
|
|
+ ' invite ui util activity timerender MessageList blueslip'
|
2013-02-07 19:57:45 +01:00
|
|
|
|
2013-02-16 09:43:27 +01:00
|
|
|
// colorspace.js
|
|
|
|
+ ' colorspace'
|
|
|
|
|
2013-02-13 22:04:35 +01:00
|
|
|
// tutorial.js
|
|
|
|
+ ' tutorial'
|
|
|
|
|
2013-02-16 10:45:32 +01:00
|
|
|
// templates.js
|
|
|
|
+ ' templates'
|
|
|
|
|
2012-10-04 07:45:44 +02:00
|
|
|
// zephyr.js
|
2013-02-22 20:48:31 +01:00
|
|
|
+ ' all_msg_list home_msg_list narrowed_msg_list current_msg_list get_updates_params'
|
2013-02-27 20:47:04 +01:00
|
|
|
+ ' add_messages'
|
2013-02-26 23:09:15 +01:00
|
|
|
+ ' subject_dict people_dict'
|
2012-10-10 20:20:31 +02:00
|
|
|
+ ' keep_pointer_in_view move_pointer_at_page_top_and_bottom'
|
2013-03-28 19:16:48 +01:00
|
|
|
+ ' respond_to_message recenter_view last_viewport_movement_direction'
|
2012-12-03 19:49:12 +01:00
|
|
|
+ ' scroll_to_selected disable_pointer_movement get_private_message_recipient'
|
2012-11-19 17:43:46 +01:00
|
|
|
+ ' load_old_messages'
|
2013-03-23 05:09:41 +01:00
|
|
|
+ ' at_top_of_viewport at_bottom_of_viewport within_viewport'
|
2013-04-02 20:47:18 +02:00
|
|
|
+ ' viewport restart_get_updates'
|
2012-11-27 23:17:30 +01:00
|
|
|
+ ' load_more_messages reset_load_more_status have_scrolled_away_from_top'
|
2013-02-12 22:32:14 +01:00
|
|
|
+ ' maybe_scroll_to_selected recenter_pointer_on_display suppress_scroll_pointer_update'
|
2013-03-04 23:44:07 +01:00
|
|
|
+ ' process_visible_unread_messages message_range message_in_table process_loaded_for_unread'
|
2013-03-19 21:53:49 +01:00
|
|
|
+ ' mark_all_as_read message_unread process_read_messages unread_in_current_view'
|
2013-04-02 20:47:18 +02:00
|
|
|
+ ' fast_forward_pointer'
|
2012-10-04 07:45:44 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
var options = {
|
2012-10-04 07:45:44 +02:00
|
|
|
vars: true, // Allow multiple 'var' per function
|
|
|
|
sloppy: true, // Don't require "use strict"
|
|
|
|
white: true, // Lenient whitespace rules
|
|
|
|
plusplus: true, // Allow increment/decrement operators
|
|
|
|
regexp: true, // Allow . and [^...] in regular expressions
|
|
|
|
todo: true, // Allow "TODO" comments.
|
2013-02-12 21:41:59 +01:00
|
|
|
newcap: true, // Don't assume that capitalized functions are
|
|
|
|
// constructors (and the converse)
|
2013-02-19 04:40:57 +01:00
|
|
|
nomen: true, // Tolerate underscore at the beginning of a name
|
|
|
|
stupid: true // Allow synchronous methods
|
2012-10-04 07:45:44 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// For each error.raw message, we can return 'true' to ignore
|
|
|
|
// the error.
|
|
|
|
var exceptions = {
|
|
|
|
"Expected '{a}' and instead saw '{b}'." : function (error) {
|
|
|
|
// We allow single-statement 'if' with no brace.
|
|
|
|
// This exception might be overly broad but oh well.
|
|
|
|
return (error.a === '{');
|
|
|
|
},
|
|
|
|
|
|
|
|
"Unexpected 'else' after 'return'." : function () {
|
|
|
|
return true;
|
2013-02-12 23:26:25 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
"Don't make functions within a loop." : function () {
|
|
|
|
return true;
|
2013-04-04 00:04:47 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
// We use typeof to test if a variable exists at all.
|
|
|
|
"Unexpected 'typeof'. Use '===' to compare directly with {a}.": function (error) {
|
|
|
|
return error.a === 'undefined';
|
2012-10-04 07:45:44 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var fs = require('fs');
|
2012-10-04 19:15:37 +02:00
|
|
|
var path = require('path');
|
|
|
|
var JSLINT = require(path.join(__dirname, 'jslint')).JSLINT;
|
2012-10-04 07:45:44 +02:00
|
|
|
|
2012-10-04 19:40:29 +02:00
|
|
|
var cwd = process.cwd();
|
2012-10-04 07:45:44 +02:00
|
|
|
|
|
|
|
var exit_code = 0;
|
2013-02-19 04:40:57 +01:00
|
|
|
var i;
|
2012-10-04 07:45:44 +02:00
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
// Drop 'node' and the script name from args.
|
|
|
|
for (i=0; i<2; i++) {
|
|
|
|
process.argv.shift();
|
|
|
|
}
|
2012-10-04 07:45:44 +02:00
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
process.argv.forEach(function (filepath) {
|
2012-10-04 19:40:29 +02:00
|
|
|
var contents = fs.readFileSync(filepath, 'utf8');
|
2012-10-04 07:45:44 +02:00
|
|
|
var messages = [];
|
|
|
|
|
2013-02-19 04:40:57 +01:00
|
|
|
// We mutate 'options' so be sure to clear everything.
|
|
|
|
if (filepath.indexOf('zephyr/static/js/') !== -1) {
|
|
|
|
// Frontend browser code
|
|
|
|
options.browser = true;
|
|
|
|
options.node = false;
|
|
|
|
options.predef = globals.split(/\s+/);
|
|
|
|
} else {
|
|
|
|
// Backend code for Node.js
|
|
|
|
options.browser = false;
|
|
|
|
options.node = true;
|
|
|
|
|
|
|
|
if (filepath.indexOf('zephyr/tests/frontend/') !== -1) {
|
|
|
|
// Include '$' because we use jQuery inside casper.evaluate
|
|
|
|
options.predef = ['casper', '$'];
|
|
|
|
} else {
|
|
|
|
options.predef = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!JSLINT(contents, options)) {
|
2012-10-04 07:45:44 +02:00
|
|
|
JSLINT.errors.forEach(function (error) {
|
|
|
|
if (error === null) {
|
|
|
|
// JSLint stopping error
|
|
|
|
messages.push(' (JSLint giving up)');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var exn = exceptions[error.raw];
|
|
|
|
if (exn && exn(error)) {
|
|
|
|
// Ignore this error.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: this will break on a 10,000 line file
|
|
|
|
var line = (' ' + error.line).slice(-4);
|
|
|
|
|
|
|
|
messages.push(' ' + line + ' ' + error.reason);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (messages.length > 0) {
|
|
|
|
exit_code = 1;
|
|
|
|
|
2012-10-04 19:40:29 +02:00
|
|
|
console.log(path.relative(cwd, filepath));
|
2012-10-04 07:45:44 +02:00
|
|
|
|
|
|
|
// Something very wacky happens if we do
|
|
|
|
// .forEach(console.log) directly.
|
|
|
|
messages.forEach(function (msg) {
|
|
|
|
console.log(msg);
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log('');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
process.exit(exit_code);
|