Skip to content

Commit

Permalink
Cleaning the linted code
Browse files Browse the repository at this point in the history
  • Loading branch information
reficul31 committed Apr 1, 2017
1 parent 077573e commit 11a8c52
Show file tree
Hide file tree
Showing 31 changed files with 132 additions and 155 deletions.
8 changes: 4 additions & 4 deletions gulpfile.babel.js
Expand Up @@ -44,7 +44,7 @@ const browserifySettings = {
}

function createBundle({entries, output, destination, cssOutput},
{watch=false, production=false}) {
{watch = false, production = false}) {
let b = watch
? watchify(browserify({...watchify.args, ...browserifySettings, entries}))
.on('update', bundle)
Expand All @@ -54,7 +54,7 @@ function createBundle({entries, output, destination, cssOutput},
NODE_ENV: production ? 'production' : 'development'
}), {global: true})

if(cssOutput) {
if (cssOutput) {
b.plugin(cssModulesify, {
global: true,
output: path.join(destination, cssOutput),
Expand All @@ -71,10 +71,10 @@ function createBundle({entries, output, destination, cssOutput},
function bundle() {
let startTime = new Date().getTime()
b.bundle()
.on('error', error=>console.error(error.message))
.on('error', error => console.error(error.message))
.pipe(source(output))
.pipe(buffer())
.pipe(production ? uglify({output: {ascii_only:true}}) : identity())
.pipe(production ? uglify({output: {ascii_only: true}}) : identity())
.pipe(gulp.dest(destination))
.on('end', () => {
let time = (new Date().getTime() - startTime) / 1000
Expand Down
4 changes: 2 additions & 2 deletions src/activity-logger/background/index.js
Expand Up @@ -3,9 +3,9 @@ import maybeLogPageVisit from './log-page-visit'
// Listen for navigations to log them and analyse the pages.
browser.webNavigation.onCommitted.addListener(({url, tabId, frameId}) => {
// Ignore pages loaded in frames, it is usually noise.
if (frameId !== 0)
if (frameId !== 0) {
return
}

maybeLogPageVisit({url, tabId})

})
4 changes: 2 additions & 2 deletions src/activity-logger/background/log-page-visit.js
Expand Up @@ -19,10 +19,10 @@ export default async function maybeLogPageVisit({
tabId,
url,
}) {

// First check if we want to log this page (hence the 'maybe' in the name).
if (!isWorthRemembering({url}))
if (!isWorthRemembering({url})) {
return
}

// The time to put in documents.
const timestamp = new Date().getTime()
Expand Down
2 changes: 1 addition & 1 deletion src/activity-logger/index.js
Expand Up @@ -14,7 +14,7 @@ const convertAnyTimestampedDocId = docuri.route(':type/:timestamp/:nonce')
export const getTimestamp = doc =>
Number.parseInt(convertAnyTimestampedDocId(doc._id).timestamp)

export function generateVisitDocId({timestamp, nonce}={}) {
export function generateVisitDocId({timestamp, nonce} = {}) {
const date = timestamp ? new Date(timestamp) : new Date()
return convertVisitDocId({
timestamp: date.getTime(),
Expand Down
2 changes: 1 addition & 1 deletion src/background.js
Expand Up @@ -14,7 +14,7 @@ browser.browserAction.onClicked.addListener(() => {
})

browser.commands.onCommand.addListener(command => {
if (command === "openOverview") {
if (command === 'openOverview') {
openOverview()
}
})
5 changes: 2 additions & 3 deletions src/browser-history/background/import-history.js
Expand Up @@ -88,8 +88,7 @@ function convertHistoryToPagesAndVisits({
const referringVisitDocId = referringVisitDoc._id
// Add a reference to the visit document.
visitDoc.referringVisit = {_id: referringVisitDocId}
}
else {
} else {
// Apparently the referring visit is not present in the history.
// We can just pretend that there was no referrer.
}
Expand All @@ -106,7 +105,7 @@ function convertHistoryToPagesAndVisits({
export default async function importHistory({
startTime,
endTime,
}={}) {
} = {}) {
// Get the full history: both the historyItems and visitItems.
console.time('import history')
const historyItems = await getHistoryItems({startTime, endTime})
Expand Down
26 changes: 12 additions & 14 deletions src/omnibar.js
Expand Up @@ -5,10 +5,9 @@ import { filterVisitsByQuery } from 'src/search'
import niceTime from 'src/util/nice-time'


const shortUrl = (url, maxLength=50) => {
const shortUrl = (url, maxLength = 50) => {
url = url.replace(/^https?:\/\//i, '')
if (url.length > maxLength)
url = url.slice(0, maxLength-3) + '...'
if (url.length > maxLength) { url = url.slice(0, maxLength - 3) + '...' }
return url
}

Expand Down Expand Up @@ -50,8 +49,7 @@ async function makeSuggestion(query, suggest) {

// A subsequent search could have already started and finished while we
// were busy searching, so we ensure we do not overwrite its results.
if (currentQuery !== query && latestResolvedQuery !== queryForOldSuggestions)
return
if (currentQuery !== query && latestResolvedQuery !== queryForOldSuggestions) { return }

if (visitDocs.length === 0) {
browser.omnibox.setDefaultSuggestion({
Expand All @@ -71,15 +69,15 @@ async function makeSuggestion(query, suggest) {
const acceptInput = (text, disposition) => {
// TODO if text is not a suggested URL, open the overview with this query.
switch (disposition) {
case 'currentTab':
browser.tabs.update({url: text})
break
case 'newForegroundTab':
browser.tabs.create({url: text})
break
case 'newBackgroundTab':
browser.tabs.create({url: text, active: false})
break
case 'currentTab':
browser.tabs.update({url: text})
break
case 'newForegroundTab':
browser.tabs.create({url: text})
break
case 'newBackgroundTab':
browser.tabs.create({url: text, active: false})
break
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/overview/actions.js
Expand Up @@ -21,7 +21,7 @@ export const setEndDate = createAction('overview/setEndDate')
export function init() {
return function (dispatch, getState) {
// Perform an initial search to populate the view (empty query = get all docs)
dispatch(refreshSearch({loadingIndicator:true}))
dispatch(refreshSearch({loadingIndicator: true}))

// Track database changes, to e.g. trigger search result refresh
onDatabaseChange(change => dispatch(handlePouchChange({change})))
Expand Down
4 changes: 2 additions & 2 deletions src/overview/components/VisitAsListItem.js
Expand Up @@ -3,7 +3,7 @@ import classNames from 'classnames'

import styles from './VisitAsListItem.css'

import {localVersionAvailable, LinkToLocalVersion } from 'src/page-viewer'
import {localVersionAvailable, LinkToLocalVersion} from 'src/page-viewer'

const VisitAsListItem = ({doc, compact}) => {
const visitClasses = classNames({
Expand All @@ -17,7 +17,7 @@ const VisitAsListItem = ({doc, compact}) => {
href={doc.page.url}
title={doc.page.url}
// DEBUG Show document props on ctrl+meta+click
onClick={e=>{if (e.metaKey && e.ctrlKey) {console.log(doc); e.preventDefault()}}}
onClick={ e => { if (e.metaKey && e.ctrlKey) { console.log(doc); e.preventDefault() } }}
>

{doc.page.screenshot
Expand Down
6 changes: 3 additions & 3 deletions src/overview/epics.js
Expand Up @@ -8,17 +8,17 @@ import * as actions from './actions'
const searchUpdateActions = [
actions.setQuery.getType(),
actions.setStartDate.getType(),
actions.setEndDate.getType(),
actions.setEndDate.getType()
]

// When the query changed, refresh the search results
export const refreshSearchResultsUponQueryChange = action$ => action$
.filter(action => searchUpdateActions.includes(action.type))
.debounceTime(500) // wait until typing stops for 500ms
.map(() => actions.refreshSearch({loadingIndicator:true}))
.map(() => actions.refreshSearch({loadingIndicator: true}))

// When the database changed, refresh the search results
export const refreshSearchResultsUponLogChange = action$ => action$
.ofType(actions.handlePouchChange.getType())
.debounceTime(1000)
.map(() => actions.refreshSearch({loadingIndicator:false}))
.map(() => actions.refreshSearch({loadingIndicator: false}))
4 changes: 2 additions & 2 deletions src/overview/reducer.js
Expand Up @@ -30,11 +30,11 @@ function showLoadingIndicator(state) {
// We have to keep a counter, rather than a boolean, as it can currently
// happen that multiple subsequent searches are running simultaneously. The
// animation will thus hide again when all of them have completed.
return {...state, waitingForResults: state.waitingForResults+1}
return {...state, waitingForResults: state.waitingForResults + 1}
}

function hideLoadingIndicator(state) {
return {...state, waitingForResults: state.waitingForResults-1}
return {...state, waitingForResults: state.waitingForResults - 1}
}

export default createReducer({
Expand Down
44 changes: 21 additions & 23 deletions src/overview/store.js
@@ -1,36 +1,34 @@
import { createStore, applyMiddleware, compose } from 'redux'
import { combineReducers } from 'redux'
import { createEpicMiddleware } from 'redux-observable';
import { combineEpics } from 'redux-observable';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'
import { createEpicMiddleware, combineEpics } from 'redux-observable'
import thunk from 'redux-thunk'

import overview from 'src/overview'

const rootReducer = combineReducers({
overview: overview.reducer,
overview: overview.reducer
})

const rootEpic = combineEpics(
...Object.values(overview.epics),
...Object.values(overview.epics)
)

export default function configureStore({ReduxDevTools=undefined}={}) {
const enhancers = [
applyMiddleware(
createEpicMiddleware(rootEpic),
thunk,
),
]
if (ReduxDevTools) {
enhancers.push(ReduxDevTools.instrument())
}
const enhancer = compose(...enhancers)
export default function configureStore({ReduxDevTools = undefined} = {}) {
const enhancers = [
applyMiddleware(
createEpicMiddleware(rootEpic),
thunk
)
]
if (ReduxDevTools) {
enhancers.push(ReduxDevTools.instrument())
}
const enhancer = compose(...enhancers)

const store = createStore(
rootReducer,
undefined, // initial state
enhancer
)
const store = createStore(
rootReducer,
undefined, // initial state
enhancer
)

return store
return store
}
10 changes: 8 additions & 2 deletions src/page-analysis/background/index.js
Expand Up @@ -13,7 +13,6 @@ import makeScreenshot from './make-screenshot'

// Extract interesting stuff from the current page and store it.
async function performPageAnalysis({pageId, tabId}) {

// Run these functions in the content script in the tab.
const extractPageText = remoteFunction('extractPageText', {tabId})
const extractPageMetadata = remoteFunction('extractPageMetadata', {tabId})
Expand Down Expand Up @@ -49,11 +48,18 @@ async function performPageAnalysis({pageId, tabId}) {
storePageMetadata,
storePageText,
storeFavIcon,
storeScreenshot,
storeScreenshot
], {
onRejection: err => console.error(err)
<<<<<<< HEAD
})
await updatePageSearchIndex()
=======
}).then(
// Update search index
() => updatePageSearchIndex()
)
>>>>>>> Cleaning the linted code
}

export default async function analysePage({page, tabId}) {
Expand Down
2 changes: 1 addition & 1 deletion src/page-analysis/content_script/extract-page-metadata.js
Expand Up @@ -4,7 +4,7 @@ import { getMetadata, metadataRules } from 'page-metadata-parser'
export default function extractPageMetadata({
doc = document,
url = window.location.href,
}={}) {
} = {}) {
const pageMetadata = getMetadata(doc, url, metadataRules)
return pageMetadata
}
13 changes: 6 additions & 7 deletions src/page-analysis/content_script/extract-page-text.js
Expand Up @@ -5,23 +5,22 @@ function extractPageText_sync({
// By default, use the globals window and document.
loc = window.location,
doc = document,
}={}) {
} = {}) {
const uri = {
spec: loc.href,
host: loc.host,
prePath: loc.protocol + "//" + loc.host,
scheme: loc.protocol.substr(0, loc.protocol.indexOf(":")),
pathBase: loc.protocol + "//" + loc.host + loc.pathname.substr(0, loc.pathname.lastIndexOf("/") + 1)
prePath: loc.protocol + '//' + loc.host,
scheme: loc.protocol.substr(0, loc.protocol.indexOf(':')),
pathBase: loc.protocol + '//' + loc.host + loc.pathname.substr(0, loc.pathname.lastIndexOf('/') + 1)
}
let article
try {
article = new Readability(
uri,
// Readability mutates the DOM, so pass it a clone.
doc.cloneNode(true),
doc.cloneNode(true)
).parse()
}
catch (err) {
} catch (err) {
// Bummer.
console.error('Readability (content extraction) crashed:', err)
}
Expand Down
8 changes: 4 additions & 4 deletions src/page-analysis/index.js
Expand Up @@ -6,15 +6,15 @@ export const searchableTextFields = [
'extractedMetadata.title',
'extractedText.excerpt',
'extractedText.textContent',
'extractedText.bodyInnerText',
'extractedText.bodyInnerText'
]

// Revise and augment a page doc using available fields from the extracted data.
// (done at retrieval rather than at storage time for the sake of flexibility)
export const revisePageFields = doc => ({
...doc,
// Choose something presentable as a title.
title: (doc.extractedMetadata && doc.extractedMetadata.title)
|| doc.title
|| doc.url,
title: (doc.extractedMetadata && doc.extractedMetadata.title) ||
doc.title ||
doc.url
})
9 changes: 4 additions & 5 deletions src/page-storage/deduplication.js
Expand Up @@ -57,7 +57,7 @@ export default async function tryDedupePage({
page,
samePageCandidates,
}) {
if (samePageCandidates.length===0) {
if (samePageCandidates.length === 0) {
return {page}
}

Expand All @@ -69,8 +69,8 @@ export default async function tryDedupePage({

// Choose the action to take.
if (
sameness >= Sameness.MOSTLY
&& !candidatePage.protected
sameness >= Sameness.MOSTLY &&
!candidatePage.protected
) {
// Forget the old page's contents. Replace them with a link to the new
// page.
Expand All @@ -79,8 +79,7 @@ export default async function tryDedupePage({
newPage: page,
sameness,
})
}
else {
} else {
// Do nothing, leave as duplicate. We do create a link for information
// if they are similar enough.
if (sameness >= Sameness.PARTLY) {
Expand Down
2 changes: 1 addition & 1 deletion src/page-storage/index.js
Expand Up @@ -5,7 +5,7 @@ export const pageKeyPrefix = 'page/'

export const convertPageDocId = docuri.route(`${pageKeyPrefix}:timestamp/:nonce`)

export function generatePageDocId({timestamp, nonce}={}) {
export function generatePageDocId({timestamp, nonce} = {}) {
const date = timestamp ? new Date(timestamp) : new Date()
return convertPageDocId({
timestamp: date.getTime(),
Expand Down

0 comments on commit 11a8c52

Please sign in to comment.