Skip to content

Commit

Permalink
Add Prettier (OctoLinker#380)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
stefanbuck authored and josephfrazier committed Oct 6, 2017
1 parent e4bd3de commit f808918
Show file tree
Hide file tree
Showing 70 changed files with 598 additions and 571 deletions.
8 changes: 6 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module.exports = {
extends: ['airbnb-base', 'plugin:import/errors'],
plugins: ['mocha'],
extends: ['airbnb-base', 'plugin:import/errors', 'prettier'],
plugins: ['prettier', 'mocha'],
env: {
browser: true,
mocha: true
},
rules: {
'prettier/prettier': ['error', {
singleQuote: true,
trailingComma: 'all',
}],
'func-names': 0,
'id-length': [1, {'exceptions': ['$']}],
'new-cap': [2, {'capIsNewExceptions': ['Deferred']}],
Expand Down
5 changes: 2 additions & 3 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

const webpackConfig = require('./webpack.config');

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

module.exports = function (config) {
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['detectBrowsers', 'mocha', 'fixture'],
detectBrowsers: {
postDetection(availableBrowsers) {
return availableBrowsers
.filter(browser => ['Chrome', 'Firefox'].includes(browser))
.map((browser) => {
.map(browser => {
if (browser === 'Chrome' && process.env.TRAVIS) {
return 'Chrome_travis_ci';
}
Expand Down
15 changes: 8 additions & 7 deletions lib/background/insight.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class Insight {
this.cid = clientId;
}

track({
category, action, label, value,
}) {
track({ category, action, label, value }) {
const params = {
t: 'event',
ec: category,
Expand All @@ -50,10 +48,13 @@ class Insight {
if (label) params.el = label;
if (value) params.ev = value;

return send({
tid: this.tid,
cid: this.cid,
}, params);
return send(
{
tid: this.tid,
cid: this.cid,
},
params,
);
}
}

Expand Down
12 changes: 8 additions & 4 deletions lib/click-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { showTooltip } from './gh-interface.js';
import * as storage from './options/storage.js';
import fetch from './utils/fetch.js';

const SORRY = 'I\'m sorry, unable to resolve this link 😱';
const SORRY = "I'm sorry, unable to resolve this link 😱";
const PROCESS = 'Processing ⏳';
const RESOLVED = 'Redirecting 🚀';

Expand Down Expand Up @@ -47,7 +47,7 @@ function getResolverUrls(dataAttr) {
},
});

return [].concat(resolver(dataAttr)).map((url) => {
return [].concat(resolver(dataAttr)).map(url => {
if (!url) {
return null;
}
Expand Down Expand Up @@ -111,7 +111,11 @@ async function onClick(event) {
track('success');
showTooltip($tooltipTarget, RESOLVED);

const newWindow = (storage.get('newWindow') || event.metaKey || event.ctrlKey || event.which === 2);
const newWindow =
storage.get('newWindow') ||
event.metaKey ||
event.ctrlKey ||
event.which === 2;
const newWindowActive = storage.get('newWindowActive');
openUrl((res || {}).url || url, newWindow, newWindowActive);
} catch (err) {
Expand All @@ -122,7 +126,7 @@ async function onClick(event) {
}
}

export default function (_pluginManager) {
export default function(_pluginManager) {
$body.undelegate(LINK_SELECTOR, 'click', onClick);
$body.undelegate(LINK_SELECTOR, 'mouseup', onClick);

Expand Down
2 changes: 1 addition & 1 deletion lib/debug-mode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function (enable = false) {
export default function(enable = false) {
if (!enable) {
return;
}
Expand Down
16 changes: 12 additions & 4 deletions lib/insert-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ function wrapsInnerString(text, matchValue, dataAttrObject) {
const [leftSide, rightSide] = text.split(matchValue);
const openingQuote = getQuoteAtPos(matchValue, 0);
const closingQuote = getQuoteAtPos(matchValue, matchValue.length - 1);
const linkText = matchValue.slice(openingQuote ? 1 : 0, closingQuote ? matchValue.length - 1 : undefined);
const linkText = matchValue.slice(
openingQuote ? 1 : 0,
closingQuote ? matchValue.length - 1 : undefined,
);

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

function replace(portion, match, dataAttr, captureGroup) {
const { text, node, indexInMatch } = portion;
const isAlreadyWrapped = (node.parentNode.parentNode || node.parentNode).classList.contains(CLASS_NAME);
const isAlreadyWrapped = (node.parentNode.parentNode || node.parentNode
).classList.contains(CLASS_NAME);
if (isAlreadyWrapped) {
return text;
}
Expand All @@ -143,7 +147,11 @@ function replace(portion, match, dataAttr, captureGroup) {
return wrapsInnerString(text, matchValue, dataAttrObject);
}

const { valueStartPos, valueEndPos, portionEndPos } = getIndexes(portion, match[0], matchValue);
const { valueStartPos, valueEndPos, portionEndPos } = getIndexes(
portion,
match[0],
matchValue,
);
if (valueStartPos === indexInMatch) {
if (portionEndPos === valueEndPos) {
return createLinkElement(text, dataAttrObject);
Expand All @@ -156,7 +164,7 @@ function replace(portion, match, dataAttr, captureGroup) {
return text;
}

export default function (el, regex, mapping, captureGroup = '$1') {
export default function(el, regex, mapping, captureGroup = '$1') {
if (!(el instanceof HTMLElement)) {
throw new Error('must be called with a DOM element');
}
Expand Down
5 changes: 3 additions & 2 deletions lib/load-plugins.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

// Load all plugins from /lib/plugins/*/index.js.
// For more information about dynamic require see
// https://webpack.github.io/docs/context.html

export default function loadPlugins() {
function requireAll(requireContext) {
return requireContext.keys().map(pluginPath => requireContext(pluginPath).default);
return requireContext
.keys()
.map(pluginPath => requireContext(pluginPath).default);
}

return requireAll(require.context('./plugins', false, /[^/]*.js$/));
Expand Down
11 changes: 8 additions & 3 deletions lib/notification.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { showNotification } from './gh-interface';
import * as storage from './options/storage.js';

const pkgVersion = require('../package.json').version.split('.').slice(0, -1).join('.');
const pkgVersion = require('../package.json')
.version.split('.')
.slice(0, -1)
.join('.');

export default async function () {
export default async function() {
const showUpdateNotification = storage.get('showUpdateNotification');

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

if (installedVersion && installedVersion !== pkgVersion) {
const response = await fetch('https://api.github.com/repos/octolinker/browser-extension/releases/latest');
const response = await fetch(
'https://api.github.com/repos/octolinker/browser-extension/releases/latest',
);
const json = await response.json();
const description = json.body.split('\n')[0];
const url = json.html_url;
Expand Down
7 changes: 3 additions & 4 deletions lib/octo-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import debugMode from './debug-mode.js';
import loadPlugins from './load-plugins';
import * as storage from './options/storage.js';


function initialize(self) {
debugMode(storage.get('debugMode'));
notification();
Expand All @@ -25,18 +24,18 @@ function run(self) {

self._blobReader.read();

self._blobReader.forEach((blob) => {
self._blobReader.forEach(blob => {
const plugins = self._pluginManager.get(blob.path, blob.el.classList);

if (!plugins.length) {
return;
}

plugins.forEach((plugin) => {
plugins.forEach(plugin => {
if (plugin.parseBlob) {
plugin.parseBlob(blob);
} else if (plugin.getLinkRegexes) {
[].concat(plugin.getLinkRegexes(blob)).forEach((regex) => {
[].concat(plugin.getLinkRegexes(blob)).forEach(regex => {
insertLink(blob.el, regex, {
pluginName: plugin.name,
target: '$1',
Expand Down
6 changes: 2 additions & 4 deletions lib/options/components/checkbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export default ({
name, label, value, defaultValue, description,
}) => {
const val = (value === undefined) ? defaultValue : value;
export default ({ name, label, value, defaultValue, description }) => {
const val = value === undefined ? defaultValue : value;
const note = description ? `<p class="note">${description}</p>` : '';

return `<div class="form-checkbox">
Expand Down
2 changes: 1 addition & 1 deletion lib/options/components/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import checkbox from './checkbox';
import input from './input';

export default function ({ type, ...rest }) {
export default function({ type, ...rest }) {
if (type === 'checkbox') {
return checkbox(rest);
} else if (type === 'text' || type === 'password') {
Expand Down
6 changes: 2 additions & 4 deletions lib/options/components/input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export default ({
type, name, label, value, defaultValue, description,
}) => {
const val = (value === undefined) ? defaultValue : value;
export default ({ type, name, label, value, defaultValue, description }) => {
const val = value === undefined ? defaultValue : value;
const note = description ? `<p class="note">${description}</p>` : '';

return `<dl class="form-group">
Expand Down
3 changes: 2 additions & 1 deletion lib/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export const options = [
name: 'githubToken',
label: 'Access token',
sensitiveData: true,
description: 'If you want better <strong>Sass, Less or Haskell support</strong> for private repositories, you\'ll need to <a href="https://github.com/settings/tokens/new?scopes=repo&description=OctoLinker%20browser%20extension">create a token</a> with the repo permissions.',
description:
'If you want better <strong>Sass, Less or Haskell support</strong> for private repositories, you\'ll need to <a href="https://github.com/settings/tokens/new?scopes=repo&description=OctoLinker%20browser%20extension">create a token</a> with the repo permissions.',
defaultValue: '',
},
{
Expand Down
2 changes: 1 addition & 1 deletion lib/options/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { options } from './options';
const formEl = document.querySelector('#options');

storage.load().then(() => {
options.forEach((item) => {
options.forEach(item => {
formEl.innerHTML += components({
...item,
value: storage.get(item.name),
Expand Down
2 changes: 1 addition & 1 deletion lib/options/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const chromep = new ChromePromise();
const store = {};
const defaults = {};

options.forEach((item) => {
options.forEach(item => {
if (item.sensitiveData) {
return;
}
Expand Down
10 changes: 6 additions & 4 deletions lib/plugin-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ function updatePluginsForKey(lookup, plugin, key) {
function buildPluginCache(plugins) {
const lookup = new Map();

plugins.forEach((plugin) => {
plugin.getPattern().pathPatterns.forEach((pattern) => {
plugins.forEach(plugin => {
plugin.getPattern().pathPatterns.forEach(pattern => {
updatePluginsForKey(lookup, plugin, RegExp(pattern));
});

if (!plugin.getPattern().githubClasses) {
return;
}

plugin.getPattern().githubClasses.forEach((githubClass) => {
plugin.getPattern().githubClasses.forEach(githubClass => {
updatePluginsForKey(lookup, plugin, githubClass);
});
});
Expand All @@ -47,7 +47,9 @@ function getPluginsForPath(plugins, filepath) {
}

function getPluginsForGithubClasses(plugins, classList) {
return flattenAndCompact(Array.from(classList).map(plugins.get.bind(plugins)));
return flattenAndCompact(
Array.from(classList).map(plugins.get.bind(plugins)),
);
}

export default class {
Expand Down
5 changes: 1 addition & 4 deletions lib/plugins/bower-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ export default {
return liveResolverQuery({ type: 'bower', target });
}

return [
gitUrl({ target }),
githubShorthand({ target }),
];
return [gitUrl({ target }), githubShorthand({ target })];
},

getPattern() {
Expand Down
9 changes: 2 additions & 7 deletions lib/plugins/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ export default {
name: 'CSS',

resolve({ target, path }) {
return [
relativeFile({ path, target }),
];
return [relativeFile({ path, target })];
},

getPattern() {
return {
pathPatterns: ['.css$'],
githubClasses: [
'type-css',
'highlight-source-css',
],
githubClasses: ['type-css', 'highlight-source-css'],
};
},

Expand Down
9 changes: 2 additions & 7 deletions lib/plugins/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ export default {
isOffical = false;
}

return [
`https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`,
];
return [`https://hub.docker.com/${isOffical ? '_' : 'r'}/${imageName}`];
},

getPattern() {
return {
pathPatterns: ['/Dockerfile$'],
githubClasses: [
'type-dockerfile',
'highlight-source-dockerfile',
],
githubClasses: ['type-dockerfile', 'highlight-source-dockerfile'],
};
},

Expand Down
10 changes: 2 additions & 8 deletions lib/plugins/go.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@ export default {
return githubUrls(target);
}

return [
`https://${target}`,
`https://golang.org/pkg/${target}`,
];
return [`https://${target}`, `https://golang.org/pkg/${target}`];
},

getPattern() {
return {
pathPatterns: ['.go$'],
githubClasses: [
'type-go',
'highlight-source-go',
],
githubClasses: ['type-go', 'highlight-source-go'],
};
},

Expand Down
Loading

0 comments on commit f808918

Please sign in to comment.