Skip to content

Commit a75dd31

Browse files
committed
tweaks based on eslint
1 parent 48bd1db commit a75dd31

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

.eslintrc.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
"extends": "eslint:recommended",
3+
"globals": {
4+
"Utils" : "writable",
5+
"UART" : "readonly",
6+
"Puck" : "readonly"
7+
},
8+
"rules": {
9+
"indent": [
10+
"off",
11+
2,
12+
{
13+
"SwitchCase": 1
14+
}
15+
],
16+
"no-constant-condition": "off",
17+
"no-empty": ["warn", { "allowEmptyCatch": true }],
18+
"no-global-assign": "off",
19+
"no-inner-declarations": "off",
20+
"no-prototype-builtins": "off",
21+
"no-redeclare": "off",
22+
"no-unreachable": "warn",
23+
"no-cond-assign": "warn",
24+
"no-useless-catch": "warn",
25+
"no-undef": "warn",
26+
"no-unused-vars": ["warn", { "args": "none" } ],
27+
"no-useless-escape": "off",
28+
"no-control-regex" : "off"
29+
},
30+
reportUnusedDisableDirectives: true,
31+
}

js/appinfo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function translateJS(options, app, code) {
7272
// remap any chars that we don't think we can display in Espruino's
7373
// built in fonts.
7474
translation = Utils.convertStringToISO8859_1(translation);
75-
tokenString = toJSString(translation);
75+
tokenString = Utils.toJSString(translation);
7676
}
7777
} else if (tok.str.startsWith("`")) {
7878
// it's a tempated String! scan all clauses inside it and re-run on the JS in those

js/comms.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Puck = {
2525

2626
/// Add progress handler so we get nice upload progress shown
2727
{
28-
let COMMS = (typeof UART !== undefined)?UART:Puck;
28+
let COMMS = (typeof UART != "undefined")?UART:Puck;
2929
COMMS.writeProgress = function(charsSent, charsTotal) {
3030
if (charsSent===undefined || charsTotal<10) {
3131
Progress.hide();
@@ -41,7 +41,7 @@ const Comms = {
4141
// Low Level Comms
4242
/// enable debug print statements
4343
debug : () => {
44-
if (typeof UART !== undefined)
44+
if (typeof UART !== "undefined")
4545
UART.debug = 3;
4646
else
4747
Puck.debug = 3;
@@ -55,7 +55,7 @@ const Comms = {
5555
write : (data, options) => {
5656
if (data===undefined) throw new Error("Comms.write(undefined) called!")
5757
options = options||{};
58-
if (typeof UART !== undefined) { // New method
58+
if (typeof UART !== "undefined") { // New method
5959
return UART.write(data, undefined, !!options.waitNewLine);
6060
} else { // Old method
6161
return new Promise((resolve,reject) =>
@@ -69,7 +69,7 @@ const Comms = {
6969
/// Evaluate the given expression, return the result as a promise
7070
eval : (expr) => {
7171
if (expr===undefined) throw new Error("Comms.eval(undefined) called!")
72-
if (typeof UART === undefined) { // New method
72+
if (typeof UART === "undefined") { // New method
7373
return UART.eval(expr);
7474
} else { // Old method
7575
return new Promise((resolve,reject) =>
@@ -82,15 +82,15 @@ const Comms = {
8282
},
8383
/// Return true if we're connected, false if not
8484
isConnected : () => {
85-
if (typeof UART !== undefined) { // New method
85+
if (typeof UART !== "undefined") { // New method
8686
return UART.isConnected();
8787
} else { // Old method
8888
return Puck.isConnected();
8989
}
9090
},
9191
/// Get the currently active connection object
9292
getConnection : () => {
93-
if (typeof UART !== undefined) { // New method
93+
if (typeof UART !== "undefined") { // New method
9494
return UART.getConnection();
9595
} else { // Old method
9696
return Puck.getConnection();
@@ -331,8 +331,8 @@ const Comms = {
331331
console.log("<COMMS> watch was in debug mode, interrupting.", result);
332332
// we got a debug prompt - we interrupted the watch while JS was executing
333333
// so we're in debug mode, issue another ctrl-c to bump the watch out of it
334-
return Comms.write("\x03").then(checkCtrlC);
335334
interrupts++;
335+
return Comms.write("\x03").then(checkCtrlC);
336336
} else {
337337
return result;
338338
}
@@ -378,7 +378,7 @@ const Comms = {
378378
return reject("No response from device. Is 'Programmable' set to 'Off'?");
379379
}
380380
// now try and parse
381-
let info = {};
381+
let err, info = {};
382382
let appList;
383383
try {
384384
appList = JSON.parse(appListJSON);
@@ -446,21 +446,21 @@ const Comms = {
446446
app.files=app.id+".info";
447447
}
448448
if (Const.FILES_IN_FS)
449-
cmds += app.files.split(',').filter(f=>f!="").map(file => `\x10require("fs").unlinkSync(${toJSString(file)});\n`).join("");
449+
cmds += app.files.split(',').filter(f=>f!="").map(file => `\x10require("fs").unlinkSync(${Utils.toJSString(file)});\n`).join("");
450450
else
451-
cmds += app.files.split(',').filter(f=>f!="").map(file => `\x10require("Storage").erase(${toJSString(file)});\n`).join("");
451+
cmds += app.files.split(',').filter(f=>f!="").map(file => `\x10require("Storage").erase(${Utils.toJSString(file)});\n`).join("");
452452
// remove app Data: (dataFiles and storageFiles)
453453
const data = AppInfo.parseDataString(app.data)
454454
const isGlob = f => /[?*]/.test(f)
455455
// regular files, can use wildcards
456456
cmds += data.dataFiles.map(file => {
457-
if (!isGlob(file)) return `\x10require("Storage").erase(${toJSString(file)});\n`;
457+
if (!isGlob(file)) return `\x10require("Storage").erase(${Utils.toJSString(file)});\n`;
458458
const regex = new RegExp(globToRegex(file))
459459
return `\x10require("Storage").list(${regex}).forEach(f=>require("Storage").erase(f));\n`;
460460
}).join("");
461461
// storageFiles, can use wildcards
462462
cmds += data.storageFiles.map(file => {
463-
if (!isGlob(file)) return `\x10require("Storage").open(${toJSString(file)},'r').erase();\n`;
463+
if (!isGlob(file)) return `\x10require("Storage").open(${Utils.toJSString(file)},'r').erase();\n`;
464464
// storageFiles have a chunk number appended to their real name
465465
const regex = globToRegex(file+'\u0001')
466466
// open() doesn't want the chunk number though

0 commit comments

Comments
 (0)