Skip to content

Commit 773ae36

Browse files
committed
Modify code to better fit with style guide recommendations
This makes the changes to the code suggested by coffeelint.
1 parent 22ffaab commit 773ae36

18 files changed

+128
-105
lines changed

background_scripts/commands.coffee

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Commands =
99
# Registers a command, making it available to be optionally bound to a key.
1010
# options:
1111
# - background: whether this command needs to be run against the background page.
12-
# - passCountToFunction: true if this command should have any digits which were typed prior to the
13-
# command passed to it. This is used to implement e.g. "closing of 3 tabs".
12+
# - passCountToFunction: true if this command should have any digits which were typed prior to the command
13+
# passed to it. This is used to implement e.g. "closing of 3 tabs".
1414
addCommand: (command, description, options) ->
1515
if command of @availableCommands
1616
console.log(command, "is already defined! Check commands.coffee for duplicates.")
@@ -38,12 +38,11 @@ Commands =
3838

3939
# Lower-case the appropriate portions of named keys.
4040
#
41-
# A key name is one of three forms exemplified by <c-a> <left> or <c-f12>
42-
# (prefixed normal key, named key, or prefixed named key). Internally, for
43-
# simplicity, we would like prefixes and key names to be lowercase, though
44-
# humans may prefer other forms <Left> or <C-a>.
45-
# On the other hand, <c-a> and <c-A> are different named keys - for one of
46-
# them you have to press "shift" as well.
41+
# A key name is one of three forms exemplified by <c-a> <left> or <c-f12> (prefixed normal key, named key,
42+
# or prefixed named key). Internally, for simplicity, we would like prefixes and key names to be lowercase,
43+
# though humans may prefer other forms <Left> or <C-a>.
44+
# On the other hand, <c-a> and <c-A> are different named keys - for one of them you have to press "shift"
45+
# as well.
4746
normalizeKey: (key) ->
4847
key.replace(/<[acm]-/ig, (match) -> match.toLowerCase())
4948
.replace(/<([acm]-)?([a-zA-Z0-9]{2,5})>/g, (match, optionalPrefix, keyName) ->
@@ -82,19 +81,19 @@ Commands =
8281
for key of defaultKeyMappings
8382
@mapKeyToCommand(key, defaultKeyMappings[key])
8483

85-
# An ordered listing of all available commands, grouped by type. This is the order they will
86-
# be shown in the help page.
84+
# An ordered listing of all available commands, grouped by type. This is the order they will be shown in
85+
# the help page.
8786
commandGroups:
8887
pageNavigation:
89-
["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop", "scrollToBottom", "scrollToLeft",
90-
"scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageUp", "scrollFullPageDown", "reload",
91-
"toggleViewSource", "copyCurrentUrl", "LinkHints.activateModeToCopyLinkUrl",
92-
"openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp", "goToRoot", "enterInsertMode",
93-
"focusInput", "LinkHints.activateMode", "LinkHints.activateModeToOpenInNewTab",
94-
"LinkHints.activateModeToOpenInNewForegroundTab", "LinkHints.activateModeWithQueue", "Vomnibar.activate",
95-
"Vomnibar.activateInNewTab", "Vomnibar.activateTabSelection", "Vomnibar.activateBookmarks",
96-
"Vomnibar.activateBookmarksInNewTab", "goPrevious", "goNext", "nextFrame", "Marks.activateCreateMode",
97-
"Marks.activateGotoMode"]
88+
["scrollDown", "scrollUp", "scrollLeft", "scrollRight", "scrollToTop", "scrollToBottom",
89+
"scrollToLeft", "scrollToRight", "scrollPageDown", "scrollPageUp", "scrollFullPageUp",
90+
"scrollFullPageDown", "reload", "toggleViewSource", "copyCurrentUrl",
91+
"LinkHints.activateModeToCopyLinkUrl", "openCopiedUrlInCurrentTab", "openCopiedUrlInNewTab", "goUp",
92+
"goToRoot", "enterInsertMode", "focusInput", "LinkHints.activateMode",
93+
"LinkHints.activateModeToOpenInNewTab", "LinkHints.activateModeToOpenInNewForegroundTab",
94+
"LinkHints.activateModeWithQueue", "Vomnibar.activate", "Vomnibar.activateInNewTab",
95+
"Vomnibar.activateTabSelection", "Vomnibar.activateBookmarks", "Vomnibar.activateBookmarksInNewTab",
96+
"goPrevious", "goNext", "nextFrame", "Marks.activateCreateMode", "Marks.activateGotoMode"]
9897
findCommands: ["enterFindMode", "performFind", "performBackwardsFind"]
9998
historyNavigation:
10099
["goBack", "goForward"]
@@ -109,10 +108,9 @@ Commands =
109108
# a focused, high-signal set of commands to the new and casual user. Only those truly hungry for more power
110109
# from Vimium will uncover these gems.
111110
advancedCommands: [
112-
"scrollToLeft", "scrollToRight", "moveTabToNewWindow",
113-
"goUp", "goToRoot", "focusInput", "LinkHints.activateModeWithQueue",
114-
"LinkHints.activateModeToOpenIncognito", "goNext", "goPrevious", "Marks.activateCreateMode",
115-
"Marks.activateGotoMode", "moveTabLeft", "moveTabRight",
111+
"scrollToLeft", "scrollToRight", "moveTabToNewWindow", "goUp", "goToRoot", "focusInput",
112+
"LinkHints.activateModeWithQueue", "LinkHints.activateModeToOpenIncognito", "goNext", "goPrevious",
113+
"Marks.activateCreateMode", "Marks.activateGotoMode", "moveTabLeft", "moveTabRight",
116114
"closeTabsOnLeft","closeTabsOnRight", "closeOtherTabs"]
117115

118116
defaultKeyMappings =
@@ -142,8 +140,8 @@ defaultKeyMappings =
142140

143141
"gi": "focusInput"
144142

145-
"f": "LinkHints.activateMode"
146-
"F": "LinkHints.activateModeToOpenInNewTab"
143+
"f": "LinkHints.activateMode"
144+
"F": "LinkHints.activateModeToOpenInNewTab"
147145
"<a-f>": "LinkHints.activateModeWithQueue"
148146

149147
"/": "enterFindMode"

background_scripts/completion.coffee

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class Suggestion
6060
# - splits = [ "", "A", "b", "a", "c", "a", b" ]
6161
# UM M UM M UM M UM (M=Matched, UM=Unmatched)
6262
splits = string.split(RegexpCache.get(term, "(", ")"))
63-
for index in [0..splits.length-2] by 2
63+
for index in [0..splits.length - 2] by 2
6464
unmatchedText = splits[index]
65-
matchedText = splits[index+1]
65+
matchedText = splits[index + 1]
6666
# Add the indices spanning `matchedText` to `ranges`.
6767
textPosition += unmatchedText.length
6868
ranges.push([textPosition, textPosition + matchedText.length])
@@ -114,9 +114,11 @@ class BookmarkCompleter
114114
onBookmarksLoaded: -> @performSearch() if @currentSearch
115115

116116
performSearch: ->
117-
# If the folder separator character the first character in any query term, then we'll use the bookmark's full path as its title.
118-
# Otherwise, we'll just use the its regular title.
119-
usePathAndTitle = @currentSearch.queryTerms.reduce ((prev,term) => prev || term.indexOf(@folderSeparator) == 0), false
117+
# If the folder separator character the first character in any query term, then we'll use the bookmark's
118+
# full path as its title. Otherwise, we'll just use the its regular title.
119+
usePathAndTitle = @currentSearch.queryTerms.reduce (prev,term) =>
120+
prev || term.indexOf(@folderSeparator) == 0
121+
, false
120122
results =
121123
if @currentSearch.queryTerms.length > 0
122124
@bookmarks.filter (bookmark) =>
@@ -137,7 +139,8 @@ class BookmarkCompleter
137139
@bookmarks = @traverseBookmarks(bookmarks).filter((bookmark) -> bookmark.url?)
138140
@onBookmarksLoaded()
139141

140-
# If these names occur as top-level bookmark names, then they are not included in the names of bookmark folders.
142+
# If these names occur as top-level bookmark names, then they are not included in the names of bookmark
143+
# folders.
141144
ignoreTopLevel:
142145
'Other Bookmarks': true
143146
'Mobile Bookmarks': true
@@ -151,14 +154,15 @@ class BookmarkCompleter
151154
results
152155

153156
# Recursive helper for `traverseBookmarks`.
154-
traverseBookmarksRecursive: (bookmark, results, parent={pathAndTitle:""}) ->
157+
traverseBookmarksRecursive: (bookmark, results, parent = {pathAndTitle: ""}) ->
155158
bookmark.pathAndTitle =
156159
if bookmark.title and not (parent.pathAndTitle == "" and @ignoreTopLevel[bookmark.title])
157160
parent.pathAndTitle + @folderSeparator + bookmark.title
158161
else
159162
parent.pathAndTitle
160163
results.push bookmark
161-
bookmark.children.forEach((child) => @traverseBookmarksRecursive child, results, bookmark) if bookmark.children
164+
if bookmark.children
165+
bookmark.children.forEach((child) => @traverseBookmarksRecursive child, results, bookmark)
162166

163167
computeRelevancy: (suggestion) ->
164168
RankingUtils.wordRelevancy(suggestion.queryTerms, suggestion.url, suggestion.title)
@@ -186,8 +190,9 @@ class HistoryCompleter
186190

187191
refresh: ->
188192

189-
# The domain completer is designed to match a single-word query which looks like it is a domain. This supports
190-
# the user experience where they quickly type a partial domain, hit tab -> enter, and expect to arrive there.
193+
# The domain completer is designed to match a single-word query which looks like it is a domain. This
194+
# supports the user experience where they quickly type a partial domain, hit tab -> enter, and expect to
195+
# arrive there.
191196
class DomainCompleter
192197
# A map of domain -> { entry: <historyEntry>, referenceCount: <count> }
193198
# - `entry` is the most recently accessed page in the History within this domain.
@@ -275,8 +280,10 @@ class SearchEngineCompleter
275280
searchEngineMatch = this.getSearchEngineMatches(queryTerms[0])
276281
suggestions = []
277282
if searchEngineMatch
278-
searchEngineMatch = searchEngineMatch.replace(/%s/g, queryTerms[1..].join(" "))
279-
suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy)
283+
searchUrl = searchEngineMatch.replace(/%s/g, queryTerms[1..].join(" "))
284+
queryTerms[0] += ":"
285+
queryStr = queryTerms.join(" ")
286+
suggestion = new Suggestion(queryTerms, "search", searchUrl, queryStr, @computeRelevancy)
280287
suggestions.push(suggestion)
281288
onComplete(suggestions)
282289

@@ -288,8 +295,8 @@ class SearchEngineCompleter
288295
getSearchEngineMatches: (queryTerm) ->
289296
this.searchEngines[queryTerm]
290297

291-
# A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the top
292-
# 10. Queries from the vomnibar frontend script come through a multi completer.
298+
# A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the
299+
# top 10. Queries from the vomnibar frontend script come through a multi completer.
293300
class MultiCompleter
294301
constructor: (@completers) -> @maxResults = 10
295302

@@ -325,7 +332,7 @@ class MultiCompleter
325332
# Utilities which help us compute a relevancy score for a given item.
326333
RankingUtils =
327334
# Whether the given things (usually URLs or titles) match any one of the query terms.
328-
# This is used to prune out irrelevant suggestions before we try to rank them, and for calculating word relevancy.
335+
# This is used to prune out irrelevant suggestions before ranking them, and for calculating word relevancy.
329336
# Every term must match at least one thing.
330337
matches: (queryTerms, things...) ->
331338
for term in queryTerms
@@ -338,17 +345,19 @@ RankingUtils =
338345

339346
# Weights used for scoring matches.
340347
matchWeights:
341-
matchAnywhere: 1
342-
matchStartOfWord: 1
343-
matchWholeWord: 1
348+
matchAnywhere: 1
349+
matchStartOfWord: 1
350+
matchWholeWord: 1
344351
# The following must be the sum of the three weights above; it is used for normalization.
345-
maximumScore: 3
352+
maximumScore: 3
346353
#
347354
# Calibration factor for balancing word relevancy and recency.
348-
recencyCalibrator: 2.0/3.0
355+
recencyCalibrator: 2.0 / 3.0
349356
# The current value of 2.0/3.0 has the effect of:
350-
# - favoring the contribution of recency when matches are not on word boundaries ( because 2.0/3.0 > (1)/3 )
351-
# - favoring the contribution of word relevance when matches are on whole words ( because 2.0/3.0 < (1+1+1)/3 )
357+
# - favoring the contribution of recency when matches are not on word boundaries
358+
# ( because 2.0/3.0 > (1)/3 )
359+
# - favoring the contribution of word relevance when matches are on whole words
360+
# ( because 2.0/3.0 < (1+1+1)/3 )
352361

353362
# Calculate a score for matching term against string.
354363
# The score is in the range [0, matchWeights.maximumScore], see above.
@@ -448,13 +457,14 @@ RegexpCache =
448457
# - string="go", prefix="\b", suffix=""
449458
# - this returns regexp matching "google", but not "agog" (the "go" must occur at the start of a word)
450459
# TODO: `prefix` and `suffix` might be useful in richer word-relevancy scoring.
451-
get: (string, prefix="", suffix="") ->
460+
get: (string, prefix = "", suffix = "") ->
452461
@init() unless @initialized
453462
regexpString = string.replace(@escapeRegExp, "\\$&")
454-
# Avoid cost of constructing new strings if prefix/suffix are empty (which is expected to be a common case).
463+
# Avoid cost of constructing new strings if prefix/suffix are empty (which is expected to be common).
455464
regexpString = prefix + regexpString if prefix
456465
regexpString = regexpString + suffix if suffix
457-
# Smartcase: Regexp is case insensitive, unless `string` contains a capital letter (testing `string`, not `regexpString`).
466+
# Smartcase: Regexp is case insensitive, unless `string` contains a capital letter (testing `string`, not
467+
# `regexpString`).
458468
@cache[regexpString] ||= new RegExp regexpString, (if Utils.hasUpperCase(string) then "" else "i")
459469

460470
# Provides cached access to Chrome's history. As the user browses to new pages, we add those pages to this
@@ -503,7 +513,7 @@ HistoryCache =
503513
@history = []
504514
else
505515
toRemove.urls.forEach (url) =>
506-
i = HistoryCache.binarySearch({url:url}, @history, @compareHistoryByUrl)
516+
i = HistoryCache.binarySearch({url: url}, @history, @compareHistoryByUrl)
507517
if i < @history.length and @history[i].url == url
508518
@history.splice(i, 1)
509519

background_scripts/main.coffee

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ BackgroundCommands =
258258
# Clean out the tabQueue so we don't have unused windows laying about.
259259
delete tabQueue[window.id] if (tabQueue[window.id].length == 0)
260260

261-
# We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until the
262-
# tab is created because the content script is not available during the "loading" state. We need to
263-
# wait until that's over before we can call setScrollPosition.
261+
# We have to chain a few callbacks to set the appropriate scroll position. We can't just wait until
262+
# the tab is created because the content script is not available during the "loading" state. We need
263+
# to wait until that's over before we can call setScrollPosition.
264264
chrome.tabs.create({ url: tabQueueEntry.url, index: tabQueueEntry.positionIndex }, (tab) ->
265265
tabLoadedHandlers[tab.id] = ->
266266
chrome.tabs.sendRequest(tab.id,
@@ -276,7 +276,7 @@ BackgroundCommands =
276276
showHelp: (callback, frameId) ->
277277
chrome.tabs.getSelected(null, (tab) ->
278278
chrome.tabs.sendMessage(tab.id,
279-
{ name: "toggleHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId }))
279+
{ name: "toggleHelpDialog", dialogHtml: helpDialogHtml(), frameId: frameId }))
280280
moveTabLeft: (count) -> moveTab(null, -count)
281281
moveTabRight: (count) -> moveTab(null, count)
282282
nextFrame: (count) ->
@@ -416,8 +416,8 @@ chrome.tabs.onRemoved.addListener (tabId) ->
416416
else
417417
tabQueue[openTabInfo.windowId] = [openTabInfo]
418418

419-
# keep the reference around for a while to wait for the last messages from the closed tab (e.g. for updating
420-
# scroll position)
419+
# keep the reference around for a while to wait for the last messages from the closed tab (e.g. for
420+
# updating scroll position)
421421
tabInfoMap.deletor = -> delete tabInfoMap[tabId]
422422
setTimeout tabInfoMap.deletor, 1000
423423
delete framesForTab[tabId]

background_scripts/settings.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ root.Settings = Settings =
4747
parseSearchEngines: (searchEnginesText) ->
4848
@searchEnginesMap = {}
4949
# find the split pairs by first splitting by line then splitting on the first `: `
50-
split_pairs = ( pair.split( /: (.+)/, 2) for pair in searchEnginesText.split( /\n/ ) when pair[0] != "#" )
50+
split_pairs = (pair.split( /: (.+)/, 2) for pair in searchEnginesText.split( /\n/ ) when pair[0] != "#")
5151
@searchEnginesMap[a[0]] = a[1] for a in split_pairs
5252
@searchEnginesMap
5353
getSearchEngines: ->

background_scripts/sync.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ root.Sync = Sync =
7878
@log "set scheduled: #{key}=#{value}"
7979
key_value = {}
8080
key_value[key] = value
81-
@storage.set key_value, =>
81+
@storage.set key_value, ->
8282
# Chrome sets chrome.runtime.lastError if there is an error.
8383
if chrome.runtime.lastError
8484
console.log "callback for Sync.set() indicates error: #{key} <- #{value}"
@@ -88,7 +88,7 @@ root.Sync = Sync =
8888
clear: (key) ->
8989
if @shouldSyncKey key
9090
@log "clear scheduled: #{key}"
91-
@storage.remove key, =>
91+
@storage.remove key, ->
9292
# Chrome sets chrome.runtime.lastError if there is an error.
9393
if chrome.runtime.lastError
9494
console.log "for Sync.clear() indicates error: #{key}"

content_scripts/link_hints.coffee

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#
22
# This implements link hinting. Typing "F" will enter link-hinting mode, where all clickable items on the
3-
# page have a hint marker displayed containing a sequence of letters. Typing those letters will select a link.
3+
# page have a hint marker displayed containing a sequence of letters. Typing those letters will select a
4+
# link.
45
#
56
# In our 'default' mode, the characters we use to show link hints are a user-configurable option. By default
67
# they're the home row. The CSS which is used on the link hints is also a configurable option.
@@ -346,8 +347,8 @@ filterHints =
346347
if (forElement)
347348
labelText = label.textContent.trim()
348349
# remove trailing : commonly found in labels
349-
if (labelText[labelText.length-1] == ":")
350-
labelText = labelText.substr(0, labelText.length-1)
350+
if (labelText[labelText.length - 1] == ":")
351+
labelText = labelText.substr(0, labelText.length - 1)
351352
@labelMap[forElement] = labelText
352353

353354
generateHintString: (linkHintNumber) ->

0 commit comments

Comments
 (0)