Skip to content

Commit f808918

Browse files
stefanbuckjosephfrazier
authored andcommitted
Add Prettier (OctoLinker#380)
* Add prettier * Bypass prettier issue with eslint disable line comments Basically I changed all eslint-disable-line comments to eslint-disable-next-line See prettier/prettier#1267 for details * Reformat code with prettier
1 parent e4bd3de commit f808918

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+598
-571
lines changed

.eslintrc.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
module.exports = {
2-
extends: ['airbnb-base', 'plugin:import/errors'],
3-
plugins: ['mocha'],
2+
extends: ['airbnb-base', 'plugin:import/errors', 'prettier'],
3+
plugins: ['prettier', 'mocha'],
44
env: {
55
browser: true,
66
mocha: true
77
},
88
rules: {
9+
'prettier/prettier': ['error', {
10+
singleQuote: true,
11+
trailingComma: 'all',
12+
}],
913
'func-names': 0,
1014
'id-length': [1, {'exceptions': ['$']}],
1115
'new-cap': [2, {'capIsNewExceptions': ['Deferred']}],

karma.conf.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
const webpackConfig = require('./webpack.config');
32

43
webpackConfig.devtool = 'inline-source-map';
@@ -7,15 +6,15 @@ if (process.env.APPVEYOR) {
76
require('phantomjs-prebuilt').path = ''; // eslint-disable-line
87
}
98

10-
module.exports = function (config) {
9+
module.exports = function(config) {
1110
config.set({
1211
basePath: '',
1312
frameworks: ['detectBrowsers', 'mocha', 'fixture'],
1413
detectBrowsers: {
1514
postDetection(availableBrowsers) {
1615
return availableBrowsers
1716
.filter(browser => ['Chrome', 'Firefox'].includes(browser))
18-
.map((browser) => {
17+
.map(browser => {
1918
if (browser === 'Chrome' && process.env.TRAVIS) {
2019
return 'Chrome_travis_ci';
2120
}

lib/background/insight.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class Insight {
3838
this.cid = clientId;
3939
}
4040

41-
track({
42-
category, action, label, value,
43-
}) {
41+
track({ category, action, label, value }) {
4442
const params = {
4543
t: 'event',
4644
ec: category,
@@ -50,10 +48,13 @@ class Insight {
5048
if (label) params.el = label;
5149
if (value) params.ev = value;
5250

53-
return send({
54-
tid: this.tid,
55-
cid: this.cid,
56-
}, params);
51+
return send(
52+
{
53+
tid: this.tid,
54+
cid: this.cid,
55+
},
56+
params,
57+
);
5758
}
5859
}
5960

lib/click-handler.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { showTooltip } from './gh-interface.js';
33
import * as storage from './options/storage.js';
44
import fetch from './utils/fetch.js';
55

6-
const SORRY = 'I\'m sorry, unable to resolve this link 😱';
6+
const SORRY = "I'm sorry, unable to resolve this link 😱";
77
const PROCESS = 'Processing ⏳';
88
const RESOLVED = 'Redirecting 🚀';
99

@@ -47,7 +47,7 @@ function getResolverUrls(dataAttr) {
4747
},
4848
});
4949

50-
return [].concat(resolver(dataAttr)).map((url) => {
50+
return [].concat(resolver(dataAttr)).map(url => {
5151
if (!url) {
5252
return null;
5353
}
@@ -111,7 +111,11 @@ async function onClick(event) {
111111
track('success');
112112
showTooltip($tooltipTarget, RESOLVED);
113113

114-
const newWindow = (storage.get('newWindow') || event.metaKey || event.ctrlKey || event.which === 2);
114+
const newWindow =
115+
storage.get('newWindow') ||
116+
event.metaKey ||
117+
event.ctrlKey ||
118+
event.which === 2;
115119
const newWindowActive = storage.get('newWindowActive');
116120
openUrl((res || {}).url || url, newWindow, newWindowActive);
117121
} catch (err) {
@@ -122,7 +126,7 @@ async function onClick(event) {
122126
}
123127
}
124128

125-
export default function (_pluginManager) {
129+
export default function(_pluginManager) {
126130
$body.undelegate(LINK_SELECTOR, 'click', onClick);
127131
$body.undelegate(LINK_SELECTOR, 'mouseup', onClick);
128132

lib/debug-mode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function (enable = false) {
1+
export default function(enable = false) {
22
if (!enable) {
33
return;
44
}

lib/insert-link.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ function wrapsInnerString(text, matchValue, dataAttrObject) {
119119
const [leftSide, rightSide] = text.split(matchValue);
120120
const openingQuote = getQuoteAtPos(matchValue, 0);
121121
const closingQuote = getQuoteAtPos(matchValue, matchValue.length - 1);
122-
const linkText = matchValue.slice(openingQuote ? 1 : 0, closingQuote ? matchValue.length - 1 : undefined);
122+
const linkText = matchValue.slice(
123+
openingQuote ? 1 : 0,
124+
closingQuote ? matchValue.length - 1 : undefined,
125+
);
123126

124127
if (leftSide) parent.appendChild(document.createTextNode(leftSide));
125128
if (openingQuote) parent.appendChild(document.createTextNode(openingQuote));
@@ -131,7 +134,8 @@ function wrapsInnerString(text, matchValue, dataAttrObject) {
131134

132135
function replace(portion, match, dataAttr, captureGroup) {
133136
const { text, node, indexInMatch } = portion;
134-
const isAlreadyWrapped = (node.parentNode.parentNode || node.parentNode).classList.contains(CLASS_NAME);
137+
const isAlreadyWrapped = (node.parentNode.parentNode || node.parentNode
138+
).classList.contains(CLASS_NAME);
135139
if (isAlreadyWrapped) {
136140
return text;
137141
}
@@ -143,7 +147,11 @@ function replace(portion, match, dataAttr, captureGroup) {
143147
return wrapsInnerString(text, matchValue, dataAttrObject);
144148
}
145149

146-
const { valueStartPos, valueEndPos, portionEndPos } = getIndexes(portion, match[0], matchValue);
150+
const { valueStartPos, valueEndPos, portionEndPos } = getIndexes(
151+
portion,
152+
match[0],
153+
matchValue,
154+
);
147155
if (valueStartPos === indexInMatch) {
148156
if (portionEndPos === valueEndPos) {
149157
return createLinkElement(text, dataAttrObject);
@@ -156,7 +164,7 @@ function replace(portion, match, dataAttr, captureGroup) {
156164
return text;
157165
}
158166

159-
export default function (el, regex, mapping, captureGroup = '$1') {
167+
export default function(el, regex, mapping, captureGroup = '$1') {
160168
if (!(el instanceof HTMLElement)) {
161169
throw new Error('must be called with a DOM element');
162170
}

lib/load-plugins.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
21
// Load all plugins from /lib/plugins/*/index.js.
32
// For more information about dynamic require see
43
// https://webpack.github.io/docs/context.html
54

65
export default function loadPlugins() {
76
function requireAll(requireContext) {
8-
return requireContext.keys().map(pluginPath => requireContext(pluginPath).default);
7+
return requireContext
8+
.keys()
9+
.map(pluginPath => requireContext(pluginPath).default);
910
}
1011

1112
return requireAll(require.context('./plugins', false, /[^/]*.js$/));

lib/notification.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { showNotification } from './gh-interface';
22
import * as storage from './options/storage.js';
33

4-
const pkgVersion = require('../package.json').version.split('.').slice(0, -1).join('.');
4+
const pkgVersion = require('../package.json')
5+
.version.split('.')
6+
.slice(0, -1)
7+
.join('.');
58

6-
export default async function () {
9+
export default async function() {
710
const showUpdateNotification = storage.get('showUpdateNotification');
811

912
if (!showUpdateNotification) {
@@ -15,7 +18,9 @@ export default async function () {
1518
storage.set('version', pkgVersion);
1619

1720
if (installedVersion && installedVersion !== pkgVersion) {
18-
const response = await fetch('https://api.github.com/repos/octolinker/browser-extension/releases/latest');
21+
const response = await fetch(
22+
'https://api.github.com/repos/octolinker/browser-extension/releases/latest',
23+
);
1924
const json = await response.json();
2025
const description = json.body.split('\n')[0];
2126
const url = json.html_url;

lib/octo-linker.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import debugMode from './debug-mode.js';
88
import loadPlugins from './load-plugins';
99
import * as storage from './options/storage.js';
1010

11-
1211
function initialize(self) {
1312
debugMode(storage.get('debugMode'));
1413
notification();
@@ -25,18 +24,18 @@ function run(self) {
2524

2625
self._blobReader.read();
2726

28-
self._blobReader.forEach((blob) => {
27+
self._blobReader.forEach(blob => {
2928
const plugins = self._pluginManager.get(blob.path, blob.el.classList);
3029

3130
if (!plugins.length) {
3231
return;
3332
}
3433

35-
plugins.forEach((plugin) => {
34+
plugins.forEach(plugin => {
3635
if (plugin.parseBlob) {
3736
plugin.parseBlob(blob);
3837
} else if (plugin.getLinkRegexes) {
39-
[].concat(plugin.getLinkRegexes(blob)).forEach((regex) => {
38+
[].concat(plugin.getLinkRegexes(blob)).forEach(regex => {
4039
insertLink(blob.el, regex, {
4140
pluginName: plugin.name,
4241
target: '$1',

lib/options/components/checkbox.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
export default ({
2-
name, label, value, defaultValue, description,
3-
}) => {
4-
const val = (value === undefined) ? defaultValue : value;
1+
export default ({ name, label, value, defaultValue, description }) => {
2+
const val = value === undefined ? defaultValue : value;
53
const note = description ? `<p class="note">${description}</p>` : '';
64

75
return `<div class="form-checkbox">

0 commit comments

Comments
 (0)