add linting (#27)

This commit is contained in:
Lynn 2017-03-03 16:07:48 -08:00 committed by GitHub
parent 40e6b173af
commit 71387c1dce
12 changed files with 254 additions and 210 deletions

6
.eslintignore Normal file
View File

@ -0,0 +1,6 @@
build
config
coverage
dist
installer
node_modules

30
.eslintrc Normal file
View File

@ -0,0 +1,30 @@
{
"extends": [
"airbnb-base/rules/best-practices",
"airbnb-base/rules/errors",
"airbnb-base/rules/node",
"airbnb-base/rules/strict",
"airbnb-base/rules/variables"
],
"rules": {
"comma-dangle": 0,
"vars-on-top": 0,
"one-var": 0,
"indent": [ 2, 4, {
"SwitchCase": 1
} ],
"space-in-parens": 0,
"func-names" : 0,
"eol-last": 0,
"no-use-before-define": 0,
"strict": 0
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"globals": {
"SYM_API": true
}
}

View File

@ -21,8 +21,8 @@ electron.app.on('certificate-error', function(event, webContents, url, error,
return;
}
let browserWin = electron.BrowserWindow.fromWebContents(webContents);
var buttonId = electron.dialog.showMessageBox(browserWin, {
const browserWin = electron.BrowserWindow.fromWebContents(webContents);
const buttonId = electron.dialog.showMessageBox(browserWin, {
type: 'warning',
buttons: [ 'Allow', 'Deny', 'Ignore All' ],
defaultId: 1,

View File

@ -3,11 +3,13 @@
const electron = require('electron');
const app = electron.app;
const nodeURL = require('url');
const squirrelStartup = require('electron-squirrel-startup');
const getConfig = require('./getConfig.js');
const { isMac } = require('./utils.js');
// exit early for squirrel installer
if (require('electron-squirrel-startup')) {
if (squirrelStartup) {
return;
}

View File

@ -5,7 +5,6 @@
* from the renderer process.
*/
const electron = require('electron');
const path = require('path');
const windowMgr = require('./windowMgr.js');
const log = require('./log.js');
@ -18,8 +17,8 @@ const log = require('./log.js');
function isValidWindow(event) {
if (event && event.sender) {
// validate that event sender is from window we created
let browserWin = electron.BrowserWindow.fromWebContents(event.sender);
let winKey = event.sender.browserWindowOptions &&
const browserWin = electron.BrowserWindow.fromWebContents(event.sender);
const winKey = event.sender.browserWindowOptions &&
event.sender.browserWindowOptions.webPreferences &&
event.sender.browserWindowOptions.webPreferences.winKey;
@ -43,15 +42,15 @@ function isCmdAllowed(event, cmd) {
// validate that event sender is from window we created
let browserWin = electron.BrowserWindow.fromWebContents(event.sender);
if (windowMgr.isMainWindow(browserWin)) {
if (!windowMgr.isMainWindow(browserWin)) {
// allow all commands for main window
return true;
} else {
}
// allow only certain cmds for child windows
// e.g., open cmd not allowed for child windows
return (cmdBlackList.indexOf(cmd) === -1)
}
}
return false;
}
@ -62,12 +61,16 @@ function isCmdAllowed(event, cmd) {
*/
electron.ipcMain.on('symphony-api', (event, arg) => {
if (!isValidWindow(event)) {
/* eslint-disable no-console */
console.log('invalid window try to perform action, ignoring action.');
/* eslint-enable no-console */
return;
}
if (!isCmdAllowed(event, arg && arg.cmd)) {
/* eslint-disable no-console */
console.log('cmd not allowed for this window: ' + arg.cmd);
/* eslint-enable no-console */
return;
}
@ -91,6 +94,5 @@ electron.ipcMain.on('symphony-api', (event, arg) => {
let width = arg.width || 1024;
let height = arg.height || 768;
windowMgr.createChildWindow(arg.url, title, width, height);
return;
}
});

View File

@ -1,6 +1,5 @@
'use strict';
const electron = require('electron');
const log = require('./log.js');
const logLevels = require('./enums/logLevels.js')

View File

@ -1,36 +1,20 @@
'use strict';
const electron = require('electron');
const template = [
{
label: 'Edit',
submenu: [
{
role: 'undo'
},
{
role: 'redo'
},
{
type: 'separator'
},
{
role: 'cut'
},
{
role: 'copy'
},
{
role: 'paste'
},
{
role: 'pasteandmatchstyle'
},
{
role: 'delete'
},
{
role: 'selectall'
}
{ role: 'undo' },
{ role: 'redo' },
{ type: 'separator' },
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'pasteandmatchstyle' },
{ role: 'delete' },
{ role: 'selectall' }
]
},
{
@ -90,7 +74,7 @@ const template = [
submenu: [
{
label: 'Learn More',
click () { require('electron').shell.openExternal('https://www.symphony.com') }
click () { electron.shell.openExternal('https://www.symphony.com') }
}
]
}

View File

@ -25,7 +25,8 @@ const api = 'symphony-api';
// Note: certain cmds are only allowed on some windows, this is checked by
// main process.
window.SYM_API = {
version: '1.0.0', // api version
// api version
version: '1.0.0',
// only allowed by main window - enforced by main process.
openWindow: function(url) {
@ -60,7 +61,6 @@ window.SYM_API = {
// listen for log message from main process
local.ipcRenderer.on('log', (event, arg) => {
console.log('got msg:' + arg)
if (local.logger && arg && arg.level && arg.msg) {
local.logger({
logLevel: arg.level,
@ -72,7 +72,7 @@ local.ipcRenderer.on('log', (event, arg) => {
function updateOnlineStatus() {
local.ipcRenderer.send(api, {
cmd: 'isOnline',
isOnline: navigator.onLine
isOnline: window.navigator.onLine
});
}

View File

@ -1,7 +1,7 @@
'use strict';
const isDevEnv = process.env.ELECTRON_DEV ?
process.env.ELECTRON_DEV.trim().toLowerCase() === "true" : false;
process.env.ELECTRON_DEV.trim().toLowerCase() === 'true' : false;
const isMac = (process.platform === 'darwin');
@ -12,9 +12,9 @@ const isMac = (process.platform === 'darwin');
* @return {String} guid value in string
*/
function getGuid() {
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
const guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
function(c) {
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
var r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
return guid;

View File

@ -45,10 +45,13 @@ function createMainWindow (url) {
});
function retry() {
if (isOnline) {
mainWindow.webContents && mainWindow.webContents.reload();
} else {
if (!isOnline) {
loadErrors.showNetworkConnectivityError(mainWindow, url, retry);
return;
}
if (mainWindow.webContents) {
mainWindow.webContents.reload();
}
}
@ -63,7 +66,7 @@ function createMainWindow (url) {
});
mainWindow.webContents.on('did-fail-load', function(event, errorCode,
errorDesc, validatedURL, isMainFrame) {
errorDesc) {
loadErrors.showLoadFailure(mainWindow, url, errorDesc, errorCode, retry);
});
@ -75,7 +78,7 @@ function createMainWindow (url) {
mainWindow.on('close', function(e) {
if (willQuitApp) {
mainWindow = null;
destroyMainWindow();
return;
}
// mac should hide window when hitting x close
@ -85,19 +88,23 @@ function createMainWindow (url) {
}
});
mainWindow.on('closed', function () {
function destroyMainWindow() {
removeWindowKey(key);
mainWindow.removeAllEventListeners();
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
if (mainWindow) {
mainWindow.removeAllListeners();
if (mainWindow.webContents) {
mainWindow.webContents.removeAllListeners();
}
mainWindow = null;
});
}
}
mainWindow.on('closed', destroyMainWindow);
// open external links in default browser - window.open
mainWindow.webContents.on('new-window', function(event, url) {
mainWindow.webContents.on('new-window', function(event, newWinUrl) {
event.preventDefault();
electron.shell.openExternal(url);
electron.shell.openExternal(newWinUrl);
});
}
@ -141,8 +148,13 @@ function createChildWindow(url, title, width, height) {
childWindow.loadURL(url);
childWindow.on('closed', function() {
childWindow.removeAllEventListeners();
removeWindowKey(winKey);
if (childWindow) {
childWindow.removeAllListeners();
if (childWindow.webContents) {
childWindow.webContents.removeAllListeners();
}
}
});
}

View File

@ -9,15 +9,19 @@
"dev:mac": "ELECTRON_DEV=true npm run start",
"dev:win": "SET ELECTRON_DEV=true && npm run start",
"start": "electron .",
"dist-mac": "build --mac",
"dist-win": "build --win --x64",
"dist-win-x86": "build --win --ia32",
"unpacked-win": "build --win --x64 --dir",
"unpacked-win-x86": "build --win --ia32 --dir",
"test": "jest --coverage"
"dist-mac": "npm run test && npm run lint && build --mac",
"dist-win": "npm run test && npm run lint && build --win --x64",
"dist-win-x86": "npm run test && npm run lint && build --win --ia32",
"unpacked-win": "npm run test && npm run lint && build --win --x64 --dir",
"unpacked-win-x86": "npm run test && npm run lint && build --win --ia32 --dir",
"test": "jest --coverage",
"lint": "eslint js/**"
},
"build": {
"files": [ "!installer/*", "!tests/*" ],
"files": [
"!installer/*",
"!tests/*"
],
"extraFiles": "config/Symphony.config",
"appId": "symphony-electron-desktop",
"mac": {
@ -59,6 +63,11 @@
"electron-builder": "^13.9.0",
"electron-builder-squirrel-windows": "^12.3.0",
"electron-packager": "^8.5.2",
"eslint": "^3.16.1",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.0",
"jest": "^19.0.2"
},
"dependencies": {