Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use jshint in favor of jslint; enforce linting pretest using yui jshi…

…nt rules
  • Loading branch information...
commit 09d35d8a577a29240ca24d7f52a578b8cef86dd4 1 parent 38b998a
@gotwarlost gotwarlost authored
View
5 lib/cli.js
@@ -6,11 +6,8 @@
*/
-var path = require('path'),
- Command = require('./command'),
+var Command = require('./command'),
inputError = require('./util/input-error'),
- Store = require('./store'),
- Report = require('./report'),
exit = process.exit; //hold a reference to original process.exit so that we are not affected even when a test changes it
require('./register-plugins');
View
1  lib/collector.js
@@ -62,6 +62,7 @@ Collector.prototype = {
* @param {String} testName Optional. The name of the test used to produce the object.
* This is currently not used.
*/
+ /*jshint unused: false */
add: function (coverage, testName) {
var store = this.store;
Object.keys(coverage).forEach(function (key) {
View
13 lib/command/instrument.js
@@ -78,11 +78,14 @@ Command.mix(InstrumentCommand, {
},
usage: function () {
- console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' <options> <file-or-directory>\n\nOptions are:\n\n'
- + [
- formatOption('--output <file-or-dir>', 'The output file or directory. This is required when the input is a directory, defaults to standard output when input is a file'),
- formatOption('-x <exclude-pattern> [-x <exclude-pattern>]', 'one or more fileset patterns (e.g. "**/vendor/**" to ignore all files under a vendor directory). Also see the --default-excludes option'),
- formatOption('--variable <global-coverage-variable-name>', 'change the variable name of the global coverage variable from the default value of `__coverage__` to something else'),
+ console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' <options> <file-or-directory>\n\nOptions are:\n\n' +
+ [
+ formatOption('--output <file-or-dir>', 'The output file or directory. This is required when the input is a directory, ' +
+ 'defaults to standard output when input is a file'),
+ formatOption('-x <exclude-pattern> [-x <exclude-pattern>]', 'one or more fileset patterns (e.g. "**/vendor/**" to ignore all files ' +
+ 'under a vendor directory). Also see the --default-excludes option'),
+ formatOption('--variable <global-coverage-variable-name>', 'change the variable name of the global coverage variable from the ' +
+ 'default value of `__coverage__` to something else'),
formatOption('--embed-source', 'embed source code into the coverage object, defaults to false'),
formatOption('--[no-]compact', 'produce [non]compact output, defaults to compact')
].join('\n\n') + '\n');
View
7 lib/command/report.js
@@ -27,8 +27,8 @@ Command.mix(ReportCommand, {
},
usage: function () {
- console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' <options> [ <format> [<include-pattern>] ]\n\nOptions are:\n\n'
- + [
+ console.error('\nUsage: ' + this.toolName() + ' ' + this.type() + ' <options> [ <format> [<include-pattern>] ]\n\nOptions are:\n\n' +
+ [
formatOption('--root <input-directory>', 'The input root directory for finding coverage files'),
formatOption('--dir <report-directory>', 'The output directory where files will be written. This defaults to ./coverage/'),
formatOption('--verbose, -v', 'verbose mode')
@@ -37,7 +37,8 @@ Command.mix(ReportCommand, {
console.error('\n');
console.error('<format> is one of html, lcovonly or lcov (html + lcovonly). Default is lcov');
- console.error('<include-pattern> is a fileset pattern that can be used to select one or move coverage files for merged reporting. This defaults to "**/coverage*.json"');
+ console.error('<include-pattern> is a fileset pattern that can be used to select one or move coverage files ' +
+ 'for merged reporting. This defaults to "**/coverage*.json"');
console.error('\n');
},
View
7 lib/hook.js
@@ -31,8 +31,7 @@
* @class Hook
*/
/*jslint nomen: true */
-var path = require('path'),
- fs = require('fs'),
+var fs = require('fs'),
Module = require('module'),
vm = require('vm'),
originalLoader = Module._extensions['.js'],
@@ -90,8 +89,8 @@ function hookRequire(matcher, transformer, options) {
options = options || {};
lastMatcher = matcher;
var fn = transformFn(matcher, transformer, options.verbose),
- postLoadHook = options.postLoadHook
- && typeof options.postLoadHook === 'function' ? options.postLoadHook : null;
+ postLoadHook = options.postLoadHook &&
+ typeof options.postLoadHook === 'function' ? options.postLoadHook : null;
Module._extensions['.js'] = function (module, filename) {
var ret = fn(fs.readFileSync(filename, 'utf8'), filename);
View
29 lib/instrumenter.js
@@ -138,7 +138,8 @@
var type = node.type,
children = SYNTAX[type].children,
- applyCustomWalker = !!node.loc || node.type === SYNTAX.Program.name, // don't run generated nodes thru custom walks otherwise we will attempt to instrument the instrumentation code :)
+ // don't run generated nodes thru custom walks otherwise we will attempt to instrument the instrumentation code :)
+ applyCustomWalker = !!node.loc || node.type === SYNTAX.Program.name,
walkerFn = applyCustomWalker ? walker.walkMap[type] : null,
i,
j,
@@ -148,7 +149,6 @@
ret = node,
childArray,
childElement,
- tmpNode,
pathElement,
assignNode,
isLast;
@@ -159,7 +159,9 @@
for (walkFnIndex = 0; walkFnIndex < walkerFn.length; walkFnIndex += 1) {
isLast = walkFnIndex === walkerFn.length - 1;
ret = walker.walk(ret, walkerFn[walkFnIndex]) || ret;
- if (ret.type !== type && !isLast) { throw new Error('Only the last walker is allowed to change the node type: [type was: ' + type + ' ]'); }
+ if (ret.type !== type && !isLast) {
+ throw new Error('Only the last walker is allowed to change the node type: [type was: ' + type + ' ]');
+ }
}
} else {
if (walkerFn) {
@@ -370,7 +372,8 @@
statement: 0
};
- if (typeof code !== 'string') { throw new Error('Code must be string'); } //protect from users accidentally passing in a Buffer object instead
+ //protect from users accidentally passing in a Buffer object instead
+ if (typeof code !== 'string') { throw new Error('Code must be string'); }
if (code.charAt(0) === '#') { //shebang, 'comment' it out, won't affect syntax tree locations for things we care about
code = '//' + code;
}
@@ -451,7 +454,9 @@
file = this.coverState.path.replace(/\\/g, '\\\\'),
tracker = this.currentState.trackerVar,
coverState,
- replacer = function (s) { //return replacements using the function to ensure that the replacement is treated like a dumb string and not as a string with RE replacement patterns
+ // return replacements using the function to ensure that the replacement is
+ // treated like a dumb string and not as a string with RE replacement patterns
+ replacer = function (s) {
return function () { return s; };
},
code;
@@ -504,13 +509,13 @@
return sName;
},
- skipInit: function (node, walker) {
+ skipInit: function (node /*, walker */) {
if (node.init) {
node.init.skipWalk = true;
}
},
- skipLeft: function (node, walker) {
+ skipLeft: function (node /*, walker */) {
node.left.skipWalk = true;
},
@@ -546,7 +551,10 @@
},
coverFunction: function (node, walker) {
- var id = this.functionName(node, walker.startLineForNode(node), { start: node.loc.start, end: { line: node.body.loc.start.line, column: node.body.loc.start.column } }),
+ var id = this.functionName(node, walker.startLineForNode(node), {
+ start: node.loc.start,
+ end: { line: node.body.loc.start.line, column: node.body.loc.start.column }
+ }),
body = node.body,
blockBody = body.body;
blockBody.unshift(
@@ -651,7 +659,10 @@
}
this.findLeaves(node, leaves);
- bName = this.branchName('binary-expr', walker.startLineForNode(node), this.locationsForNodes(leaves.map(function (item) { return item.node; })));
+ bName = this.branchName('binary-expr',
+ walker.startLineForNode(node),
+ this.locationsForNodes(leaves.map(function (item) { return item.node; }))
+ );
for (i = 0; i < leaves.length; i += 1) {
tuple = leaves[i];
tuple.parent[tuple.property] = astgen.sequence(this.branchIncrementExprAst(bName, i), tuple.node);
View
52 lib/report/html.js
@@ -3,7 +3,7 @@
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
-/*jslint nomen: true */
+/*jshint maxlen: 300 */
var handlebars = require('handlebars'),
path = require('path'),
SEP = path.sep || '/',
@@ -65,7 +65,6 @@ var handlebars = require('handlebars'),
'</table>',
'</div>'
].join('\n'),
- seq = 0,
lt = '\u0001',
gt = '\u0002',
RE_LT = /</g,
@@ -84,22 +83,22 @@ handlebars.registerHelper('show_picture', function (opts) {
}
num = Math.floor(num);
rest = 100 - num;
- return '<span class="cover-fill' + cls + '" style="width: ' + num + 'px;"></span>'
- + '<span class="cover-empty" style="width:' + rest + 'px;"></span>';
+ return '<span class="cover-fill' + cls + '" style="width: ' + num + 'px;"></span>' +
+ '<span class="cover-empty" style="width:' + rest + 'px;"></span>';
} else {
return '';
}
});
handlebars.registerHelper('show_lines', function (opts) {
- var maxLines = Number(opts.fn(this)),
- i,
- array = [];
-
- for (i = 0; i < maxLines; i += 1) {
- array[i] = i + 1;
- }
- return array.join('\n');
+ var maxLines = Number(opts.fn(this)),
+ i,
+ array = [];
+
+ for (i = 0; i < maxLines; i += 1) {
+ array[i] = i + 1;
+ }
+ return array.join('\n');
});
handlebars.registerHelper('show_line_execution_counts', function (context, opts) {
@@ -128,7 +127,16 @@ handlebars.registerHelper('show_line_execution_counts', function (context, opts)
return array.join('\n');
});
-handlebars.registerHelper('show_code', function (context, opts) {
+function customEscape(text) {
+ text = text.toString();
+ return text.replace(RE_AMP, '&amp;')
+ .replace(RE_LT, '&lt;')
+ .replace(RE_GT, '&gt;')
+ .replace(RE_lt, '<')
+ .replace(RE_gt, '>');
+}
+
+handlebars.registerHelper('show_code', function (context /*, opts */) {
var structured = context,
array = [];
@@ -271,15 +279,6 @@ function annotateBranches(fileCoverage, structuredText) {
});
}
-function customEscape(text) {
- text = text.toString();
- return text.replace(RE_AMP, '&amp;')
- .replace(RE_LT, '&lt;')
- .replace(RE_GT, '&gt;')
- .replace(RE_lt, '<')
- .replace(RE_gt, '>');
-}
-
function getReportClass(stats) {
var coveragePct = stats.pct,
identity = 1;
@@ -329,12 +328,12 @@ Report.mix(HtmlReport, {
}
for (i = 0; i < nodePath.length; i += 1) {
- linkPath.push('<a href="' + linkMapper.ancestor(node, i + 1) + '">'
- + (nodePath[i].relativeName || 'All files') + '</a>');
+ linkPath.push('<a href="' + linkMapper.ancestor(node, i + 1) + '">' +
+ (nodePath[i].relativeName || 'All files') + '</a>');
}
linkPath.reverse();
- return linkPath.length > 0 ? linkPath.join(' &#187; ') + ' &#187; '
- + node.displayShortName() : '';
+ return linkPath.length > 0 ? linkPath.join(' &#187; ') + ' &#187; ' +
+ node.displayShortName() : '';
},
writeDetailPage: function (writer, node, linkMapper, templateData, fileCoverage, metrics) {
@@ -345,7 +344,6 @@ Report.mix(HtmlReport, {
code = sourceText.split(/\r?\n/),
count = 0,
structured = code.map(function (str) { count += 1; return { line: count, covered: null, text: new InsertionText(str, true) }; }),
- lineNum = 0,
context;
structured.unshift({ line: 0, covered: null, text: new InsertionText("") });
View
4 lib/report/index.js
@@ -24,7 +24,7 @@ var Factory = require('../util/factory'),
* @protected
* @param {Object} options Optional. The options supported by a specific store implementation.
*/
-function Report(options) {}
+function Report(/* options */) {}
//add register, create, mix, loadAll, getStoreList as class methods
factory.bindClassMethods(Report);
@@ -51,7 +51,7 @@ Report.prototype = {
* @param {Collector} collector the collector for getting the set of files and coverage
* @param {Boolean} sync true if reports must be written synchronously, false if they can be written using asynchronous means (e.g. stream.write)
*/
- writeReport: function (collector, sync) {
+ writeReport: function (/* collector, sync */) {
throw new Error('writeReport: must be overridden');
}
};
View
4 lib/report/lcov.js
@@ -5,7 +5,6 @@
var path = require('path'),
mkdirp = require('mkdirp'),
- util = require('util'),
Report = require('./index'),
LcovOnlyReport = require('./lcovonly'),
HtmlReport = require('./html');
@@ -24,7 +23,8 @@ var path = require('path'),
* @extends Report
* @constructor
* @param {Object} opts optional
- * @param {String} [opts.dir] the directory in which to the `lcov.info` file. HTML files are written in a subdirectory called `lcov-report`. Defaults to `process.cwd()`
+ * @param {String} [opts.dir] the directory in which to the `lcov.info` file.
+ * HTML files are written in a subdirectory called `lcov-report`. Defaults to `process.cwd()`
*/
function LcovReport(opts) {
Report.call(this);
View
8 lib/report/lcovonly.js
@@ -4,13 +4,9 @@
*/
var path = require('path'),
- fs = require('fs'),
- util = require('util'),
- Report = require('./index'),
- Store = require('../store'),
Writer = require('../util/file-writer'),
- utils = require('../object-utils');
-
+ util = require('util'),
+ Report = require('./index');
/**
* a `Report` implementation that produces an LCOV coverage file from coverage objects.
*
View
5 lib/report/none.js
@@ -3,8 +3,7 @@
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
-var util = require('util'),
- Report = require('./index');
+var Report = require('./index');
function NoneReport() {
Report.call(this);
@@ -13,7 +12,7 @@ function NoneReport() {
NoneReport.TYPE = 'none';
Report.mix(NoneReport, {
- writeReport: function (collector, sync) {
+ writeReport: function (/* collector, sync */) {
//noop
}
});
View
3  lib/report/text-summary.js
@@ -6,7 +6,6 @@
var path = require('path'),
mkdirp = require('mkdirp'),
fs = require('fs'),
- util = require('util'),
utils = require('../object-utils'),
Report = require('./index');
@@ -42,7 +41,7 @@ function lineForKey(summary, key) {
}
Report.mix(TextSummaryReport, {
- writeReport: function (collector, sync) {
+ writeReport: function (collector /*, sync */) {
var summaries = [],
finalSummary,
lines = [],
View
11 lib/report/text.js
@@ -6,7 +6,6 @@
var path = require('path'),
mkdirp = require('mkdirp'),
fs = require('fs'),
- util = require('util'),
Report = require('./index'),
TreeSummarizer = require('../util/tree-summarizer'),
utils = require('../object-utils'),
@@ -60,14 +59,14 @@ function fill(str, width, right, tabs) {
remaining = width - leadingSpaces,
leader = padding(leadingSpaces),
fmtStr = '',
- fill;
+ fillStr;
if (remaining > 0) {
if (remaining >= str.length) {
- fill = padding(remaining - str.length);
- fmtStr = right ? fill + str : str + fill;
+ fillStr = padding(remaining - str.length);
+ fmtStr = right ? fillStr + str : str + fillStr;
} else {
- fmtStr = str.substring(str.length - remaining);
+ fmtStr = str.substring(str.length - remaining);
fmtStr = '... ' + fmtStr.substring(4);
}
}
@@ -161,7 +160,7 @@ function walk(node, nameWidth, array, level) {
}
Report.mix(TextReport, {
- writeReport: function (collector, sync) {
+ writeReport: function (collector /*, sync */) {
var summarizer = new TreeSummarizer(),
tree,
root,
View
2  lib/store/fslookup.js
@@ -47,7 +47,7 @@ Store.mix(LookupStore, {
return false;
}
},
- set: function (key, contents) {
+ set: function (key /*, contents */) {
if (!this.hasKey(key)) {
throw new Error('Attempt to set contents for non-existent file [' + key + '] on a fslookup store');
}
View
8 lib/store/index.js
@@ -39,7 +39,7 @@ var Factory = require('../util/factory'),
* @protected
* @param {Object} options Optional. The options supported by a specific store implementation.
*/
-function Store(options) {}
+function Store(/* options */) {}
//add register, create, mix, loadAll, getStoreList as class methods
factory.bindClassMethods(Store);
@@ -70,7 +70,7 @@ Store.prototype = {
* @param {String} key the key for the content
* @param {String} contents the contents for the key
*/
- set: function (key, contents) { throw new Error("set: must be overridden"); },
+ set: function (/* key, contents */) { throw new Error("set: must be overridden"); },
/**
* returns the content associated to a specific key or throws if the key
* was not `set`
@@ -78,7 +78,7 @@ Store.prototype = {
* @param {String} key the key for which to get the content
* @return {String} the content for the specified key
*/
- get: function (key) { throw new Error("get: must be overridden"); },
+ get: function (/* key */) { throw new Error("get: must be overridden"); },
/**
* returns a list of all known keys
* @method keys
@@ -91,7 +91,7 @@ Store.prototype = {
* @param {String} key
* @return true if the key is valid for this store, false otherwise
*/
- hasKey: function (key) { throw new Error("hasKey: must be overridden"); },
+ hasKey: function (/* key */) { throw new Error("hasKey: must be overridden"); },
/**
* lifecycle method to dispose temporary resources associated with the store
* @method dispose
View
3  lib/util/tree-summarizer.js
@@ -154,8 +154,7 @@ TreeSummary.prototype = {
});
},
calculateMetrics: function (entry) {
- var that = this,
- metrics = null;
+ var that = this;
if (entry.kind !== 'dir') {return; }
entry.children.forEach(function (child) {
that.calculateMetrics(child);
View
5 package.json
@@ -12,6 +12,7 @@
],
"preferGlobal": true,
"scripts": {
+ "pretest": "jshint --config ./node_modules/yui-lint/jshint.json lib/*js lib/command/*js lib/report/*js lib/store/*js lib/util/*js",
"test": "test/run.js",
"docs": "npm install yuidocjs && node node_modules/yuidocjs/lib/cli.js ."
},
@@ -32,7 +33,9 @@
},
"devDependencies": {
"rimraf": "*",
- "nodeunit": "*"
+ "nodeunit": "*",
+ "jshint": "*",
+ "yui-lint": "*"
},
"TODO": [
"Need a legend for the HTML report + some explanation on how branch coverage is shown",
Please sign in to comment.
Something went wrong with that request. Please try again.