From 9e69fd2e74b4e4972768c2b4a8c1f0b7e0f1da97 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sat, 23 May 2020 22:41:18 +0300 Subject: [PATCH 1/9] buffgym: Code style vs linter Pass redraw as parameter to Workout, instead of using global variable. Make code to honor eslint linebreak-style (use Windows linebreak). Change eslintrc indent rule to match code style. Add missing semicolons. --- apps/buffgym/.eslintrc.json | 3 +- apps/buffgym/buffgym-exercise.js | 306 +++++++++++++++---------------- apps/buffgym/buffgym-icon.js | 2 +- apps/buffgym/buffgym-set.js | 56 +++--- apps/buffgym/buffgym-workout.js | 167 ++++++++--------- apps/buffgym/buffgym.app.js | 2 +- 6 files changed, 269 insertions(+), 267 deletions(-) diff --git a/apps/buffgym/.eslintrc.json b/apps/buffgym/.eslintrc.json index c91a72544..087c94da6 100644 --- a/apps/buffgym/.eslintrc.json +++ b/apps/buffgym/.eslintrc.json @@ -15,7 +15,8 @@ "rules": { "indent": [ "error", - 2 + 2, + { "SwitchCase": 1 } ], "linebreak-style": [ "error", diff --git a/apps/buffgym/buffgym-exercise.js b/apps/buffgym/buffgym-exercise.js index ea20aa132..103ff99b7 100644 --- a/apps/buffgym/buffgym-exercise.js +++ b/apps/buffgym/buffgym-exercise.js @@ -1,153 +1,153 @@ -exports = class Exercise { - constructor(params) { - this.completed = false; - this.sets = []; - this.title = params.title; - this.weight = params.weight; - this.weightIncrement = params.weightIncrement; - this.unit = params.unit; - this.restPeriod = params.restPeriod; - this._originalRestPeriod = params.restPeriod; - this._restTimeout = null; - this._restInterval = null; - this._state = null; - } - - get humanTitle() { - return `${this.title} ${this.weight}${this.unit}`; - } - - get subTitle() { - const totalSets = this.sets.length; - const uncompletedSets = this.sets.filter((set) => !set.isCompleted()).length; - const currentSet = (totalSets - uncompletedSets) + 1; - return `Set ${currentSet} of ${totalSets}`; - } - - decRestPeriod() { - this.restPeriod--; - } - - addSet(set) { - this.sets.push(set); - } - - currentSet() { - return this.sets.filter(set => !set.isCompleted())[0]; - } - - isLastSet() { - return this.sets.filter(set => !set.isCompleted()).length === 1; - } - - isCompleted() { - return !!this.completed; - } - - canSetCompleted() { - return this.sets.filter(set => set.isCompleted()).length === this.sets.length; - } - - setCompleted() { - if (!this.canSetCompleted()) throw "All sets must be completed"; - if (this.canProgress()) this.weight += this.weightIncrement; - this.completed = true; - } - - canProgress() { - let completedRepsTotalSum = 0; - let targetRepsTotalSum = 0; - this.sets.forEach(set => completedRepsTotalSum += set.reps); - this.sets.forEach(set => targetRepsTotalSum += set.maxReps); - - return (targetRepsTotalSum - completedRepsTotalSum) === 0; - } - - startRestTimer(workout) { - this._restTimeout = setTimeout(() => { - this.next(workout); - }, 1000 * this.restPeriod); - - this._restInterval = setInterval(() => { - this.decRestPeriod(); - - if (this.restPeriod < 0) { - this.resetRestTimer(); - this.next(); - - return; - } - - workout.emit("redraw"); - }, 1000 ); - } - - resetRestTimer() { - clearTimeout(this._restTimeout); - clearInterval(this._restInterval); - this._restTimeout = null; - this._restInterval = null; - this.restPeriod = this._originalRestPeriod; - } - - isRestTimerRunning() { - return this._restTimeout != null; - } - - setupStartedButtons(workout) { - clearWatch(); - - setWatch(() => { - this.currentSet().incReps(); - workout.emit("redraw"); - }, BTN1, {repeat: true}); - - setWatch(workout.next.bind(workout), BTN2, {repeat: false}); - - setWatch(() => { - this.currentSet().decReps(); - workout.emit("redraw"); - }, BTN3, {repeat: true}); - } - - setupRestingButtons(workout) { - clearWatch(); - setWatch(workout.next.bind(workout), BTN2, {repeat: false}); - } - - next(workout) { - const STARTED = 1; - const RESTING = 2; - const COMPLETED = 3; - - switch(this._state) { - case null: - this._state = STARTED; - this.setupStartedButtons(workout); - break; - case STARTED: - this._state = RESTING; - this.startRestTimer(workout); - this.setupRestingButtons(workout); - break; - case RESTING: - this.resetRestTimer(); - this.currentSet().setCompleted(); - - if (this.canSetCompleted()) { - this._state = COMPLETED; - this.setCompleted(); - } else { - this._state = null; - } - // As we are changing state and require it to be reprocessed - // invoke the next step of workout - workout.next(); - break; - default: - throw "Exercise: Attempting to move to an unknown state"; - } - - workout.emit("redraw"); - } -} \ No newline at end of file +exports = class Exercise { + constructor(params) { + this.completed = false; + this.sets = []; + this.title = params.title; + this.weight = params.weight; + this.weightIncrement = params.weightIncrement; + this.unit = params.unit; + this.restPeriod = params.restPeriod; + this._originalRestPeriod = params.restPeriod; + this._restTimeout = null; + this._restInterval = null; + this._state = null; + } + + get humanTitle() { + return `${this.title} ${this.weight}${this.unit}`; + } + + get subTitle() { + const totalSets = this.sets.length; + const uncompletedSets = this.sets.filter((set) => !set.isCompleted()).length; + const currentSet = (totalSets - uncompletedSets) + 1; + return `Set ${currentSet} of ${totalSets}`; + } + + decRestPeriod() { + this.restPeriod--; + } + + addSet(set) { + this.sets.push(set); + } + + currentSet() { + return this.sets.filter(set => !set.isCompleted())[0]; + } + + isLastSet() { + return this.sets.filter(set => !set.isCompleted()).length === 1; + } + + isCompleted() { + return !!this.completed; + } + + canSetCompleted() { + return this.sets.filter(set => set.isCompleted()).length === this.sets.length; + } + + setCompleted() { + if (!this.canSetCompleted()) throw "All sets must be completed"; + if (this.canProgress()) this.weight += this.weightIncrement; + this.completed = true; + } + + canProgress() { + let completedRepsTotalSum = 0; + let targetRepsTotalSum = 0; + this.sets.forEach(set => completedRepsTotalSum += set.reps); + this.sets.forEach(set => targetRepsTotalSum += set.maxReps); + + return (targetRepsTotalSum - completedRepsTotalSum) === 0; + } + + startRestTimer(workout) { + this._restTimeout = setTimeout(() => { + this.next(workout); + }, 1000 * this.restPeriod); + + this._restInterval = setInterval(() => { + this.decRestPeriod(); + + if (this.restPeriod < 0) { + this.resetRestTimer(); + this.next(); + + return; + } + + workout.emit("redraw"); + }, 1000 ); + } + + resetRestTimer() { + clearTimeout(this._restTimeout); + clearInterval(this._restInterval); + this._restTimeout = null; + this._restInterval = null; + this.restPeriod = this._originalRestPeriod; + } + + isRestTimerRunning() { + return this._restTimeout != null; + } + + setupStartedButtons(workout) { + clearWatch(); + + setWatch(() => { + this.currentSet().incReps(); + workout.emit("redraw"); + }, BTN1, {repeat: true}); + + setWatch(workout.next.bind(workout), BTN2, {repeat: false}); + + setWatch(() => { + this.currentSet().decReps(); + workout.emit("redraw"); + }, BTN3, {repeat: true}); + } + + setupRestingButtons(workout) { + clearWatch(); + setWatch(workout.next.bind(workout), BTN2, {repeat: false}); + } + + next(workout) { + const STARTED = 1; + const RESTING = 2; + const COMPLETED = 3; + + switch(this._state) { + case null: + this._state = STARTED; + this.setupStartedButtons(workout); + break; + case STARTED: + this._state = RESTING; + this.startRestTimer(workout); + this.setupRestingButtons(workout); + break; + case RESTING: + this.resetRestTimer(); + this.currentSet().setCompleted(); + + if (this.canSetCompleted()) { + this._state = COMPLETED; + this.setCompleted(); + } else { + this._state = null; + } + // As we are changing state and require it to be reprocessed + // invoke the next step of workout + workout.next(); + break; + default: + throw "Exercise: Attempting to move to an unknown state"; + } + + workout.emit("redraw"); + } +}; \ No newline at end of file diff --git a/apps/buffgym/buffgym-icon.js b/apps/buffgym/buffgym-icon.js index 523ed35b6..c41e9cd85 100644 --- a/apps/buffgym/buffgym-icon.js +++ b/apps/buffgym/buffgym-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("mEwxH+ACPI5AUSADAtB5vNGFQtBAIfNF95hoF4wwoF5AwmF5BhmXYbAEF/6QbF1QwIF04qB54ADAwIwoF4oRKBoIvsB4gvZ58kkgCDFxoxaF5wuHGDQcMF5IwXDZwLDGDmlDIWlkgJDSwIABCRAwPDQohCFgIABDQIOCFwYABr4RCCQIvQDYguEAAwtFF5owJDZAvHFw4vFOYQvKFAowMBxIvFMQwvPAB4wFUQ4vJGDYvUGC4vNdgyuEGDIsNFwYwGNAgAPExAvMGIdfTIovfTpYvrfRCOkZ44ugF44NGF05gUFyQvKGIoueGKIufGJ4uhG5oupGItfr4vvAAgvlGAQvt/wrEF9oEGF841IF9QGHX0oGIAD8kAAYJOFzwEBBQoMFACA=")) +require("heatshrink").decompress(atob("mEwxH+ACPI5AUSADAtB5vNGFQtBAIfNF95hoF4wwoF5AwmF5BhmXYbAEF/6QbF1QwIF04qB54ADAwIwoF4oRKBoIvsB4gvZ58kkgCDFxoxaF5wuHGDQcMF5IwXDZwLDGDmlDIWlkgJDSwIABCRAwPDQohCFgIABDQIOCFwYABr4RCCQIvQDYguEAAwtFF5owJDZAvHFw4vFOYQvKFAowMBxIvFMQwvPAB4wFUQ4vJGDYvUGC4vNdgyuEGDIsNFwYwGNAgAPExAvMGIdfTIovfTpYvrfRCOkZ44ugF44NGF05gUFyQvKGIoueGKIufGJ4uhG5oupGItfr4vvAAgvlGAQvt/wrEF9oEGF841IF9QGHX0oGIAD8kAAYJOFzwEBBQoMFACA=")); diff --git a/apps/buffgym/buffgym-set.js b/apps/buffgym/buffgym-set.js index dc0c05671..efb3c2582 100644 --- a/apps/buffgym/buffgym-set.js +++ b/apps/buffgym/buffgym-set.js @@ -1,28 +1,28 @@ -exports = class Set { - constructor(maxReps) { - this.completed = false; - this.minReps = 0; - this.reps = 0; - this.maxReps = maxReps; - } - - isCompleted() { - return !!this.completed; - } - - setCompleted() { - this.completed = true; - } - - incReps() { - if (this.completed) return; - if (this.reps >= this.maxReps) return; - this.reps++; - } - - decReps() { - if (this.completed) return; - if (this.reps <= this.minReps) return; - this.reps--; - } -} \ No newline at end of file +exports = class Set { + constructor(maxReps) { + this.completed = false; + this.minReps = 0; + this.reps = 0; + this.maxReps = maxReps; + } + + isCompleted() { + return !!this.completed; + } + + setCompleted() { + this.completed = true; + } + + incReps() { + if (this.completed) return; + if (this.reps >= this.maxReps) return; + this.reps++; + } + + decReps() { + if (this.completed) return; + if (this.reps <= this.minReps) return; + this.reps--; + } +}; \ No newline at end of file diff --git a/apps/buffgym/buffgym-workout.js b/apps/buffgym/buffgym-workout.js index 124c27f4b..770ed5ffa 100644 --- a/apps/buffgym/buffgym-workout.js +++ b/apps/buffgym/buffgym-workout.js @@ -1,83 +1,84 @@ -exports = class Workout { - constructor(params) { - this.title = params.title; - this.exercises = []; - this.completed = false; - this.on("redraw", redraw.bind(null, this)); - } - - addExercises(exercises) { - exercises.forEach(exercise => this.exercises.push(exercise)); - } - - currentExercise() { - return this.exercises.filter(exercise => !exercise.isCompleted())[0]; - } - - canComplete() { - return this.exercises.filter(exercise => exercise.isCompleted()).length === this.exercises.length; - } - - setCompleted() { - if (!this.canComplete()) throw "All exercises must be completed"; - this.completed = true; - } - - isCompleted() { - return !!this.completed; - } - - static fromJSON(workoutJSON) { - const Set = require("buffgym-set.js"); - const Exercise = require("buffgym-exercise.js"); - const workout = new this({ - title: workoutJSON.title, - }); - const exercises = workoutJSON.exercises.map(exerciseJSON => { - const exercise = new Exercise({ - title: exerciseJSON.title, - weight: exerciseJSON.weight, - weightIncrement: exerciseJSON.weightIncrement, - unit: exerciseJSON.unit, - restPeriod: exerciseJSON.restPeriod, - }); - exerciseJSON.sets.forEach(setJSON => { - exercise.addSet(new Set(setJSON)); - }); - - return exercise; - }); - - workout.addExercises(exercises); - - return workout; - } - - toJSON() { - return { - title: this.title, - exercises: this.exercises.map(exercise => { - return { - title: exercise.title, - weight: exercise.weight, - weightIncrement: exercise.weightIncrement, - unit: exercise.unit, - sets: exercise.sets.map(set => set.maxReps), - restPeriod: exercise.restPeriod, - }; - }), - }; - } - - // State machine - next() { - if (this.canComplete()) { - this.setCompleted(); - this.emit("redraw"); - return; - } - - // Call current exercise state machine - this.currentExercise().next(this); - } -} \ No newline at end of file +exports = class Workout { + constructor(params) { + this.title = params.title; + this.exercises = []; + this.completed = false; + this.on("redraw", params.redraw.bind(null, this)); + } + + addExercises(exercises) { + exercises.forEach(exercise => this.exercises.push(exercise)); + } + + currentExercise() { + return this.exercises.filter(exercise => !exercise.isCompleted())[0]; + } + + canComplete() { + return this.exercises.filter(exercise => exercise.isCompleted()).length === this.exercises.length; + } + + setCompleted() { + if (!this.canComplete()) throw "All exercises must be completed"; + this.completed = true; + } + + isCompleted() { + return !!this.completed; + } + + static fromJSON(workoutJSON, redraw) { + const Set = require("buffgym-set.js"); + const Exercise = require("buffgym-exercise.js"); + const workout = new this({ + title: workoutJSON.title, + redraw: redraw, + }); + const exercises = workoutJSON.exercises.map(exerciseJSON => { + const exercise = new Exercise({ + title: exerciseJSON.title, + weight: exerciseJSON.weight, + weightIncrement: exerciseJSON.weightIncrement, + unit: exerciseJSON.unit, + restPeriod: exerciseJSON.restPeriod, + }); + exerciseJSON.sets.forEach(setJSON => { + exercise.addSet(new Set(setJSON)); + }); + + return exercise; + }); + + workout.addExercises(exercises); + + return workout; + } + + toJSON() { + return { + title: this.title, + exercises: this.exercises.map(exercise => { + return { + title: exercise.title, + weight: exercise.weight, + weightIncrement: exercise.weightIncrement, + unit: exercise.unit, + sets: exercise.sets.map(set => set.maxReps), + restPeriod: exercise.restPeriod, + }; + }), + }; + } + + // State machine + next() { + if (this.canComplete()) { + this.setCompleted(); + this.emit("redraw"); + return; + } + + // Call current exercise state machine + this.currentExercise().next(this); + } +}; \ No newline at end of file diff --git a/apps/buffgym/buffgym.app.js b/apps/buffgym/buffgym.app.js index fc2be83f9..7ed7db1bd 100755 --- a/apps/buffgym/buffgym.app.js +++ b/apps/buffgym/buffgym.app.js @@ -248,7 +248,7 @@ function getWorkoutIndex() { function buildWorkout(fName) { const Workout = require("buffgym-workout.js"); const workoutJSON = require("Storage").readJSON(fName); - const workout = Workout.fromJSON(workoutJSON); + const workout = Workout.fromJSON(workoutJSON, redraw); return workout; } From 3eb150792c1f468abe6d791e0a4718248f1b68b5 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sat, 23 May 2020 23:29:42 +0300 Subject: [PATCH 2/9] Revert back buffgym-icon.js semicolon addition Files to be evaluated must be expressions. Loosen buffgym eslintrc to allow missing semicolons. --- apps/buffgym/.eslintrc.json | 5 +++-- apps/buffgym/buffgym-icon.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/buffgym/.eslintrc.json b/apps/buffgym/.eslintrc.json index 087c94da6..aaae0a0cb 100644 --- a/apps/buffgym/.eslintrc.json +++ b/apps/buffgym/.eslintrc.json @@ -25,10 +25,11 @@ "quotes": [ "error", "double" - ], + ] + /*, "semi": [ "error", "always" - ] + ]*/ } } \ No newline at end of file diff --git a/apps/buffgym/buffgym-icon.js b/apps/buffgym/buffgym-icon.js index c41e9cd85..9938c9030 100644 --- a/apps/buffgym/buffgym-icon.js +++ b/apps/buffgym/buffgym-icon.js @@ -1 +1 @@ -require("heatshrink").decompress(atob("mEwxH+ACPI5AUSADAtB5vNGFQtBAIfNF95hoF4wwoF5AwmF5BhmXYbAEF/6QbF1QwIF04qB54ADAwIwoF4oRKBoIvsB4gvZ58kkgCDFxoxaF5wuHGDQcMF5IwXDZwLDGDmlDIWlkgJDSwIABCRAwPDQohCFgIABDQIOCFwYABr4RCCQIvQDYguEAAwtFF5owJDZAvHFw4vFOYQvKFAowMBxIvFMQwvPAB4wFUQ4vJGDYvUGC4vNdgyuEGDIsNFwYwGNAgAPExAvMGIdfTIovfTpYvrfRCOkZ44ugF44NGF05gUFyQvKGIoueGKIufGJ4uhG5oupGItfr4vvAAgvlGAQvt/wrEF9oEGF841IF9QGHX0oGIAD8kAAYJOFzwEBBQoMFACA=")); +require("heatshrink").decompress(atob("mEwxH+ACPI5AUSADAtB5vNGFQtBAIfNF95hoF4wwoF5AwmF5BhmXYbAEF/6QbF1QwIF04qB54ADAwIwoF4oRKBoIvsB4gvZ58kkgCDFxoxaF5wuHGDQcMF5IwXDZwLDGDmlDIWlkgJDSwIABCRAwPDQohCFgIABDQIOCFwYABr4RCCQIvQDYguEAAwtFF5owJDZAvHFw4vFOYQvKFAowMBxIvFMQwvPAB4wFUQ4vJGDYvUGC4vNdgyuEGDIsNFwYwGNAgAPExAvMGIdfTIovfTpYvrfRCOkZ44ugF44NGF05gUFyQvKGIoueGKIufGJ4uhG5oupGItfr4vvAAgvlGAQvt/wrEF9oEGF841IF9QGHX0oGIAD8kAAYJOFzwEBBQoMFACA=")) From cb90425fdfe6f6f24d938d40e081f554e3ca74e3 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sat, 23 May 2020 23:34:16 +0300 Subject: [PATCH 3/9] For apps, add eslint with baseline .eslintrc.json Add also npm run target "lint-apps". --- apps/.eslintrc.json | 47 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +++- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 apps/.eslintrc.json diff --git a/apps/.eslintrc.json b/apps/.eslintrc.json new file mode 100644 index 000000000..4b23abc34 --- /dev/null +++ b/apps/.eslintrc.json @@ -0,0 +1,47 @@ +{ + "env": { + "shared-node-browser": true + }, + "extends": "eslint:recommended", + "globals": { + "require": "readonly", + "process": "readonly", + "g": "writable", + "E": "readonly", + "Bangle": "readonly", + "Modules": "readonly", + "clearWatch": "readonly", + "setWatch": "readonly", + "getTime": "readonly", + "setTime": "readonly", + "atob": "readonly", + "load": "readonly", + "save": "readonly", + "BTN1": "readonly", + "BTN2": "readonly", + "BTN3": "readonly", + "BTN4": "readonly", + "BTN5": "readonly", + "NRF": "readonly", + "WIDGETS": "readonly" + }, + "parserOptions": { + "ecmaVersion": 11 + }, + "rules": { + "linebreak-style": "off", + "no-case-declarations": "off", + "no-constant-condition": "off", + "no-delete-var": "off", + "no-empty": "off", + "no-extra-semi": "off", + "no-inner-declarations": "off", + "no-mixed-spaces-and-tabs": "off", + "no-octal": "off", + "no-prototype-builtins": "off", + "no-redeclare": "off", + "no-undef": "off", + "no-unused-vars": "off", + "no-useless-escape": "off" + } +} diff --git a/package.json b/package.json index 34ee837d8..c42a937b4 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,11 @@ "author": "Gordon Williams (http://espruino.com)", "version": "0.0.1", "devDependencies": { - "acorn": "" + "acorn": "", + "eslint": "7.1.0" }, "scripts": { + "lint-apps": "eslint ./apps --ext .js", "test": "node bin/sanitycheck.js", "start": "npx http-server" }, From ff18d5c2011c3bfb04bf380db6faf2a157efac33 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sat, 23 May 2020 23:45:56 +0300 Subject: [PATCH 4/9] Remove "no-extra-semi": "off" and make linter happy --- apps/.eslintrc.json | 1 - apps/gpsnav/app.js | 2 +- apps/hidbkbd/hid-binary-keyboard.js | 2 +- apps/numerals/numerals.settings.js | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/apps/.eslintrc.json b/apps/.eslintrc.json index 4b23abc34..98c594dc1 100644 --- a/apps/.eslintrc.json +++ b/apps/.eslintrc.json @@ -34,7 +34,6 @@ "no-constant-condition": "off", "no-delete-var": "off", "no-empty": "off", - "no-extra-semi": "off", "no-inner-declarations": "off", "no-mixed-spaces-and-tabs": "off", "no-octal": "off", diff --git a/apps/gpsnav/app.js b/apps/gpsnav/app.js index 5a6319385..960ad7e4d 100644 --- a/apps/gpsnav/app.js +++ b/apps/gpsnav/app.js @@ -190,7 +190,7 @@ function setButtons(){ setWatch(nextwp.bind(null,-1), BTN1, {repeat:true,edge:"falling"}); setWatch(doselect, BTN2, {repeat:true,edge:"falling"}); setWatch(nextwp.bind(null,1), BTN3, {repeat:true,edge:"falling"}); -}; +} var SCREENACCESS = { withApp:true, diff --git a/apps/hidbkbd/hid-binary-keyboard.js b/apps/hidbkbd/hid-binary-keyboard.js index 81838b42d..4b0401699 100644 --- a/apps/hidbkbd/hid-binary-keyboard.js +++ b/apps/hidbkbd/hid-binary-keyboard.js @@ -95,7 +95,7 @@ function startKeyboardHID() { getCharacter().then(ch => { return sendHID(KEY[ch]); }).then(startKeyboardHID); -}; +} if (settings.HID=="kb" || settings.HID=="kbmedia") { if (settings.HID=="kbmedia") { diff --git a/apps/numerals/numerals.settings.js b/apps/numerals/numerals.settings.js index 1e97271b6..37af6b6f2 100644 --- a/apps/numerals/numerals.settings.js +++ b/apps/numerals/numerals.settings.js @@ -1,7 +1,7 @@ (function(back) { function updateSettings() { storage.write('numerals.json', numeralsSettings); - }; + } function resetSettings() { numeralsSettings = { color:0, From 894e13bd112064bfb692f7848a7317157fb7cf94 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sat, 23 May 2020 23:46:14 +0300 Subject: [PATCH 5/9] Remove unused "linebreak-style": "off" --- apps/.eslintrc.json | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/.eslintrc.json b/apps/.eslintrc.json index 98c594dc1..ff0cc46fe 100644 --- a/apps/.eslintrc.json +++ b/apps/.eslintrc.json @@ -29,7 +29,6 @@ "ecmaVersion": 11 }, "rules": { - "linebreak-style": "off", "no-case-declarations": "off", "no-constant-condition": "off", "no-delete-var": "off", From 0a32e40b1abdf221b79228a8fb36659c18fa0a00 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Sat, 23 May 2020 23:51:24 +0300 Subject: [PATCH 6/9] Remove "no-mixed-spaces-and-tabs": "off" and make linter happy --- apps/.eslintrc.json | 1 - apps/_example_widget/widget.js | 2 +- apps/berlinc/berlin-clock.js | 2 +- apps/metronome/metronome.js | 2 +- apps/numerals/numerals.app.js | 4 ++-- apps/widhrm/widget.js | 2 +- apps/widram/widget.js | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/.eslintrc.json b/apps/.eslintrc.json index ff0cc46fe..4ed76396a 100644 --- a/apps/.eslintrc.json +++ b/apps/.eslintrc.json @@ -34,7 +34,6 @@ "no-delete-var": "off", "no-empty": "off", "no-inner-declarations": "off", - "no-mixed-spaces-and-tabs": "off", "no-octal": "off", "no-prototype-builtins": "off", "no-redeclare": "off", diff --git a/apps/_example_widget/widget.js b/apps/_example_widget/widget.js index 3893e3096..f7aed6991 100644 --- a/apps/_example_widget/widget.js +++ b/apps/_example_widget/widget.js @@ -3,7 +3,7 @@ currently-running apps */ (() => { function draw() { g.reset(); // reset the graphics context to defaults (color/font/etc) - // add your code + // add your code g.drawString("X", this.x, this.y); } diff --git a/apps/berlinc/berlin-clock.js b/apps/berlinc/berlin-clock.js index 93b584f66..0c8e2d076 100644 --- a/apps/berlinc/berlin-clock.js +++ b/apps/berlinc/berlin-clock.js @@ -49,7 +49,7 @@ function drawBerlinClock() { Bangle.on('lcdPower', (on) => { g.clear(); if (on) { - Bangle.drawWidgets(); + Bangle.drawWidgets(); // call your app function here drawBerlinClock(); }}); diff --git a/apps/metronome/metronome.js b/apps/metronome/metronome.js index add6fee16..6e0827c19 100644 --- a/apps/metronome/metronome.js +++ b/apps/metronome/metronome.js @@ -65,7 +65,7 @@ Bangle.on('touch', function(button) { // setting bpm by tapping the screen. Uses the mean time difference between several tappings. if (tindex < time_diffs.length) { if (Date.now()-tStart < 5000) { - time_diffs[tindex] = Date.now()-tStart; + time_diffs[tindex] = Date.now()-tStart; } } else { tindex=0; diff --git a/apps/numerals/numerals.app.js b/apps/numerals/numerals.app.js index b24e8bc5e..f95c7d379 100644 --- a/apps/numerals/numerals.app.js +++ b/apps/numerals/numerals.app.js @@ -51,8 +51,8 @@ function drawNum(num,col,x,y,func){ let tx = x*100+25; let ty = y*104+32; for (let i=0;i0) g.setColor((func==fill)?"#000000":col); - func(translate(tx,ty,numerals[num][i])); + if (i>0) g.setColor((func==fill)?"#000000":col); + func(translate(tx,ty,numerals[num][i])); } } diff --git a/apps/widhrm/widget.js b/apps/widhrm/widget.js index ca66f8b44..a591fa0df 100644 --- a/apps/widhrm/widget.js +++ b/apps/widhrm/widget.js @@ -5,7 +5,7 @@ function draw() { var width = 24; - g.reset(); + g.reset(); g.setFont("6x8", 1); g.setFontAlign(0, 0); g.clearRect(this.x,this.y+15,this.x+width,this.y+23); // erase background diff --git a/apps/widram/widget.js b/apps/widram/widget.js index 08710b726..bd44b98a4 100644 --- a/apps/widram/widget.js +++ b/apps/widram/widget.js @@ -1,7 +1,7 @@ (() => { function draw() { g.reset(); - var m = process.memory(); + var m = process.memory(); var pc = Math.round(m.usage*100/m.total); g.drawImage(atob("BwgBqgP////AVQ=="), this.x+(24-7)/2, this.y+4); g.setColor(pc>70 ? "#ff0000" : (pc>50 ? "#ffff00" : "#ffffff")); From 593a9240d799788248e9fd4ac5893531be2ec0a1 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Tue, 26 May 2020 15:10:34 +0300 Subject: [PATCH 7/9] eslint: Updated globals based on https://banglejs.com/reference --- apps/.eslintrc.json | 132 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 120 insertions(+), 12 deletions(-) diff --git a/apps/.eslintrc.json b/apps/.eslintrc.json index 4ed76396a..b92b5780d 100644 --- a/apps/.eslintrc.json +++ b/apps/.eslintrc.json @@ -1,28 +1,134 @@ { "env": { - "shared-node-browser": true + // TODO: "espruino": false + // TODO: "banglejs": false }, "extends": "eslint:recommended", "globals": { - "require": "readonly", - "process": "readonly", - "g": "writable", - "E": "readonly", + // Methods and Fields at https://banglejs.com/reference + "Array": "readonly", + "ArrayBuffer": "readonly", + "ArrayBufferView": "readonly", "Bangle": "readonly", + "BluetoothDevice": "readonly", + "BluetoothRemoteGATTCharacteristic": "readonly", + "BluetoothRemoteGATTServer": "readonly", + "BluetoothRemoteGATTService": "readonly", + "Boolean": "readonly", + "console": "readonly", + "DataView": "readonly", + "Date": "readonly", + "E": "readonly", + "Error": "readonly", + "Flash": "readonly", + "Float32Array": "readonly", + "Float64Array": "readonly", + "fs": "readonly", + "Function": "readonly", + "Graphics": "readonly", + "heatshrink": "readonly", + "I2C": "readonly", + "Int16Array": "readonly", + "Int32Array": "readonly", + "Int8Array": "readonly", + "InternalError": "readonly", + "JSON": "readonly", + "Math": "readonly", "Modules": "readonly", - "clearWatch": "readonly", - "setWatch": "readonly", - "getTime": "readonly", - "setTime": "readonly", + "NRF": "readonly", + "Number": "readonly", + "Object": "readonly", + "OneWire": "readonly", + "Pin": "readonly", + "process": "readonly", + "Promise": "readonly", + "ReferenceError": "readonly", + "RegExp": "readonly", + "Serial": "readonly", + "SPI": "readonly", + "Storage": "readonly", + "StorageFile": "readonly", + "String": "readonly", + "SyntaxError": "readonly", + "tensorflow": "readonly", + "TFMicroInterpreter": "readonly", + "TypeError": "readonly", + "Uint16Array": "readonly", + "Uint24Array": "readonly", + "Uint32Array": "readonly", + "Uint8Array": "readonly", + "Uint8ClampedArray": "readonly", + "Waveform": "readonly", + // Methods and Fields at https://banglejs.com/reference + "analogRead": "readonly", + "analogWrite": "readonly", + "arguments": "readonly", "atob": "readonly", - "load": "readonly", - "save": "readonly", + "Bluetooth": "readonly", + "BTN": "readonly", "BTN1": "readonly", "BTN2": "readonly", "BTN3": "readonly", "BTN4": "readonly", "BTN5": "readonly", - "NRF": "readonly", + "btoa": "readonly", + "changeInterval": "readonly", + "clearInterval": "readonly", + "clearTimeout": "readonly", + "clearWatch": "readonly", + "decodeURIComponent": "readonly", + "digitalPulse": "readonly", + "digitalRead": "readonly", + "digitalWrite": "readonly", + "dump": "readonly", + "echo": "readonly", + "edit": "readonly", + "encodeURIComponent": "readonly", + "eval": "readonly", + "getPinMode": "readonly", + "getSerial": "readonly", + "getTime": "readonly", + "global": "readonly", + "HIGH": "readonly", + "I2C1": "readonly", + "Infinity": "readonly", + "isFinite": "readonly", + "isNaN": "readonly", + "LED": "readonly", + "LED1": "readonly", + "LED2": "readonly", + "load": "readonly", + "LoopbackA": "readonly", + "LoopbackB": "readonly", + "LOW": "readonly", + "NaN": "readonly", + "parseFloat": "readonly", + "parseInt": "readonly", + "peek16": "readonly", + "peek32": "readonly", + "peek8": "readonly", + "pinMode": "readonly", + "poke16": "readonly", + "poke32": "readonly", + "poke8": "readonly", + "print": "readonly", + "require": "readonly", + "reset": "readonly", + "save": "readonly", + "Serial1": "readonly", + "setBusyIndicator": "readonly", + "setInterval": "readonly", + "setSleepIndicator": "readonly", + "setTime": "readonly", + "setTimeout": "readonly", + "setWatch": "readonly", + "shiftOut": "readonly", + "SPI1": "readonly", + "Terminal": "readonly", + "trace": "readonly", + "VIBRATE": "readonly", + // Aliases and not defined at https://banglejs.com/reference + "g": "readonly", "WIDGETS": "readonly" }, "parserOptions": { @@ -33,10 +139,12 @@ "no-constant-condition": "off", "no-delete-var": "off", "no-empty": "off", + "no-global-assign": "off", "no-inner-declarations": "off", "no-octal": "off", "no-prototype-builtins": "off", "no-redeclare": "off", + // TODO: "no-undef": "warn", "no-undef": "off", "no-unused-vars": "off", "no-useless-escape": "off" From d1b890c49a7d7282d8aaff7795e18b2ac6e8107e Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Tue, 26 May 2020 15:21:43 +0300 Subject: [PATCH 8/9] npm test: Run eslint after sanitycheck.js --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c42a937b4..4b1a42c05 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ }, "scripts": { "lint-apps": "eslint ./apps --ext .js", - "test": "node bin/sanitycheck.js", + "test": "node bin/sanitycheck.js && eslint ./apps --ext .js", "start": "npx http-server" }, "dependencies": { From 2a81ad52f9881d1e5e39083ab7e8046e18a892c2 Mon Sep 17 00:00:00 2001 From: Tuukka Ikkala Date: Tue, 26 May 2020 18:16:29 +0300 Subject: [PATCH 9/9] Revert back the latest formatting of berlin-clock author. --- apps/berlinc/berlin-clock.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/berlinc/berlin-clock.js b/apps/berlinc/berlin-clock.js index 0398ffd2f..3950147b8 100644 --- a/apps/berlinc/berlin-clock.js +++ b/apps/berlinc/berlin-clock.js @@ -88,9 +88,10 @@ Bangle.on('lcdPower', (on) => { g.clear(); if (on) { Bangle.drawWidgets(); - // call your app function here - drawBerlinClock(); -}}); + // call your app function here + drawBerlinClock(); + } +}); // refesh every 15 sec setInterval(drawBerlinClock, 15E3);