Skip to content

Commit

Permalink
Move to the "standard" JS linter & formatter
Browse files Browse the repository at this point in the history
- Closes #42
  • Loading branch information
lidel committed Jan 16, 2016
1 parent 819937e commit 701443c
Show file tree
Hide file tree
Showing 16 changed files with 714 additions and 791 deletions.
13 changes: 3 additions & 10 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
"rules": {
"indent": [1,2],
"quotes": [1,"single"],
"linebreak-style": [1,"unix"],
"no-console": 1,
"semi": [1,"always"]
"space-before-function-paren": 1,
"padded-blocks": 1
},
"env": {
"es6": true,
"browser": true,
"node": true
},
"extends": "eslint:recommended"
"extends": "standard"
}
60 changes: 7 additions & 53 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,19 @@
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
var jsPaths = ['*.js', 'lib/**.js', 'test/**.js', 'data/**.js'];
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt)
var jsPaths = ['*.js', 'lib/**.js', 'test/**.js', 'data/**.js']
grunt.initConfig({
eslint: {
target: jsPaths
},
jsbeautifier: {
files: ['data/**.html', 'data/**.css'].concat(jsPaths),
options: {
js: {
braceStyle: 'collapse',
breakChainedMethods: false,
e4x: false,
evalCode: false,
indentChar: ' ',
indentLevel: 0,
indentSize: 2,
indentWithTabs: false,
jslintHappy: false,
keepArrayIndentation: false,
keepFunctionIndentation: false,
maxPreserveNewlines: 10,
preserveNewlines: true,
spaceBeforeConditional: true,
spaceInParen: false,
unescapeStrings: false,
wrapLineLength: 0,
endWithNewline: true
},
html: {
braceStyle: 'collapse',
indentSize: 4,
indentChar: ' ',
indentScripts: 'keep',
indentWithTabs: false,
maxPreserveNewlines: 10,
preserveNewlines: true,
unformatted: ['a', 'sub', 'sup', 'b', 'i', 'u'],
wrapLineLength: 0,
endWithNewline: true
},
css: {
indentSize: 4,
indentChar: ' '
}
}

},
run: {
jpm_test: {
cmd: 'jpm',
args: ['-b', process.env.FIREFOX_BIN || 'firefox', 'test']
}
}
});

grunt.loadNpmTasks('grunt-jsbeautifier');
grunt.loadNpmTasks('grunt-run');

grunt.registerTask('travis', ['run:jpm_test', 'eslint']);
grunt.registerTask('default', ['jsbeautifier', 'travis']);
})

};
grunt.registerTask('test', ['run:jpm_test', 'eslint'])
grunt.registerTask('default', ['test'])
}
// vim:ts=2:sw=2:et:
30 changes: 16 additions & 14 deletions data/panel.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
/* global self */

// incoming
self.port.on('show', function(ipfsResource) {
//console.log('show event received by panel.js (ipfsResource='+ipfsResource+')');
self.port.on('show', function (ipfsResource) {
// console.log('show event received by panel.js (ipfsResource='+ipfsResource+')')

// show/hide ipfs-only items
document.getElementById('ipfs-only')
.style.display = ipfsResource ? 'block' : 'none';
});
.style.display = ipfsResource ? 'block' : 'none'
})

// outgoing
function forwardClickEvent(eventName) {
function forwardClickEvent (eventName) {
document.getElementById(eventName)
.addEventListener('click', function(event) { // eslint-disable-line no-unused-vars
self.port.emit(eventName);
});
.addEventListener('click', function (event) { // eslint-disable-line no-unused-vars
self.port.emit(eventName)
})
}

// always visible
forwardClickEvent('toggle-gateway-redirect');
forwardClickEvent('open-webui');
forwardClickEvent('open-preferences');
forwardClickEvent('toggle-gateway-redirect')
forwardClickEvent('open-webui')
forwardClickEvent('open-preferences')

// ipfs-only
forwardClickEvent('pin-current-ipfs-address');
forwardClickEvent('copy-current-ipfs-address');
forwardClickEvent('copy-current-public-gw-url');
forwardClickEvent('pin-current-ipfs-address')
forwardClickEvent('copy-current-ipfs-address')
forwardClickEvent('copy-current-public-gw-url')
12 changes: 6 additions & 6 deletions lib/child-main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';
'use strict'

const protocols = require('./protocols.js');
const protocols = require('./protocols.js')

protocols.register();
require("./rewrite-pages.js");
protocols.register()
require('./rewrite-pages.js')

require('sdk/system/unload').when(() => {
protocols.unregister();
});
protocols.unregister()
})
115 changes: 56 additions & 59 deletions lib/gateways.js
Original file line number Diff line number Diff line change
@@ -1,107 +1,104 @@
'use strict';
'use strict'

const {
Cc, Ci
} = require('chrome');
const {Cc, Ci} = require('chrome')

const prefs = require('sdk/simple-prefs').prefs
const ioservice = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService)

const prefs = require('sdk/simple-prefs').prefs;
const ioservice = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
const IPFS_RESOURCE = /^https?:\/\/[^\/]+\/ip(f|n)s\//

const IPFS_RESOURCE = /^https?:\/\/[^\/]+\/ip(f|n)s\//;
exports.IPFS_RESOURCE = IPFS_RESOURCE

exports.IPFS_RESOURCE = IPFS_RESOURCE;
var PUBLIC_GATEWAY_HOSTS // getPublicGatewayHostsRegex()
var PUBLIC_GATEWAY_URI // getDefaultPublicURI()
var CUSTOM_GATEWAY_URI
var CUSTOM_API_URI

var PUBLIC_GATEWAY_HOSTS; // getPublicGatewayHostsRegex()
var PUBLIC_GATEWAY_URI; // getDefaultPublicURI();
var CUSTOM_GATEWAY_URI;
var CUSTOM_API_URI;

function getPublicGatewayHostList() {
return prefs.publicGatewayHosts.split(/,|;| |\|/);
function getPublicGatewayHostList () {
return prefs.publicGatewayHosts.split(/,|;| |\|/)
}

function getDefaultPublicURI() {
var hosts = getPublicGatewayHostList();
return ioservice.newURI('https://' + hosts[0], null, null);
function getDefaultPublicURI () {
var hosts = getPublicGatewayHostList()
return ioservice.newURI('https://' + hosts[0], null, null)
}

function getPublicGatewayHostsRegex() {
var hosts = getPublicGatewayHostList();
var hostsRegex = '';
function getPublicGatewayHostsRegex () {
var hosts = getPublicGatewayHostList()
var hostsRegex = ''
for (var i = 0; i < hosts.length; i++) {
if (i > 0) {
hostsRegex += '|';
hostsRegex += '|'
}
hostsRegex += hosts[i].trim().replace(/[^\w\s]/g, '\\$&');
hostsRegex += hosts[i].trim().replace(/[^\w\s]/g, '\\$&')
}
return new RegExp('^https?:\/\/(' + hostsRegex + ')\/');
return new RegExp('^https?:\/\/(' + hostsRegex + ')\/')
}

const callbacks = [];
const callbacks = []

exports.reload = (function f(changedProperty) { // eslint-disable-line no-unused-vars
exports.reload = (function f (changedProperty) { // eslint-disable-line no-unused-vars
// public gateways
PUBLIC_GATEWAY_URI = getDefaultPublicURI();
PUBLIC_GATEWAY_HOSTS = getPublicGatewayHostsRegex();
PUBLIC_GATEWAY_URI = getDefaultPublicURI()
PUBLIC_GATEWAY_HOSTS = getPublicGatewayHostsRegex()

// custom gateway
CUSTOM_GATEWAY_URI = ioservice.newURI('http://' + prefs.customGatewayHost + ':' + prefs.customGatewayPort, null, null);
CUSTOM_API_URI = ioservice.newURI('http://' + prefs.customGatewayHost + ':' + prefs.customApiPort, null, null);
CUSTOM_GATEWAY_URI = ioservice.newURI('http://' + prefs.customGatewayHost + ':' + prefs.customGatewayPort, null, null)
CUSTOM_API_URI = ioservice.newURI('http://' + prefs.customGatewayHost + ':' + prefs.customApiPort, null, null)

callbacks.forEach((c) => c());
callbacks.forEach((c) => c())

return f;
})(); // define & execute once
return f
})() // define & execute once

// execute on each Preference change
require('sdk/simple-prefs').on('', exports.reload);
require('sdk/simple-prefs').on('', exports.reload)

// execute function and add it to callback list
exports.onPreferencesChange = (f) => {
f();
callbacks.push(f);
};
f()
callbacks.push(f)
}

exports.isPinnable = (uriSpec) => {
return uriSpec && uriSpec.match(IPFS_RESOURCE) != null && !uriSpec.startsWith(CUSTOM_API_URI.spec);
};
return uriSpec && uriSpec.match(IPFS_RESOURCE) != null && !uriSpec.startsWith(CUSTOM_API_URI.spec)
}

Object.defineProperty(exports, 'customUri', {
get: function() {
return CUSTOM_GATEWAY_URI;
get: function () {
return CUSTOM_GATEWAY_URI
}
});
})

Object.defineProperty(exports, 'apiUri', {
get: function() {
return CUSTOM_API_URI;
get: function () {
return CUSTOM_API_URI
}
});
})

Object.defineProperty(exports, 'publicUri', {
get: function() {
return PUBLIC_GATEWAY_URI;
get: function () {
return PUBLIC_GATEWAY_URI
}
});
})

Object.defineProperty(exports, 'publicHosts', {
get: function() {
return PUBLIC_GATEWAY_HOSTS;
get: function () {
return PUBLIC_GATEWAY_HOSTS
}
});
})

Object.defineProperty(exports, 'redirectEnabled', {
get: function() {
return prefs.useCustomGateway;
get: function () {
return prefs.useCustomGateway
},
set: function(value) {
prefs.useCustomGateway = !!value;
set: function (value) {
prefs.useCustomGateway = !!value
}
});
})

Object.defineProperty(exports, 'linkify', {
get: function() {
return prefs.linkify;
get: function () {
return prefs.linkify
}
});
})
Loading

0 comments on commit 701443c

Please sign in to comment.