Skip to content

Commit

Permalink
Lint project source code
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and foolip committed Oct 21, 2019
1 parent 724e1bb commit a56b669
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"node": true,
"esversion": 6,
"undef": true,
"unused": true
}
2 changes: 1 addition & 1 deletion lib/check-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ var crypto = require('crypto');
module.exports = function(body, header, secret) {
var hash = crypto.createHmac('sha1', secret).update(body).digest('hex');
return ("sha1=" + hash) === header;
}
};
2 changes: 1 addition & 1 deletion lib/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ function labelAndComment(number, label, msg) {
if (!processed) {
return github.post('/repos/:owner/:repo/issues/:number/comments', { body: msg }, { number: number });
}
})
});
});
}
6 changes: 3 additions & 3 deletions lib/funk.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports.prop = prop;
function prop(propName) {
return function(obj) {
return obj[propName];
}
};
}

exports.compose = compose;
Expand All @@ -27,5 +27,5 @@ function compose() {
args = [funcs[i].apply(this, args)];
}
return args[0];
}
}
};
}
2 changes: 1 addition & 1 deletion lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function _post(method, url, body, options) {
options = mergeOptions(options || {});
url = replaceURL(baseURL(url), options);
var deferred = q.defer();
body = typeof body == "string" ? body : JSON.stringify(body)
body = typeof body == "string" ? body : JSON.stringify(body);
console.log(method + " " + url + "\n" + body);
request[method.toLowerCase()]({
url: url,
Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/filenames.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function(issue) {
.then(function(files) {
return {
all: files.map(funk.prop('filename')),
ignoreRemoved: files.filter(function(file) { return file.status != "removed" }).map(funk.prop('filename'))
ignoreRemoved: files.filter((file) => file.status != 'removed').map(funk.prop('filename'))
};
});
};
Expand Down
19 changes: 11 additions & 8 deletions lib/metadata/find-owners.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use strict";
var github = require('../github'),
funk = require('../funk'),
uniq = require('../uniq'),
yaml = require('js-yaml'),
q = require('q');
Expand All @@ -9,16 +8,21 @@ function getReviewersFile(path, reviewers) {
return github.get("/repos/:owner/:repo/contents/:path", { path: path + "/META.yml" })
.then(function(file) {
if (file.type != "file") {
throw new Error("Something's up!")
throw new Error("Something's up!");
}
parse(decode(file.content)).forEach(function(reviewer) {
reviewers.push(reviewer);
});
if (path = parentDir(path)) {

path = parentDir(path);

if (path) {
return getReviewersFile(path, reviewers);
}
}).catch(function() { // There is no META.yml file in this dir
if (path = parentDir(path)) {
path = parentDir(path);

if (path) {
return getReviewersFile(path, reviewers);
}
});
Expand All @@ -33,9 +37,9 @@ function parentDir(path) {
return path.join("/");
}

module.exports = function(directories) {
module.exports = function(_directories) {
var reviewers = [];
var directories = directories.slice(0);
var directories = _directories.slice(0);
var deferred = q.defer();
function next() {
if (directories.length) {
Expand All @@ -59,11 +63,10 @@ function decode(content) {
module.exports.parse = parse;
function parse(content) {
try {
var suggested_reviewers = yaml.safeLoad(content).suggested_reviewers;
return yaml.safeLoad(content).suggested_reviewers;
} catch(e) {
throw new Error("unable to parse yaml: " + e);
}
return suggested_reviewers;
}


Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/get-reviewers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ module.exports = function getReviewers(metadata) {
return reviewers.filter(function(login) {
return metadata.reviewers.indexOf(login) < 0;
});
}
};
5 changes: 2 additions & 3 deletions lib/metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ var filenames = require('./filenames'),
labels = require('./labels'),
getReviewers = require('./get-reviewers'),
chooseAssignee = require('./choose-assignee'),
funk = require('../funk'),
github = require('../github');

module.exports = function getMetadada(number, author, content) {
Expand All @@ -29,7 +28,7 @@ module.exports = function getMetadada(number, author, content) {
metadata.paths = paths(metadata.filenames);
fileLabels = labels.fromFiles(metadata.filenames);
metadata.isRoot = metadata.filenames.some(function(path) {
return path.split('/').length == 1
return path.split('/').length == 1;
});
metadata.isReviewable = metadata.isRoot || metadata.filenames.some(function(path) {
var dir = path.split('/')[0];
Expand All @@ -43,7 +42,7 @@ module.exports = function getMetadada(number, author, content) {
labels.fromWorkingGroups(metadata.workingGroups)
);
}).then(function() {
return findOwners(metadata.paths)
return findOwners(metadata.paths);
}).then(function(owners) {
reviewers = owners;
return findRemovedReviewers(number);
Expand Down
16 changes: 7 additions & 9 deletions lib/metadata/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ var LABEL_TO_PATTERNS = {
"html/semantics/forms/the-fieldset-element/**",
"html/semantics/forms/the-legend-element/**"
],
"html": ["rtl-reference.html/**"],
"html": ["rtl-test.html/**"],
"fetch": ["cors/**"],
"xhr": ["XMLHttpRequest/**"],

"assets": ["fonts/**", "images/**", "media/**", "common/**"],
"css": ["css/tools/**"],
"html": ["rtl-reference.html", "rtl-test.html"],
"idlharness.js": ["resources/idlharness.*", "resources/webidl2/**"],
"infra": [
"css/tools/**",
Expand All @@ -48,21 +47,20 @@ var LABEL_TO_PATTERNS = {
"testharness.js": ["resources/testharness*", "resources/test/**"]
};
var LABEL_TO_REGEXPS = Object.create(null);
var toPathRegExp = function(pattern) { return minimatch.makeRe(pattern); };

for (var key in LABEL_TO_PATTERNS) {
LABEL_TO_REGEXPS[key] = LABEL_TO_PATTERNS[key]
.map(function(pattern) { return minimatch.makeRe(pattern); });
.map(toPathRegExp);
}

function fromFile(filename) {
var matches = function(regexp) { return regexp.test(filename); };
var labels = [];
var matches, label;
var label;

for (label in LABEL_TO_REGEXPS) {
matches = LABEL_TO_REGEXPS[label]
.some(function(regexp) { return regexp.test(filename); });

if (matches) {
if (LABEL_TO_REGEXPS[label].some(matches)) {
labels.push(label);
}
}
Expand Down Expand Up @@ -111,5 +109,5 @@ exports.fromFiles = function(filenames) {
* @returns {Array<string>}
*/
exports.fromWorkingGroups = function labels(workingGroups) {
return workingGroups.map(function(shortname) { return "wg-" + shortname; })
return workingGroups.map(function(shortname) { return "wg-" + shortname; });
};
2 changes: 1 addition & 1 deletion lib/metadata/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var uniq = require('../uniq');

module.exports = function paths(filenames) {
var paths = filenames.map(function(fn) {
return fn.replace(/(?:\/|^)[^/]+$/, "")
return fn.replace(/(?:\/|^)[^/]+$/, "");
});
return uniq(paths).sort();
};
Expand Down
10 changes: 2 additions & 8 deletions lib/metadata/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
var github = require("../github");
var q = require('q');

function promise(value) {
var deferred = q.defer();
deferred.resolve(value);
return deferred.promise;
}

module.exports = function(arg) {
return typeof arg == "string" ? _status(arg) : _statuses(arg);
}
};

function _statuses(handles) {
handles = handles.slice(0);
Expand All @@ -24,7 +18,7 @@ function _statuses(handles) {
_status(handle).then(function(permission) {
output.push({ login: handle, permission: permission });
next();
}, function(err) { deferred.reject(err) });
}, function(err) { deferred.reject(err); });
} else {
deferred.resolve(output);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/metadata/wg.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ module.exports = function wg(specs) {
}
});
return uniq(output);
}
};

4 changes: 2 additions & 2 deletions lib/uniq.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = function uniq(array) {
var output = []
var output = [];
array.forEach(function(item) {
if (output.indexOf(item) < 0) {
output.push(item);
}
});
return output;
};
};
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"description": "A helper bot for web-platform-tests.",
"main": "index.js",
"scripts": {
"test": "mocha -u tdd ./test/setup.js ./test/*.js",
"lint": "jshint lib test",
"test": "npm run lint && npm run test-unit",
"test-unit": "mocha -u tdd ./test/setup.js ./test/*.js",
"start": "node index.js"
},
"dependencies": {
Expand All @@ -19,6 +21,7 @@
},
"devDependencies": {
"chai": "^4.1.2",
"jshint": "^2.9.6",
"mocha": "1.21.4",
"replay": "^2.3.0"
},
Expand Down
4 changes: 4 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../.jshintrc",
"mocha": true
}
6 changes: 3 additions & 3 deletions test/find-owners.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ var assert = require('assert'),


suite('decode META', function() {
var encoded = "R3JhbnQgb2YgTGljZW5zZQotLS0tLS0tLS0tLS0tLS0tCgpCeSBjb250cmli\ndXRpbmcgdG8gdGhpcyByZXBvc2l0b3J5LCB5b3UgYW5kIHRoZSBjb21wYW55\nIHlvdSByZXByZXNlbnQsIGlmIHRoZQpjb21wYW55IGhvbGRzIGFueSBjb3B5\ncmlnaHRzIGluIHRoZSBjb250cmlidXRpb24sIGdyYW50IHRvIHRoZSBXM0Mg\nYSBwZXJwZXR1YWwsCm5vbi1leGNsdXNpdmUsIHJveWFsdHktZnJlZSwgd29y\nbGQtd2lkZSByaWdodCBhbmQgbGljZW5zZSB1bmRlciBhbGwgb2YgeW91cgpj\nb3B5cmlnaHRzIGluIHRoaXMgY29udHJpYnV0aW9uIHRvIGNvcHksIHB1Ymxp\nc2gsIHVzZSwgYW5kIG1vZGlmeSB0aGUKY29udHJpYnV0aW9uIGFuZCB0byBk\naXN0cmlidXRlIHRoZSBjb250cmlidXRpb24gdW5kZXIgYSBCU0QgTGljZW5z\nZSBvciBvbmUgd2l0aAptb3JlIHJlc3RyaWN0aXZlIHRlcm1zLCBhcyB3ZWxs\nIGFzIGEgcmlnaHQgYW5kIGxpY2Vuc2Ugb2YgdGhlIHNhbWUgc2NvcGUgdG8g\nYW55CmRlcml2YXRpdmUgd29ya3MgcHJlcGFyZWQgYnkg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FibGUgZm9yIGFueSBwdXJwb3NlLiBXZSBtYWtlIG5vIHJlcHJlc2Vu\ndGF0aW9ucywgZXhwcmVzcyBvciBpbXBsaWVkLCB0aGF0CnRoZSBjb250ZW50\nIG9mIHRoaXMgcmVwb3NpdG9yeSBvciB0aGUgdXNlIHRoZXJlb2YgaW5kaWNh\ndGVzIGNvbmZvcm1hbmNlIHRvIGEKc3BlY2lmaWNhdGlvbi4gQWxsIGNvbnRl\nbnQgaXMgcHJvdmlkZWQgYXMtaXMgdG8gaGVscCByZWFjaCBpbnRlcm9wZXJh\nYmlsaXR5Lgo=\n"
var decoded = "Grant of License\n----------------\n\nBy contributing to this repository, you and the company you represent, if the\ncompany holds any copyrights in the contribution, grant to the W3C a perpetual,\nnon-exclusive, royalty-free, world-wide right and license under all of your\ncopyrights in this contribution to copy, publish, use, and modify the\ncontribution and to distribute the contribution under a BSD License or one with\nmore restrictive terms, as well as a right and license of the same scope to any\nderivative works prepared by the W3C and based on or incorporating all or part\nof the contribution. You further agree that any derivative works of this\ncontribution prepared by the W3C shall be solely owned by the W3C.\n\nYou state, to the best of your knowledge, that you, or the company you\nrepresent, have all rights necessary to contribute the materials.\n\nW3C will retain attribution of initial authorship to you. The W3C makes no\na-priori commitment to support or distribute contributions.\n\nDisclaimer\n----------\n\nAll content from this repository is provided as is, and W3C makes no\nrepresentations or warranties, express or implied, including, but not limited\nto, warranties of merchantability, fitness for a particular purpose,\nnon-infringement, or title; nor that the contents of this repository are\nsuitable for any purpose. We make no representations, express or implied, that\nthe content of this repository or the use thereof indicates conformance to a\nspecification. All content is provided as-is to help reach interoperability.\n"
var encoded = "R3JhbnQgb2YgTGljZW5zZQotLS0tLS0tLS0tLS0tLS0tCgpCeSBjb250cmli\ndXRpbmcgdG8gdGhpcyByZXBvc2l0b3J5LCB5b3UgYW5kIHRoZSBjb21wYW55\nIHlvdSByZXByZXNlbnQsIGlmIHRoZQpjb21wYW55IGhvbGRzIGFueSBjb3B5\ncmlnaHRzIGluI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QyBtYWtlcyBubwphLXByaW9yaSBjb21t\naXRtZW50IHRvIHN1cHBvcnQgb3IgZGlzdHJpYnV0ZSBjb250cmlidXRpb25z\nLgoKRGlzY2xhaW1lcgotLS0tLS0tLS0tCgpBbGwgY29udGVudCBmcm9tIHRo\naXMgcmVwb3NpdG9yeSBpcyBwcm92aWRlZCBhcyBpcywgYW5kIFczQyBtYWtl\ncyBubwpyZXByZXNlbnRhdGlvbnMgb3Igd2FycmFudGllcywgZXhwcmVzcyBv\nciBpbXBsaWVkLCBpbmNsdWRpbmcsIGJ1dCBub3QgbGltaXRlZAp0bywgd2Fy\ncmFudGllcyBvZiBtZXJjaGFudGFiaWxpdHksIGZpdG5lc3MgZm9yIGEgcGFy\ndGljdWxhciBwdXJwb3NlLApub24taW5mcmluZ2VtZW50LCBvciB0aXRsZTsg\nbm9yIHRoYXQgdGhlIGNvbnRlbnRzIG9mIHRoaXMgcmVwb3NpdG9yeSBhcmUK\nc3VpdGFibGUgZm9yIGFueSBwdXJwb3NlLiBXZSBtYWtlIG5vIHJlcHJlc2Vu\ndGF0aW9ucywgZXhwcmVzcyBvciBpbXBsaWVkLCB0aGF0CnRoZSBjb250ZW50\nIG9mIHRoaXMgcmVwb3NpdG9yeSBvciB0aGUgdXNlIHRoZXJlb2YgaW5kaWNh\ndGVzIGNvbmZvcm1hbmNlIHRvIGEKc3BlY2lmaWNhdGlvbi4gQWxsIGNvbnRl\nbnQgaXMgcHJvdmlkZWQgYXMtaXMgdG8gaGVscCByZWFjaCBpbnRlcm9wZXJh\nYmlsaXR5Lgo=\n";
var decoded = "Grant of License\n----------------\n\nBy contributing to this repository, you and the company you represent, if the\ncompany holds any copyrights in the contribution, grant to the W3C a perpetual,\nnon-exclusive, royalty-free, world-wide right and license under all of your\ncopyrights in this contribution to copy, publish, use, and modify the\ncontribution and to distribute the contribution under a BSD License or one with\nmore restrictive terms, as well as a right and license of the same scope to any\nderivative works prepared by the W3C and based on or incorporating all or part\nof the contribution. You further agree that any derivative works of this\ncontribution prepared by the W3C shall be solely owned by the W3C.\n\nYou state, to the best of your knowledge, that you, or the company you\nrepresent, have all rights necessary to contribute the materials.\n\nW3C will retain attribution of initial authorship to you. The W3C makes no\na-priori commitment to support or distribute contributions.\n\nDisclaimer\n----------\n\nAll content from this repository is provided as is, and W3C makes no\nrepresentations or warranties, express or implied, including, but not limited\nto, warranties of merchantability, fitness for a particular purpose,\nnon-infringement, or title; nor that the contents of this repository are\nsuitable for any purpose. We make no representations, express or implied, that\nthe content of this repository or the use thereof indicates conformance to a\nspecification. All content is provided as-is to help reach interoperability.\n";

test('decode base64 encoded content', function() {
assert.equal(findOwners.decode(encoded), decoded);
Expand Down Expand Up @@ -46,7 +46,7 @@ suite('integration', function() {

assert.deepEqual(reviewers, [
'AmeliaBR', 'annevk', 'fserb', 'jdashg', 'kenrussell'
])
]);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var path = require('path');

var replay = require('replay');

replay.fixtures = path.join(__dirname, 'fixtures')
replay.fixtures = path.join(__dirname, 'fixtures');

// Remove the "Authorization" header so the fixture data can be used in the
// absence of a valid API token.
Expand Down

0 comments on commit a56b669

Please sign in to comment.