chore(lint): Enable arrow-body-style as-needed.

This commit is contained in:
Ed Lee 2016-08-09 18:35:51 -07:00
Родитель 9d984383bc
Коммит 22bb5648d7
16 изменённых файлов: 103 добавлений и 136 удалений

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

@ -57,6 +57,7 @@
"accessor-pairs": [2, {"setWithoutGet": true, "getWithoutSet": false}],
"array-bracket-spacing": [2, "never"],
"array-callback-return": 2,
"arrow-body-style": [2, "as-needed"],
"arrow-parens": [2, "as-needed"],
"arrow-spacing": 2,
"block-scoped-var": 2,

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

@ -171,19 +171,17 @@ const GroupedActivityFeed = React.createClass({
let maxPreviews = this.props.maxPreviews;
const sites = this.props.sites
.slice(0, this.props.length)
.map(site => {
return Object.assign({}, site, {dateDisplay: site[this.props.dateKey]});
});
.map(site => Object.assign({}, site, {dateDisplay: site[this.props.dateKey]}));
const groupedSites = groupSitesByDate(sites);
let globalCount = -1;
return (<div className="grouped-activity-feed">
{Array.from(groupedSites.keys()).map((date, dateIndex) => {
return (<div className="group" key={date}>
{Array.from(groupedSites.keys()).map((date, dateIndex) =>
(<div className="group" key={date}>
{this.props.showDateHeadings &&
<h3 className="section-title">{moment(date).startOf("day").calendar(null, CALENDAR_HEADINGS)}</h3>
}
{groupedSites.get(date).map((sites, outerIndex) => {
return (<ul key={`${date}-${outerIndex}`} className="activity-feed">
{groupedSites.get(date).map((sites, outerIndex) =>
(<ul key={`${date}-${outerIndex}`} className="activity-feed">
{sites.map((site, i) => {
globalCount++;
let preview = null;
@ -210,10 +208,10 @@ const GroupedActivityFeed = React.createClass({
preview={preview}
{...site} />);
})}
</ul>);
})}
</div>);
})}
</ul>)
)}
</div>)
)}
</div>);
}
});

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

@ -63,18 +63,16 @@ const DebugPage = React.createClass({
<div className="form-group">
<label>Data Source</label>
<select value={this.state.dataSource} onChange={e => this.setState({dataSource: e.target.value})}>
{Object.keys(this.props.raw).map(source => {
return (<option key={source} value={source}>{source}</option>);
})}
{Object.keys(this.props.raw).map(source => (<option key={source} value={source}>{source}</option>))}
</select>
</div>
</div>
<div>
{this.state.component === "Spotlight" &&
<div className="spotlight">
{selectSpotlight({Highlights: this.props.raw[this.state.dataSource]}).rows.map((item, i) => {
return (<SpotlightItem key={i} {...item} />);
})}
{selectSpotlight({Highlights: this.props.raw[this.state.dataSource]}).rows.map((item, i) =>
(<SpotlightItem key={i} {...item} />))
}
</div>
}
{this.state.component === "TopSites" &&
@ -101,11 +99,9 @@ const DebugPage = React.createClass({
}
});
module.exports = connect(state => {
return {
newTab: selectNewTabSites(state),
raw: state
};
})(DebugPage);
module.exports = connect(state => ({
newTab: selectNewTabSites(state),
raw: state
}))(DebugPage);
module.exports.DebugPage = DebugPage;

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

@ -26,14 +26,14 @@ const TimelinePage = React.createClass({
<main className="timeline">
<nav className="sidebar" onScroll={this.onScroll}>
<ul>
{navItems.map(item => {
return (<li key={item.to}>
{navItems.map(item =>
(<li key={item.to}>
<Link to={item.to} className={classNames({active: item.to === pathname})}>
<span className={`icon icon-${item.icon}`} />
<span className="link-title">{item.title}</span>
</Link>
</li>);
})}
</li>)
)}
</ul>
</nav>
{this.props.children}

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

@ -20,6 +20,4 @@ moment.updateLocale("en", {
}
});
module.exports = unixTimestamp => {
return moment(unixTimestamp).fromNow();
};
module.exports = unixTimestamp => moment(unixTimestamp).fromNow();

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

@ -15,15 +15,13 @@ module.exports = function() {
case "TOP_FRECENT_SITES_REQUEST":
dispatch({
type: "TOP_FRECENT_SITES_RESPONSE",
data: fakeData.TopSites.rows.map(site => {
return Object.assign({}, site, { // eslint-disable-line object-curly-newline
data: fakeData.TopSites.rows.map(site => Object.assign({}, site, { // eslint-disable-line object-curly-newline
// images: [],
// favicon: null,
// favicon_url: null,
// favicon_colors: null,
// description: null
}); // eslint-disable-line object-curly-newline
})
})) // eslint-disable-line object-curly-newline
});
break;
case "RECENT_BOOKMARKS_REQUEST":

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

@ -83,13 +83,11 @@ const selectTopSites = module.exports.selectTopSites = createSelector(
[
state => state.TopSites
],
TopSites => {
return Object.assign({}, TopSites, {
rows: dedupe.one(TopSites.rows
// Add first run stuff to the end if init has already happened
.concat(TopSites.init ? firstRunData.TopSites : []))
});
}
TopSites => Object.assign({}, TopSites, {
rows: dedupe.one(TopSites.rows
// Add first run stuff to the end if init has already happened
.concat(TopSites.init ? firstRunData.TopSites : []))
})
);
module.exports.selectNewTabSites = createSelector(
@ -181,12 +179,10 @@ module.exports.selectHistory = createSelector(
selectSpotlight,
state => state.History
],
(Spotlight, History) => {
return {
Spotlight: Object.assign({}, Spotlight, {rows: dedupe.one(Spotlight.rows)}),
History
};
}
(Spotlight, History) => ({
Spotlight: Object.assign({}, Spotlight, {rows: dedupe.one(Spotlight.rows)}),
History
})
);
// Timeline Bookmarks

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

@ -160,14 +160,13 @@ describe("GroupedActivityFeed", () => {
});
describe("maxPreviews", () => {
const sites = ["lDv68xYHFXM", "xDv68xYHFXM", "1Dv68xYHFXM", "0Dv68xYHFXM"].map(url => {
return faker.createSite({
const sites = ["lDv68xYHFXM", "xDv68xYHFXM", "1Dv68xYHFXM", "0Dv68xYHFXM"].map(url =>
faker.createSite({
override: {
url: `https://www.youtube.com/watch?v=${url}`,
media: {type: "video"}
}
});
});
}));
it("should create previews for all items by default", () => {
const feed = renderWithProvider(<GroupedActivityFeed sites={sites} />);
const previews = TestUtils.scryRenderedComponentsWithType(feed, MediaPreview);

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

@ -5,9 +5,7 @@ const {selectSpotlight} = require("selectors/selectors");
const BASE_TIP_TOP_FAVICON_URL = "favicons/images/";
faker.timestamp = () => {
return moment().unix();
};
faker.timestamp = () => moment().unix();
faker.internet.rgbColor = () => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(faker.internet.color());

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

@ -401,7 +401,7 @@ MetadataStore.prototype = {
* Returns a promise with the array of retrieved metadata records
*/
asyncGetMetadataByCacheKey: Task.async(function*(cacheKeys) {
const quoted = cacheKeys.map(key => {return `'${key}'`;}).join(",");
const quoted = cacheKeys.map(key => `'${key}'`).join(",");
let metaObjects;
try {
metaObjects = yield this.asyncExecuteQuery(

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

@ -147,17 +147,15 @@ PreviewProvider.prototype = {
*/
_getFaviconColors(links) {
return Promise.all(
links.map(link => {
return new Promise(resolve => {
if (!link.favicon) {
return resolve(link);
}
getColor(link.favicon)
.then(color => {
resolve(Object.assign({}, link, {favicon_color: color}));
}, () => resolve(link));
});
links.map(link => new Promise(resolve => {
if (!link.favicon) {
return resolve(link);
}
getColor(link.favicon).then(color => {
resolve(Object.assign({}, link, {favicon_color: color}));
}, () => resolve(link));
})
)
);
},
@ -170,9 +168,8 @@ PreviewProvider.prototype = {
this._asyncSaveLinks(processedLinks, event);
}
return this._asyncGetEnhancedLinks(processedLinks, previewsOnly, event).then(cachedLinks => {
return this._getFaviconColors(cachedLinks);
});
return this._asyncGetEnhancedLinks(processedLinks, previewsOnly, event).then(
cachedLinks => this._getFaviconColors(cachedLinks));
},
/**

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

@ -4,35 +4,31 @@
const {Cu} = require("chrome");
Cu.import("resource://gre/modules/Services.jsm");
let makeCachePromise = name => {
return new Promise(resolve => {
let precacheNotif = `activity-streams-${name}-cache-complete`;
let waitForCache = (subject, topic, data) => {
if (topic === precacheNotif) {
Services.obs.removeObserver(waitForCache, precacheNotif);
resolve();
}
};
Services.obs.addObserver(waitForCache, precacheNotif, false);
});
};
let makeCachePromise = name => new Promise(resolve => {
let precacheNotif = `activity-streams-${name}-cache-complete`;
let waitForCache = (subject, topic, data) => {
if (topic === precacheNotif) {
Services.obs.removeObserver(waitForCache, precacheNotif);
resolve();
}
};
Services.obs.addObserver(waitForCache, precacheNotif, false);
});
let makeCountingCachePromise = (name, target) => {
return new Promise(resolve => {
let count = 0;
let precacheNotif = `activity-streams-${name}-cache-complete`;
let waitForCache = (subject, topic, data) => {
if (topic === precacheNotif) {
count++;
if (count === target) {
Services.obs.removeObserver(waitForCache, precacheNotif);
resolve(count);
}
let makeCountingCachePromise = (name, target) => new Promise(resolve => {
let count = 0;
let precacheNotif = `activity-streams-${name}-cache-complete`;
let waitForCache = (subject, topic, data) => {
if (topic === precacheNotif) {
count++;
if (count === target) {
Services.obs.removeObserver(waitForCache, precacheNotif);
resolve(count);
}
};
Services.obs.addObserver(waitForCache, precacheNotif, false);
});
};
}
};
Services.obs.addObserver(waitForCache, precacheNotif, false);
});
exports.makeCachePromise = makeCachePromise;
exports.makeCountingCachePromise = makeCountingCachePromise;

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

@ -29,32 +29,30 @@ let gApp;
let gAppURL;
let gInitialCachePref = simplePrefs.prefs["query.cache"];
let makeNotifsPromise = cacheStatus => {
return new Promise(resolve => {
let notifSet = new Set([
"getTopFrecentSites-cache",
"getRecentBookmarks-cache",
"getRecentLinks-cache",
"getHighlightsLinks-cache"
]);
let notifCount = 0;
let observer = function(subject, topic, data) {
if (notifSet.has(topic) && data === cacheStatus) {
notifCount++;
}
if (notifCount === notifSet.size) {
for (let notif of notifSet) {
Services.obs.removeObserver(observer, notif);
}
resolve(notifCount);
}
};
for (let notif of notifSet) {
Services.obs.addObserver(observer, notif, false);
let makeNotifsPromise = cacheStatus => new Promise(resolve => {
let notifSet = new Set([
"getTopFrecentSites-cache",
"getRecentBookmarks-cache",
"getRecentLinks-cache",
"getHighlightsLinks-cache"
]);
let notifCount = 0;
let observer = function(subject, topic, data) {
if (notifSet.has(topic) && data === cacheStatus) {
notifCount++;
}
});
};
if (notifCount === notifSet.size) {
for (let notif of notifSet) {
Services.obs.removeObserver(observer, notif);
}
resolve(notifCount);
}
};
for (let notif of notifSet) {
Services.obs.addObserver(observer, notif, false);
}
});
exports["test caching follows prefs"] = function*(assert) {
let tabList = [];

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

@ -9,9 +9,7 @@ let gMemoizer;
exports.test_memoizer = function*(assert) {
let count = 0;
let testFunc = () => {
return ++count;
};
let testFunc = () => ++count;
let func = gMemoizer.memoize("testKey", testFunc);
let result;
@ -31,9 +29,7 @@ exports.test_memoizer = function*(assert) {
exports.test_memoizer_replace_opt = function*(assert) {
let count = 0;
let testFunc = () => {
return ++count;
};
let testFunc = () => ++count;
let func = gMemoizer.memoize("testKey", testFunc);
let result;
@ -52,9 +48,7 @@ exports.test_memoizer_replace_opt = function*(assert) {
exports.test_memoizer_replace_opt_sub_key = function*(assert) {
let count = 0;
let testFunc = () => {
return ++count;
};
let testFunc = () => ++count;
let func = gMemoizer.memoize("testKey", testFunc);
let result;
@ -74,9 +68,7 @@ exports.test_memoizer_replace_opt_sub_key = function*(assert) {
exports.test_memoizer_prefs = function*(assert) {
simplePrefs.prefs["query.cache"] = false;
let count = 0;
let testFunc = () => {
return ++count;
};
let testFunc = () => ++count;
let func = gMemoizer.memoize("testKey", testFunc);
let result;

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

@ -169,7 +169,7 @@ exports.test_async_get_by_cache_key = function*(assert) {
assert.equal(metaObject.images.length, fixture.images.length, "It should fetch one favicon");
}
let cacheKeys = metadataFixture.map(fixture => {return fixture.cache_key;});
let cacheKeys = metadataFixture.map(fixture => fixture.cache_key);
let metaObjects = yield gMetadataStore.asyncGetMetadataByCacheKey(cacheKeys);
assert.equal(metaObjects.length, metadataFixture.length, "It should fetch all metadata records");
};
@ -177,7 +177,7 @@ exports.test_async_get_by_cache_key = function*(assert) {
exports.test_async_get_by_cache_key_in_special_cases = function*(assert) {
yield gMetadataStore.asyncInsert(metadataFixture);
let cacheKeys = metadataFixture.map(fixture => {return fixture.cache_key;});
let cacheKeys = metadataFixture.map(fixture => fixture.cache_key);
let metaObjects = yield gMetadataStore.asyncGetMetadataByCacheKey(
cacheKeys.concat("missing-key1", "missing-key2"));
assert.equal(metaObjects.length, metadataFixture.length,
@ -213,7 +213,7 @@ exports.test_on_an_invalid_connection = function*(assert) {
}
assert.ok(error, "It should raise exception if the connection is closed or not established");
let cacheKeys = metadataFixture.map(fixture => {return fixture.cache_key;});
let cacheKeys = metadataFixture.map(fixture => fixture.cache_key);
let metaObjects = yield gMetadataStore.asyncGetMetadataByCacheKey(cacheKeys);
assert.equal(metaObjects.length, 0, "It should return an empty array if the connection is closed or not established");
};

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

@ -58,7 +58,7 @@ exports.test_update_recommendations = function*(assert) {
// start the timer to update the data and wait for it to trigger
gRecommendationProvider._asyncUpdateRecommendations(100);
yield waitUntil(() => {return true;}, 1000);
yield waitUntil(() => true, 1000);
// check that the recommendations got updated
assert.equal(gRecommendationProvider._recommendedContent.length, 4, "updated the recommended content to 4 recommendations");