Skip to content

Commit

Permalink
Feature: add linting to build process (#527)
Browse files Browse the repository at this point in the history
* add build task 'lint'

* add semi colons across project

* add eslint to the 'lint' pipeline

* add eslint fule no-tabs
  • Loading branch information
simonwjackson authored and brookhong committed Oct 13, 2017
1 parent 5c167b1 commit e14bc69
Show file tree
Hide file tree
Showing 17 changed files with 88 additions and 50 deletions.
11 changes: 11 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"rules": {
"semi": ["error", "always"],
"no-tabs": 2
}
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
dist/
.DS_Store
.vscode/
package-lock.json
package-lock.json
jsconfig.json
18 changes: 9 additions & 9 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ var ChromeService = (function() {
}
} else {
var type = _port ? "[unexpected port message] " : "[unexpected runtime message] ";
console.log(type + JSON.stringify(_message))
console.log(type + JSON.stringify(_message));
}
}
}
Expand Down Expand Up @@ -377,7 +377,7 @@ var ChromeService = (function() {
return handleMessage(message, port.sender, function(resp) {
try {
if (!port.isDisconnected) {
port.postMessage(resp)
port.postMessage(resp);
}
} catch (e) {
console.log(message.action + ": " + e);
Expand Down Expand Up @@ -636,15 +636,15 @@ var ChromeService = (function() {
_response(message, sendResponse, {
urls: tabs
});
})
});
};
self.getTopSites = function(message, sender, sendResponse) {
chrome.topSites.get(function(urls) {
urls = _filterByTitleOrUrl(urls, message.query);
_response(message, sendResponse, {
urls: urls
});
})
});
};
function _getHistory(cb, sortByMostUsed) {
chrome.history.search({
Expand Down Expand Up @@ -821,7 +821,7 @@ var ChromeService = (function() {
});
};

self.closeTabLeft = function(message, sender, senderResponse) { _closeTab(sender, -message.repeats)};
self.closeTabLeft = function(message, sender, senderResponse) { _closeTab(sender, -message.repeats);};
self.closeTabRight = function(message, sender, senderResponse) { _closeTab(sender, message.repeats); };
self.closeTabsToLeft = function(message, sender, senderResponse) { _closeTab(sender, -sender.tab.index); };
self.closeTabsToRight = function(message, sender, senderResponse) {
Expand Down Expand Up @@ -921,7 +921,7 @@ var ChromeService = (function() {
function normalizeURL(url) {
if (!/^view-source:|^javascript:/.test(url) && /^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/\n]+)/im.test(url)) {
if (/^[\w-]+?:\/\//i.test(url)) {
url = url
url = url;
} else {
url = "http://" + url;
}
Expand Down Expand Up @@ -1108,8 +1108,8 @@ var ChromeService = (function() {
url: newTabUrl
}, function(tabs) {
chrome.tabs.remove(tabs.map(function(t) {
return t.id
}))
return t.id;
}));
});
}
});
Expand All @@ -1130,7 +1130,7 @@ var ChromeService = (function() {
_response(message, sendResponse, {
downloads: items
});
})
});
};
self.executeScript = function(message, sender, sendResponse) {
chrome.tabs.executeScript(sender.tab.id, {
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/content_scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ function tabOpenLink(str, simultaneousness) {

var urls;
if (str.constructor.name === "Array") {
urls = str
urls = str;
} else if (str.constructor.name === "jQuery") {
urls = str.map(function() {
return this.href;
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var Front = (function() {
});
});
};
self.openOmnibar(({type: "OmniQuery", extra: args.query, style: args.style}))
self.openOmnibar(({type: "OmniQuery", extra: args.query, style: args.style}));
};

self.openFinder = function() {
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/gist.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ var Gist = (function() {

return self;
})();
Gist.initGist('****************************************')
Gist.initGist('****************************************');
Gist.readComment(1);
// Gist.newComment("abc");
8 changes: 4 additions & 4 deletions content_scripts/normal.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ var Mode = (function() {
} else {
var pathname = window.location.pathname.split('/');
if (pathname.length) {
sl += " - frame: " + pathname[pathname.length - 1]
sl += " - frame: " + pathname[pathname.length - 1];
}
}
}
Expand Down Expand Up @@ -389,7 +389,7 @@ var Normal = (function(mode) {
var h = n.scrollHeight;
if (h > maxHeight) {
scrollIndex = i;
maxHeight = h
maxHeight = h;
}
});
var sn = scrollNodes[scrollIndex];
Expand Down Expand Up @@ -645,7 +645,7 @@ var Normal = (function(mode) {
var hints = modeKey[1];
return function() {
Hints.feedkeys(hints);
}
};
}
setTimeout(closureWrapper(), 120 + i*100);
}
Expand Down Expand Up @@ -692,7 +692,7 @@ var Normal = (function(mode) {
url: markInfo,
scrollLeft: 0,
scrollTop: 0
}
};
}
markInfo.tab = {
tabbed: newTab,
Expand Down
2 changes: 1 addition & 1 deletion content_scripts/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var runtime = window.runtime || (function() {
}
});
} else {
console.log("[unexpected runtime message] " + JSON.stringify(_message))
console.log("[unexpected runtime message] " + JSON.stringify(_message));
}
});

Expand Down
2 changes: 1 addition & 1 deletion content_scripts/visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ var Visual = (function(mode) {
annotation: "make cursor at center of window.",
feature_group: 9,
code: function() {
document.scrollingElement.scrollTop += cursor.getBoundingClientRect().top - window.innerHeight/2
document.scrollingElement.scrollTop += cursor.getBoundingClientRect().top - window.innerHeight/2;
}
});
self.mappings.add("f", {
Expand Down
28 changes: 26 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,31 @@ var gulp = require('gulp'),
zip = require('gulp-zip'),
gulpUtil = require('gulp-util'),
babel = require('gulp-babel'),
gp_uglify = require('gulp-uglify');
gp_uglify = require('gulp-uglify'),
eslint = require('gulp-eslint');

gulp.task('lint', () => {
// ESLint ignores files with "node_modules" paths.
// So, it's best to have gulp ignore the directory as well.
// Also, Be sure to return the stream from the task;
// Otherwise, the task may end before the stream has finished.
return gulp.src([
'background.js',
'gulpfile.js',
'content_scripts/*.js',
'pages/*.js',
'!node_modules/**'
])
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});

gulp.task('clean', function () {
return gulp.src('dist', {read: false})
Expand Down Expand Up @@ -87,7 +111,7 @@ gulp.task('copy-es-files', ['clean'], function() {
.pipe(gulp.dest('dist'));
});

gulp.task('default', ['copy-pretty-default-js', 'build_common_content_min', 'use_common_content_min', 'use_common_content_min_manifest'], function() {
gulp.task('default', ['lint', 'copy-pretty-default-js', 'build_common_content_min', 'use_common_content_min', 'use_common_content_min_manifest'], function() {
return gulp.src('dist/**')
.pipe(zip('sk.zip'))
.pipe(gulp.dest('dist'));
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
"description": "Map your keys for web surfing, expand your browser with javascript and keyboard.",
"main": "background.js",
"dependencies": {
"gulp-clean": "^0.3.2",
"babel-preset-es2015": "^6.22.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"babel-preset-es2015": "^6.22.0",
"gulp-uglify": "^1.5.3",
"gulp-clean": "^0.3.2",
"gulp-concat": "^2.6.0",
"gulp-eslint": "^4.0.0",
"gulp-replace": "^0.5.4",
"gulp-uglify": "^1.5.3",
"gulp-zip": "^3.2.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-eslint": "^8.0.1",
"babel-plugin-transform-react-jsx": "^6.24.1",
"babel-preset-env": "^1.6.0"
},
Expand Down
2 changes: 1 addition & 1 deletion pages/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $(document).on('surfingkeys:defaultSettingsLoaded', function() {
if (meta.annotation && meta.annotation.length && meta.feature_group === 99) {
return "<div><span class=kbd-span><kbd>{0}</kbd></span><span class=annotation>{1}</span></div>".format(htmlEncode(w), meta.annotation);
}
return null
return null;
}).filter(function(w) {
return w !== null;
});
Expand Down
4 changes: 2 additions & 2 deletions pages/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ mapkey('<Ctrl-j>', '#1Mouse out elements.', 'Hints.create("", Hints.dispatchMous
mapkey('ya', '#7Copy a link URL to the clipboard', function() {
Hints.create('*[href]', function(element) {
Front.writeClipboard(element.href);
})
});
});
mapkey('yma', '#7Copy multiple link URLs to the clipboard', function() {
var linksToYank = [];
Expand All @@ -296,7 +296,7 @@ mapkey('I', '#1Go to edit box with vim editor', function() {
});
mapkey('O', '#1Open detected links from text', function() {
Hints.create(runtime.conf.clickablePat, function(element) {
$(`<a href=${element[2]}>`)[0].click()
$(`<a href=${element[2]}>`)[0].click();
}, {statusLine: "Open detected links from text"});
});
mapkey(';s', 'Toggle PDF viewer from SurfingKeys', function() {
Expand Down
20 changes: 10 additions & 10 deletions pages/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var AceEditor = (function(mode, elmId) {
value: u.url,
score: typedCount*10 + visitCount,
meta: 'local'
}
};
});
});
var urlCompleter = {
Expand Down Expand Up @@ -121,7 +121,7 @@ var AceEditor = (function(mode, elmId) {
value: w,
score: wordScores[w],
meta: 'local'
}
};
});
};

Expand Down Expand Up @@ -204,16 +204,16 @@ var AceEditor = (function(mode, elmId) {
vim.defineEx("wq", "wq", function(cm, input) {
self.exit(self._getValue());
// tell vim editor that command is done
self.state.cm.signal('vim-command-done', '')
self.state.cm.signal('vim-command-done', '');
});
vim.map('<CR>', ':wq', 'normal')
vim.map('<CR>', ':wq', 'normal');
vim.defineEx("bnext", "bn", function(cm, input) {
Front.contentCommand({
action: 'nextEdit',
backward: false
});
});
vim.map('<C-b>', ':bn', 'normal')
vim.map('<C-b>', ':bn', 'normal');
vim.defineEx("bprevious", "bp", function(cm, input) {
Front.contentCommand({
action: 'nextEdit',
Expand All @@ -222,7 +222,7 @@ var AceEditor = (function(mode, elmId) {
});
vim.defineEx("quit", "q", function(cm, input) {
self.exit();
self.state.cm.signal('vim-command-done', '')
self.state.cm.signal('vim-command-done', '');
});
Front.vimMappings.forEach(function(a) {
vim.map.apply(vim, a);
Expand All @@ -238,7 +238,7 @@ var AceEditor = (function(mode, elmId) {
originValue = message.content;
$(self.container).find('textarea').focus();
self.enter();
vim.map('<CR>', ':wq', 'insert')
vim.map('<CR>', ':wq', 'insert');
self.type = message.type;
self.setFontSize(16);
if (message.type === 'url') {
Expand All @@ -252,12 +252,12 @@ var AceEditor = (function(mode, elmId) {
} else {
self.renderer.setOption('showLineNumbers', true);
self.language_tools.setCompleters([pageWordCompleter]);
vim.unmap('<CR>', 'insert')
vim.map('<C-CR>', ':wq', 'insert')
vim.unmap('<CR>', 'insert');
vim.map('<C-CR>', ':wq', 'insert');
self.css('height', '30%');
}
self.setReadOnly(message.type === 'select');
vim.map('<C-d>', '<C-w>', 'insert')
vim.map('<C-d>', '<C-w>', 'insert');
vim.exitInsertMode(self.state.cm);

// set cursor at initial line
Expand Down
8 changes: 4 additions & 4 deletions pages/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ var Front = (function(mode) {
tab.html("<div class=sk_tab_hint>{0}</div><div class=sk_tab_wrap><div class=sk_tab_icon><img src='{1}'></div><div class=sk_tab_title>{2}</div></div>".format(hintLabels[i], t.favIconUrl, htmlEncode(t.title)));
tab.data('url', t.url);
tabs_fg.append(tab);
})
});
tabs_fg.find('div.sk_tab').each(function() {
$(this).css('width', $(this).width() + 10);
$(this).append($("<div class=sk_tab_url>{0}</div>".format($(this).data('url'))));
});
_tabs.find('div.sk_tabs_bg').css('width', window.innerWidth).css('height', window.innerHeight);
}
};
_actions['chooseTab'] = function() {
runtime.command({
action: 'getTabs'
Expand All @@ -205,7 +205,7 @@ var Front = (function(mode) {
l10n = l10n[lang];
cb(function(str) {
return l10n[str] ? l10n[str] : str;
})
});
} else {
cb(function(str) {
return str;
Expand Down Expand Up @@ -508,7 +508,7 @@ var Front = (function(mode) {
}
}).join("");
if (words.length > 0 && _pendingHint) {
keystroke.html(words)
keystroke.html(words);
keystroke.removeClass("expandRichHints").addClass("expandRichHints");
self.flush();
}
Expand Down
2 changes: 1 addition & 1 deletion pages/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $(document).on('surfingkeys:defaultSettingsLoaded', function() {

mermaid.parseError = function(err) {
Front.showPopup(err);
}
};
function drawDiagram(code) {
Front.source = code;
$('div.mermaid').removeAttr('data-processed').html(code);
Expand Down
Loading

0 comments on commit e14bc69

Please sign in to comment.