chore(lint): #42 jscs and eslint fixes

This commit is contained in:
Olivier Yiptong 2016-02-08 16:01:42 -05:00
Родитель a3abc9ea3c
Коммит 2169c07121
23 изменённых файлов: 117 добавлений и 91 удалений

Просмотреть файл

@ -1,5 +1,4 @@
data/content/
logs/
test/
node_modules/
firefox/

Просмотреть файл

@ -14,7 +14,7 @@
"object-curly-spacing": [2, "never"],
"computed-property-spacing": [2, "never"],
"array-bracket-spacing": [2, "never"],
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
"space-before-function-paren": [2, {"anonymous": "never", "named": "never"}],
"react/jsx-uses-react": 1,
"no-trailing-spaces": [2, {"skipBlankLines": false}],
},

9
.jscsrc Normal file
Просмотреть файл

@ -0,0 +1,9 @@
{
"preset": "google",
"fileExtensions": [".js", ".jsm"],
"excludeFiles": ["test/lib/httpd.js", "test/test-httpd.js", "logs/**", "node_modules/**", "data/content/**"],
"maximumLineLength": false,
"esnext": true,
"validateQuoteMarks": true,
"requireCamelCaseOrUpperCaseIdentifiers": null
}

Просмотреть файл

@ -2,11 +2,11 @@
const ActionManager = require("../lib/ActionManager");
const am = new ActionManager([
'TOP_FRECENT_SITES_REQUEST',
'TOP_FRECENT_SITES_RESPONSE',
'RECEIVE_PLACES_CHANGES',
'RECENT_BOOKMARKS_REQUEST',
'RECENT_BOOKMARKS_RESPONSE',
"TOP_FRECENT_SITES_REQUEST",
"TOP_FRECENT_SITES_RESPONSE",
"RECEIVE_PLACES_CHANGES",
"RECENT_BOOKMARKS_REQUEST",
"RECENT_BOOKMARKS_RESPONSE",
]);
function Response(type, data, options = {}) {

Просмотреть файл

@ -37,17 +37,25 @@ class ActionManager {
}
validateStandardForm(action) {
if (!action) throw new Error('Looks like your action definition does not return an object.');
if (!action.type) throw new Error(`You must define a type for an action.`);
if (!action) {
throw new Error("Looks like your action definition does not return an object.");
}
if (!action.type) {
throw new Error(`You must define a type for an action.`);
}
Object.keys(action).forEach(key => {
if (!VALID_KEYS.has(key)) throw new Error(`${key} is not a standard action key. Should be one of ${VALID_KEYS_STRING}`);
if (!VALID_KEYS.has(key)) {
throw new Error(`${key} is not a standard action key. Should be one of ${VALID_KEYS_STRING}`);
}
});
return action;
// TODO schema validation
}
validateType(action = {}) {
if (!this._types.has(action.type)) throw new Error(`${action.type} is not defined in your ActionManager`);
if (!this._types.has(action.type)) {
throw new Error(`${action.type} is not defined in your ActionManager`);
}
return action;
}
};

Просмотреть файл

@ -5,8 +5,12 @@ const DEFAULT_OPTIONS = {
class Channel {
constructor(options = {}) {
if (!options.incoming) throw new Error("You must specify an incoming event name with the 'incoming' option.");
if (!options.outgoing) throw new Error("You must specify an outgoing event name with the 'outgoing' option.");
if (!options.incoming) {
throw new Error("You must specify an incoming event name with the 'incoming' option.");
}
if (!options.outgoing) {
throw new Error("You must specify an outgoing event name with the 'outgoing' option.");
}
this.options = Object.assign({}, DEFAULT_OPTIONS, options);
this.callbacks = new Set();
this.timeouts = new Map();
@ -42,7 +46,7 @@ class Channel {
}
get middleware() {
return store => next => function (action) {
return store => next => function(action) {
const meta = action.meta || {};
const timeouts = this.timeouts;
@ -74,8 +78,7 @@ class Channel {
if (meta.broadcast === this.options.outgoing) {
this.broadcast(action);
}
}.bind(this);
}.bind(this);
}
}

Просмотреть файл

@ -64,19 +64,19 @@ const fakeBookmarks = [
function dispatch(action) {
window.dispatchEvent(
new CustomEvent('addon-to-content', {detail: action})
new CustomEvent("addon-to-content", {detail: action})
);
}
module.exports = function () {
window.addEventListener('content-to-addon', function (event) {
module.exports = function() {
window.addEventListener("content-to-addon", function(event) {
const action = JSON.parse(event.detail);
switch(action.type) {
case 'TOP_FRECENT_SITES_REQUEST':
dispatch({type: 'TOP_FRECENT_SITES_RESPONSE', data: fakeFrecent});
switch (action.type) {
case "TOP_FRECENT_SITES_REQUEST":
dispatch({type: "TOP_FRECENT_SITES_RESPONSE", data: fakeFrecent});
break;
case 'RECENT_BOOKMARKS_REQUEST':
dispatch({type: 'RECENT_BOOKMARKS_RESPONSE', data: fakeBookmarks});
case "RECENT_BOOKMARKS_REQUEST":
dispatch({type: "RECENT_BOOKMARKS_RESPONSE", data: fakeBookmarks});
}
}, false);
};

Просмотреть файл

@ -5,7 +5,7 @@ const {Provider} = require("react-redux");
const Base = require("components/Base/Base");
const store = require("./store");
require('lib/shim')();
require("lib/shim")();
const Root = React.createClass({
render() {

Просмотреть файл

@ -4,7 +4,7 @@ module.exports = {
// This is just placeholder for now
Sites: (prevState = {frecent: [], changes: []}, action) => {
const state = {};
switch(action.type) {
switch (action.type) {
case am.type("TOP_FRECENT_SITES_RESPONSE"):
state.frecent = action.data;
break;
@ -19,7 +19,7 @@ module.exports = {
Bookmarks: (prevState = {rows: [], error: false}, action) => {
const state = {};
switch(action.type) {
switch (action.type) {
case am.type("RECENT_BOOKMARKS_RESPONSE"):
if (action.error) {
state.rows = [];

Просмотреть файл

@ -7,8 +7,10 @@ const TestUtils = require("react-addons-test-utils");
const fakeSites = require("lib/shim").data.fakeBookmarks;
describe("ActivityFeed", function () {
let node, instance, el;
describe("ActivityFeed", function() {
let node;
let instance;
let el;
beforeEach(() => {
node = document.createElement("div");
instance = ReactDOM.render(<ActivityFeed sites={fakeSites} />, node);
@ -29,9 +31,11 @@ describe("ActivityFeed", function () {
});
});
describe("ActivityFeedItem", function () {
describe("ActivityFeedItem", function() {
const fakeSite = fakeSites[0];
let node, instance, el;
let node;
let instance;
let el;
beforeEach(() => {
node = document.createElement("div");
instance = ReactDOM.render(<ActivityFeedItem {...fakeSite} />, node);

Просмотреть файл

@ -9,7 +9,9 @@ const fakeProps = {
describe("Header", () => {
let node, header, el;
let node;
let header;
let el;
beforeEach(() => {
node = document.createElement("div");
header = ReactDOM.render(<Header {...fakeProps} />, node);

Просмотреть файл

@ -19,7 +19,10 @@ const fakeProps = {
describe("TopSites", () => {
let node, topSites, el;
let node;
let topSites;
let el;
beforeEach(() => {
node = document.createElement("div");
topSites = ReactDOM.render(<TopSites {...fakeProps} />, node);

Просмотреть файл

@ -6,9 +6,9 @@ const {assert} = require("chai");
describe("ActionManager", () => {
describe("instance", () => {
if("should throw if types is not an array", () => {
it("should throw if types is not an array", () => {
assert.throws(() => new ActionManager(), "You must instantiate ActionManager with an array of action types.");
})
});
it("should create this._types", () => {
const am = new ActionManager(["FOO", "BAR"]);
assert.deepEqual(am._types, new Set(["FOO", "BAR"]));
@ -21,18 +21,18 @@ describe("ActionManager", () => {
const am = new ActionManager(["FOO", "BAR"]);
assert.isArray(am.validators);
assert.isObject(am.actions);
assert.property(am.actions, 'BaseAction');
assert.property(am.actions, "BaseAction");
});
});
describe("#defineActions", () => {
it('should add actions to this.actions', () => {
it("should add actions to this.actions", () => {
const am = new ActionManager(["FOO", "BAR"]);
am.defineActions({Foo: () => {}});
assert.property(am.actions, 'Foo');
assert.property(am.actions, "Foo");
assert.isFunction(am.actions.Foo);
});
it('should return the result of the action definition', () => {
it("should return the result of the action definition", () => {
const am = new ActionManager(["FOO", "BAR"]);
function Foo(data) {
return {type: "FOO", data};
@ -41,17 +41,17 @@ describe("ActionManager", () => {
const result = am.actions.Foo("data");
assert.deepEqual(result, {type: "FOO", data: "data"});
});
it('should run validations for defined actions', () => {
it("should run validations for defined actions", () => {
const am = new ActionManager(["FOO"]);
am.defineActions({Foo: () => {}, Bar: () => ({type: "BAR"})});
assert.throws(() => {
am.actions.Foo();
}, 'Looks like your action definition does not return an object.');
}, "Looks like your action definition does not return an object.");
assert.throws(() => {
am.actions.Bar();
}, 'BAR is not defined in your ActionManager');
}, "BAR is not defined in your ActionManager");
});
it('should allow validations to be changed after definitions', () => {
it("should allow validations to be changed after definitions", () => {
const am = new ActionManager(["FOO"]);
am.defineActions({Foo: () => {}, Bar: () => ({type: "BAR"})});
am.validators = [];

Просмотреть файл

@ -4,17 +4,17 @@
unsafeWindow.navigator.activity_streams_addon = true;
window.addEventListener('content-to-addon', function (event) {
self.port.emit('content-to-addon', JSON.parse(event.detail));
window.addEventListener("content-to-addon", function(event) {
self.port.emit("content-to-addon", JSON.parse(event.detail));
}, false);
self.port.on('addon-to-content', function (data) {
self.port.on("addon-to-content", function(data) {
const clonedData = cloneInto(data, document.defaultView);
window.dispatchEvent(
new CustomEvent('addon-to-content', {detail: clonedData})
new CustomEvent("addon-to-content", {detail: clonedData})
);
});
window.addEventListener('pagehide', function () {
self.port.emit('content-to-addon', {type: 'pagehide'});
window.addEventListener("pagehide", function() {
self.port.emit("content-to-addon", {type: "pagehide"});
}, false);

Просмотреть файл

@ -1,7 +1,7 @@
const webpack = require("./webpack.config");
const path = require("path");
module.exports = function (config) {
module.exports = function(config) {
config.set({
singleRun: true,
browsers: ["FirefoxNightly"],
@ -43,8 +43,8 @@ module.exports = function (config) {
loaders: webpack.module.loaders,
postLoaders: [{
test: /\.js$/,
loader: 'istanbul-instrumenter',
include: [path.join(__dirname, '/src')]
loader: "istanbul-instrumenter",
include: [path.join(__dirname, "/src")]
}]
},
plugins: webpack.plugins

Просмотреть файл

@ -11,7 +11,7 @@ const am = require("content-src/actions/action-manager");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource:///modules/NewTabURL.jsm");
XPCOMUtils.defineLazyGetter(this, "EventEmitter", function () {
XPCOMUtils.defineLazyGetter(this, "EventEmitter", function() {
const {EventEmitter} = Cu.import("resource://devtools/shared/event-emitter.js", {});
return EventEmitter;
});
@ -61,7 +61,6 @@ ActivityStreams.prototype = {
});
},
/**
* Broadcast places changes to pages
*/

Просмотреть файл

@ -2,12 +2,12 @@
"use strict";
const {Ci, Cu} = require('chrome');
const {Ci, Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyGetter(this, "EventEmitter", function () {
XPCOMUtils.defineLazyGetter(this, "EventEmitter", function() {
const {EventEmitter} = Cu.import("resource://devtools/shared/event-emitter.js", {});
return EventEmitter;
});
@ -18,7 +18,7 @@ XPCOMUtils.defineLazyModuleGetter(this, "Task",
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
XPCOMUtils.defineLazyGetter(this, "gPrincipal", function () {
XPCOMUtils.defineLazyGetter(this, "gPrincipal", function() {
let uri = Services.io.newURI("about:newtab", null, null);
return Services.scriptSecurityManager.getNoAppCodebasePrincipal(uri);
});
@ -69,7 +69,6 @@ let Links = function Links() {
EventEmitter.decorate(this);
};
Links.prototype = {
/**
* A set of functions called by @mozilla.org/browser/nav-historyservice
@ -136,7 +135,8 @@ Links.prototype = {
/**
* Gets the top frecent sites.
*
* @param options.limit {Integer} Maximum number of results to return. Max 100.
* @param {Integer} options
* limit: Maximum number of results to return. Max 100.
*
* @returns {Promise} Returns a promise with the array of links as payload.
*/

Просмотреть файл

@ -19,7 +19,7 @@ Object.assign(exports, {
},
onUnload(reason) {
if(exports.app) {
if (exports.app) {
exports.app.unload(reason);
}
PlacesProvider.links.uninit();

Просмотреть файл

@ -43,6 +43,7 @@
"husky": "^0.10.2",
"istanbul-instrumenter-loader": "^0.1.3",
"jpm": "^1.0.5",
"jscs": "^2.9.0",
"json-loader": "^0.5.4",
"karma": "^0.13.19",
"karma-chai": "^0.1.0",
@ -80,7 +81,7 @@
"start:server": "live-server data/content --port=1963 --no-browser",
"firefox": "jpm run -b nightly",
"test": "npm-run-all test:*",
"test:lint": "eslint .",
"test:lint": "eslint . && jscs .",
"test:jpm": "jpm test -b nightly",
"test:karma": "karma start",
"tdd": "karma start --no-single-run",

Просмотреть файл

@ -1,6 +1,7 @@
/* globals XPCOMUtils, Task, PlacesUtils, Services */
"use strict";
const {Cc, Ci, Cu, components} = require("chrome");
const {Ci, Cu, components} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
@ -9,12 +10,11 @@ Cu.import("resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm");
const PlacesTestUtils = Object.freeze({
/**
* Asynchronously adds visits to a page.
*
* @param aPlaceInfo
* @param {nsIURI} placeInfo
* Can be an nsIURI, in such a case a single LINK visit will be added.
* Otherwise can be an object describing the visit to add, or an array
* of these objects:
@ -26,19 +26,18 @@ const PlacesTestUtils = Object.freeze({
* }
*
* @return {Promise}
* @resolves When all visits have been added successfully.
* @rejects JavaScript exception.
* resolves When all visits have been added successfully.
* rejects JavaScript exception.
*/
addVisits: Task.async(function*(placeInfo) {
let promise = new Promise((resolve, reject) => {
let places = [];
if (placeInfo instanceof Ci.nsIURI) {
places.push({ uri: placeInfo });
}
else if (Array.isArray(placeInfo)) {
places.push({uri: placeInfo});
} else if (Array.isArray(placeInfo)) {
places = places.concat(placeInfo);
} else {
places.push(placeInfo)
places.push(placeInfo);
}
// Create mozIVisitInfo for each entry.
@ -58,12 +57,12 @@ const PlacesTestUtils = Object.freeze({
PlacesUtils.asyncHistory.updatePlaces(
places,
{
handleError: function AAV_handleError(resultCode, placeInfo) {
let ex = new Components.Exception("Unexpected error in adding visits.",
handleError: function AAV_handleError(resultCode, placeInfo) { // eslint-disable-line no-unused-vars
let ex = new components.Exception("Unexpected error in adding visits.",
resultCode);
reject(ex);
},
handleResult: function () {},
handleResult: function() {},
handleCompletion: function UP_handleCompletion() {
resolve();
}
@ -77,12 +76,12 @@ const PlacesTestUtils = Object.freeze({
* Clear all history.
*
* @return {Promise}
* @resolves When history was cleared successfully.
* @rejects JavaScript exception.
* resolves When history was cleared successfully.
* rejects JavaScript exception.
*/
clearHistory() {
let expirationFinished = new Promise(resolve => {
Services.obs.addObserver(function observe(subj, topic, data) {
Services.obs.addObserver(function observe(subj, topic, data) { // eslint-disable-line no-unused-vars
Services.obs.removeObserver(observe, topic);
resolve();
}, PlacesUtils.TOPIC_EXPIRATION_FINISHED, false);

Просмотреть файл

@ -1,8 +1,9 @@
/* globals XPCOMUtils, NetUtil, PlacesUtils */
"use strict";
const {PlacesProvider} = require("lib/PlacesProvider");
const {PlacesTestUtils} = require("./lib/PlacesTestUtils");
const {Cc, Ci, Cu, components} = require("chrome");
const {Ci, Cu} = require("chrome");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@ -12,8 +13,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
XPCOMUtils.defineLazyModuleGetter(this, "NetUtil",
"resource://gre/modules/NetUtil.jsm");
exports.test_LinkChecker_securityCheck = function(assert, done) {
let urls = [
exports.test_LinkChecker_securityCheck = function(assert) {
let urls = [
{url: "file://home/file/image.png", expected: false},
{url: "resource:///modules/PlacesProvider.jsm", expected: false},
{url: "javascript:alert('hello')", expected: false}, // jshint ignore:line
@ -26,10 +27,9 @@ exports.test_LinkChecker_securityCheck = function(assert, done) {
let observed = PlacesProvider.LinkChecker.checkLoadURI(url);
assert.equal(observed, expected, `can load "${url}"?`);
}
done();
};
exports.test_Links_getTopFrecentSites = function(assert, done) {
exports.test_Links_getTopFrecentSites = function*(assert) {
yield PlacesTestUtils.clearHistory();
let provider = PlacesProvider.links;
@ -45,7 +45,7 @@ exports.test_Links_getTopFrecentSites = function(assert, done) {
assert.equal(links[0].url, testURI.spec, "added visit corresponds to added url");
};
exports.test_Links_getTopFrecentSites_Order = function(assert, done) {
exports.test_Links_getTopFrecentSites_Order = function*(assert) {
yield PlacesTestUtils.clearHistory();
let provider = PlacesProvider.links;
let {
@ -83,7 +83,7 @@ exports.test_Links_getTopFrecentSites_Order = function(assert, done) {
}
};
exports.test_Links_onLinkChanged = function(assert, done) {
exports.test_Links_onLinkChanged = function*(assert) {
let provider = PlacesProvider.links;
provider.init();
assert.equal(true, true);
@ -120,7 +120,7 @@ exports.test_Links_onLinkChanged = function(assert, done) {
provider.uninit();
};
exports.test_Links_onClearHistory = function(assert, done) {
exports.test_Links_onClearHistory = function*(assert) {
let provider = PlacesProvider.links;
provider.init();
@ -144,7 +144,7 @@ exports.test_Links_onClearHistory = function(assert, done) {
provider.uninit();
};
exports.test_Links_onDeleteURI = function(assert, done) {
exports.test_Links_onDeleteURI = function*(assert) {
let provider = PlacesProvider.links;
provider.init();
@ -167,7 +167,7 @@ exports.test_Links_onDeleteURI = function(assert, done) {
provider.uninit();
};
exports.test_Links_onManyLinksChanged = function(assert, done) {
exports.test_Links_onManyLinksChanged = function*(assert) {
let provider = PlacesProvider.links;
provider.init();

Просмотреть файл

@ -7,20 +7,19 @@ const httpd = require("./lib/httpd");
const {doGetFile} = require("./lib/utils");
const {Task} = require("resource://gre/modules/Task.jsm", {});
const PORT = 8099;
exports["test messages"] = function (assert, done) {
exports["test messages"] = function(assert, done) {
let path = "/dummy-activitystreams.html";
let url = `http://localhost:${PORT}${path}`;
let srv = httpd.startServerAsync(PORT, null, doGetFile("test/resources"));
Task.spawn(function* () {
Task.spawn(function*() {
let app = new ActivityStreams({pageURL: url});
let openTabs = [];
tabs.on("open", tab => {
tab.on('ready', tab => {
tab.on("ready", tab => {
if (tab.url === url) {
openTabs.push(tab);
}

Просмотреть файл

@ -25,7 +25,7 @@ scripts:
# test: Run all tests once
test:
# test:lint: Run eslint
lint: eslint .
lint: eslint . && jscs .
# test:jpm: Run jpm tests
jpm: jpm test -b nightly
# test:karma: Run content tests only