diff --git a/.eslintrc.json b/.eslintrc.json index 0bba253..78b9b4c 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -2,6 +2,7 @@ "env": { "browser": true }, + "parser": "babel-eslint", "extends": "eslint:recommended", "rules": { "accessor-pairs": "error", @@ -96,7 +97,7 @@ "no-extra-label": "error", "no-extra-parens": "off", "no-floating-decimal": "error", - "no-implicit-coercion": "error", + "no-implicit-coercion": "off", "no-implicit-globals": "off", "no-implied-eval": "error", "no-inline-comments": "off", @@ -262,6 +263,7 @@ "esprima": true, "escodegen": true, "utils": true, - "Promise": true + "Promise": true, + "Inlet": true } } diff --git a/.travis.yml b/.travis.yml index ad20d55..56b4205 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: node_js node_js: - - '4.0' + - '6.0' install: - npm install -g eslint + - npm install -g babel-eslint script: - eslint src/*.js \ No newline at end of file diff --git a/src/analytics.js b/src/analytics.js index e0d4551..d1c3a12 100644 --- a/src/analytics.js +++ b/src/analytics.js @@ -1,3 +1,5 @@ +/* global ga */ +// eslint-disable-next-line max-params window.trackEvent = function (category, action, label, value) { if (window.DEBUG) { utils.log('trackevent', category, action, label, value) @@ -10,6 +12,8 @@ window.trackEvent = function (category, action, label, value) { // if online, load after 2 seconds if (navigator.onLine && !window.DEBUG) { + /* eslint-disable */ + setTimeout(function() { (function(i,s,o,g,r,a,m){ i['GoogleAnalyticsObject']=r; @@ -23,4 +27,6 @@ if (navigator.onLine && !window.DEBUG) { ga('set', 'checkProtocolTask', function(){ /* nothing */ }); ga('send', 'pageview'); }, 0); + + /* eslint-enable */ } \ No newline at end of file diff --git a/src/library-list.js b/src/library-list.js index 1ab77a1..ce3dd46 100644 --- a/src/library-list.js +++ b/src/library-list.js @@ -12,5 +12,5 @@ window.cssLibs = [ { url: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css', label: 'Bootstrap', type: 'css' }, { url: 'https://cdnjs.cloudflare.com/ajax/libs/foundation/6.2.3/foundation.min.css', label: 'Foundation', type: 'css' }, { url: 'https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.5.2/animate.min.css', label: 'Animate.css', type: 'css' }, - { url: 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/2.4.1/hint.min.css', label: 'Hint.css', type: 'css'} + { url: 'https://cdnjs.cloudflare.com/ajax/libs/hint.css/2.4.1/hint.min.css', label: 'Hint.css', type: 'css' } ] \ No newline at end of file diff --git a/src/script.js b/src/script.js index 4c4b2aa..e4dd0ee 100644 --- a/src/script.js +++ b/src/script.js @@ -1,3 +1,4 @@ +/* global trackEvent */ /* eslint-disable no-extra-semi */ ;(function (alertsService) { @@ -107,7 +108,7 @@ } } - function resetSplitting(dontRecreate) { + function resetSplitting() { if (codeSplitInstance) { codeSplitInstance.destroy(); } @@ -170,8 +171,8 @@ function updateExternalLibUi() { // Calculate no. of external libs var noOfExternalLibs = 0; - noOfExternalLibs += externalJsTextarea.value.split('\n').filter(lib => !!lib).length; - noOfExternalLibs += externalCssTextarea.value.split('\n').filter(lib => !!lib).length; + noOfExternalLibs += externalJsTextarea.value.split('\n').filter((lib) => !!lib).length; + noOfExternalLibs += externalCssTextarea.value.split('\n').filter((lib) => !!lib).length; if (noOfExternalLibs) { $('#js-external-lib-count').textContent = noOfExternalLibs; $('#js-external-lib-count').style.display = 'inline'; @@ -223,11 +224,11 @@ var sizes; try { sizes = [ - +htmlCode.style[dimensionProperty].match(/([\d\.]+)%/)[1], - +cssCode.style[dimensionProperty].match(/([\d\.]+)%/)[1], - +jsCode.style[dimensionProperty].match(/([\d\.]+)%/)[1] + +htmlCode.style[dimensionProperty].match(/([\d.]+)%/)[1], + +cssCode.style[dimensionProperty].match(/([\d.]+)%/)[1], + +jsCode.style[dimensionProperty].match(/([\d.]+)%/)[1] ]; - } catch(e) { + } catch (e) { sizes = [ 33.33, 33.33, 33.33 ] } finally { @@ -279,17 +280,19 @@ } savedItems = savedItems || []; - for (var i = 0; i < itemIds.length; i++) { - (function (index) { - chrome.storage.local.get(itemIds[index], function (itemResult) { - savedItems[itemIds[index]] = itemResult[itemIds[index]]; - items.push(itemResult[itemIds[index]]); - // Check if we have all items now. - if (itemIds.length === items.length) { - populateItemsInSavedPane(items); - } - }); - })(i); + for (let i = 0; i < itemIds.length; i++) { + + /* eslint-disable no-loop-func */ + chrome.storage.local.get(itemIds[i], function (itemResult) { + savedItems[itemIds[i]] = itemResult[itemIds[i]]; + items.push(itemResult[itemIds[i]]); + // Check if we have all items now. + if (itemIds.length === items.length) { + populateItemsInSavedPane(items); + } + }); + + /* eslint-enable no-loop-func */ } }); } @@ -526,11 +529,11 @@ } function getCompleteHtml(html, css, js) { - var externalJs = externalJsTextarea.value.split('\n').reduce(function (html, url) { - return html + (url ? '\n' : ''); + var externalJs = externalJsTextarea.value.split('\n').reduce(function (scripts, url) { + return scripts + (url ? '\n' : ''); }, ''); - var externalCss = externalCssTextarea.value.split('\n').reduce(function (html, url) { - return html + (url ? '\n' : ''); + var externalCss = externalCssTextarea.value.split('\n').reduce(function (links, url) { + return links + (url ? '\n' : ''); }, ''); var contents = '\n\n' + externalCss + '\n' diff --git a/src/utils.js b/src/utils.js index 9fd3951..03713f4 100644 --- a/src/utils.js +++ b/src/utils.js @@ -21,9 +21,9 @@ } function generateRandomId(len) { - len = len || 10; + var length = len || 10; var id = ''; - for (var i = len; i--;) { + for (var i = length; i--;) { id += alphaNum[~~(Math.random() * alphaNum.length)]; } return id; @@ -38,7 +38,7 @@ function log() { if (window.DEBUG) { - console.log.apply(console, [].splice.call(arguments, 0)); + console.log(...arguments); } } @@ -58,7 +58,7 @@ * @param {ASTBody} Body of an AST generated by esprima or any ES compliant AST */ function addInfiniteLoopProtection(astBody) { - if (!astBody) return; + if (!astBody) { return; } if (!Array.isArray(astBody)) { addInfiniteLoopProtection(astBody.body); return; @@ -95,7 +95,7 @@ var retVal = d.getDate() + ' ' + [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()] + ' ' + d.getFullYear(); - return retVal; + return retVal; } window.utils = {