From aa193454db630f1bd2ddd8d983dd6e85a2b29a92 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 28 May 2020 08:27:01 +0100 Subject: [PATCH] Now linting library too --- .eslintignore | 4 ++++ js/appinfo.js | 2 +- js/comms.js | 2 +- js/ui.js | 2 +- lib/.eslintrc.json | 26 ++++++++++++++++++++++++++ lib/interface.js | 20 ++++++++++---------- package.json | 2 +- 7 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 lib/.eslintrc.json diff --git a/.eslintignore b/.eslintignore index f33004ee1..7ad7ad68a 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,5 @@ js/espruinotools.js +lib/imageconverter.js +lib/qrcode.min.js +lib/heatshrink.js + diff --git a/js/appinfo.js b/js/appinfo.js index 052597ca9..54f1458db 100644 --- a/js/appinfo.js +++ b/js/appinfo.js @@ -30,7 +30,7 @@ function toJS(txt) { if ("undefined"!=typeof module) Espruino = require("./espruinotools.js"); -let AppInfo = { +const AppInfo = { /* Get files needed for app. options = { fileGetter : callback for getting URL, diff --git a/js/comms.js b/js/comms.js index 602be8227..129250ace 100644 --- a/js/comms.js +++ b/js/comms.js @@ -1,7 +1,7 @@ Puck.debug=3; // FIXME: use UART lib so that we handle errors properly -let Comms = { +const Comms = { reset : (opt) => new Promise((resolve,reject) => { Puck.write(`\x03\x10reset(${opt=="wipe"?"1":""});\n`, (result) => { if (result===null) return reject("Connection failed"); diff --git a/js/ui.js b/js/ui.js index 5c889c177..47016e86b 100644 --- a/js/ui.js +++ b/js/ui.js @@ -1,7 +1,7 @@ // General UI tools (progress bar, toast, prompt) /// Handle progress bars -let Progress = { +const Progress = { domElement : null, // the DOM element sticky : false, // Progress.show({..., sticky:true}) don't remove until Progress.hide({sticky:true}) interval : undefined, // the interval used if Progress.show({progress:"animate"}) diff --git a/lib/.eslintrc.json b/lib/.eslintrc.json new file mode 100644 index 000000000..4b259541a --- /dev/null +++ b/lib/.eslintrc.json @@ -0,0 +1,26 @@ +{ + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "script" + }, + "rules": { + "indent": [ + "warn", + 2, + { + "SwitchCase": 1 + } + ], + "no-undef": "warn", + "no-redeclare": "warn", + "no-var": "warn", + "no-unused-vars":"off" // we define stuff to use in other scripts + }, + "env": { + "browser": true + }, + "extends": "eslint:recommended", + "globals": { + "onInit" : "readonly" + } +} diff --git a/lib/interface.js b/lib/interface.js index 7e8be4fd9..ae883c97f 100644 --- a/lib/interface.js +++ b/lib/interface.js @@ -19,8 +19,8 @@ Util.eraseStorageFile(filename,callback) Util.showModal(title) Util.hideModal() */ -var __id = 0, __idlookup = []; -var Puck = { +let __id = 0, __idlookup = []; +const Puck = { eval : function(data,callback) { __id++; __idlookup[__id] = callback; @@ -32,7 +32,7 @@ var Puck = { } }; -var Util = { +const Util = { readStorageFile : function(filename,callback) { __id++; __idlookup[__id] = callback; @@ -71,25 +71,25 @@ var Util = { Util.domModal.classList.remove("active"); }, saveCSV : function(filename, csvData) { - var a = document.createElement("a"), - file = new Blob([csvData], {type: "Comma-separated value file"}); - var url = URL.createObjectURL(file); + let a = document.createElement("a"), + file = new Blob([csvData], {type: "Comma-separated value file"}); + let url = URL.createObjectURL(file); a.href = url; a.download = filename+".csv"; document.body.appendChild(a); a.click(); setTimeout(function() { - document.body.removeChild(a); - window.URL.revokeObjectURL(url); + document.body.removeChild(a); + window.URL.revokeObjectURL(url); }, 0); } }; window.addEventListener("message", function(event) { - var msg = event.data; + let msg = event.data; if (msg.type=="init") { onInit(); } else if (msg.type=="evalrsp" || msg.type=="writersp"|| msg.type=="readstoragefilersp") { - var cb = __idlookup[msg.id]; + let cb = __idlookup[msg.id]; delete __idlookup[msg.id]; cb(msg.data); } diff --git a/package.json b/package.json index 18ecc3e11..5f62983fe 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "scripts": { "lint-apps": "eslint ./apps --ext .js", - "test": "node bin/sanitycheck.js && eslint ./apps --ext .js && eslint ./js", + "test": "node bin/sanitycheck.js && eslint ./apps --ext .js && eslint ./lib ./js", "start": "npx http-server" }, "dependencies": {