Skip to content

Commit

Permalink
Lint fixes
Browse files Browse the repository at this point in the history
Update a few things, add lint rules and fix those too.
  • Loading branch information
mattgodbolt authored Nov 3, 2024
1 parent 1f123d5 commit 3349deb
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 55 deletions.
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 8 additions & 14 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
import globals from "globals";
import path from "node:path";
import {fileURLToPath} from "node:url";
import prettier from "eslint-plugin-prettier";
import eslintConfigPrettier from "eslint-config-prettier";
import js from "@eslint/js";
import {FlatCompat} from "@eslint/eslintrc";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});
import globals from "globals";

export default [
{
ignores: ["**/dist", "test/_polyfills.js"],
},
...compat.extends("eslint:recommended"),
js.configs.recommended,
eslintConfigPrettier,
{
plugins: {prettier},
languageOptions: {
globals: {
...globals.browser,
Expand All @@ -29,9 +22,10 @@ export default [
},

rules: {
eqeqeq: "error",
"no-var": "error",
semi: "error",
"no-control-regex": "off",
camelcase: "error",
"no-unused-vars": [
"error",
{
Expand Down
90 changes: 90 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"css-loader": "^7.1.2",
"css-minimizer-webpack-plugin": "^7.0.0",
"eslint": "^9.14.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"esm": "^3.2.25",
"favicons": "^7.2.0",
"favicons-webpack-plugin": "^6.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/DFS.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export class AcornDFSdisc {

console.log(`execAdd=`);
let extra = 0;
extra |= ((execAdd & 0xffff0000) == (0xffff0000 | 0) ? 3 : 0) << 6;
extra |= ((execAdd & 0xffff0000) === (0xffff0000 | 0) ? 3 : 0) << 6;
extra |= ((fileData.length >> 16) & 3) << 4;
extra |= ((loadAdd & 0xffff0000) == (0xffff0000 | 0) ? 3 : 0) << 2;
extra |= ((loadAdd & 0xffff0000) === (0xffff0000 | 0) ? 3 : 0) << 2;
extra |= ((this.nextSector >> 8) & 3) << 0;
this.image.write(0x010e, extra, 1);

Expand Down
20 changes: 7 additions & 13 deletions src/emulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const MaxCyclesPerFrame = ClocksPerSecond / 10;
const urlParams = new URLSearchParams(window.location.search);

let modelName = "BBC Micro Model B";
let beebjit_incoming = false;
let beebjitIncoming = false;
const Model = models.findModel("B");

class ScreenResizer {
Expand Down Expand Up @@ -91,7 +91,7 @@ export class Emulator {
this.loopLength = 6000000 + 320000;
this.state = null;
this.snapshot = new Snapshot();
this.loop = urlParams.get("loop") ? true : false;
this.loop = !!urlParams.get("loop");
this.showCoords = false; // coordinate display mode

window.theEmulator = this;
Expand Down Expand Up @@ -148,7 +148,7 @@ export class Emulator {
}

timer() {
if (!beebjit_incoming && !this.showCoords) {
if (!beebjitIncoming && !this.showCoords) {
this.emuStatus.innerHTML = `${modelName} | ${Math.floor(
this.cpu.currentCycles / 2000000,
)} s`;
Expand All @@ -168,7 +168,7 @@ export class Emulator {
async beebjit(tokenised) {
this.pause();

beebjit_incoming = true;
beebjitIncoming = true;

function myCounter() {
this.emuStatus.innerHTML += ".";
Expand All @@ -187,7 +187,7 @@ export class Emulator {
},
},
);
beebjit_incoming = false;
beebjitIncoming = false;
this.state = await response.json();
const t0 = performance.now();
this.snapshot.load(this.state, this.cpu);
Expand Down Expand Up @@ -245,21 +245,15 @@ export class Emulator {
frameFunc(now) {
requestAnimationFrame(this.onAnimFrame);
// Take snapshot
if (
this.loop == true &&
(this.state == null) & (this.cpu.currentCycles >= this.loopStart)
) {
if (this.loop && !this.state && this.cpu.currentCycles >= this.loopStart) {
this.pause();
this.state = this.snapshot.save(this.cpu).state;
this.start();
console.log("snapshot taken at " + this.cpu.currentCycles + " cycles");
}

// Loop back
if (
this.loop == true &&
(this.state !== null) & (this.cpu.currentCycles >= this.loopStart + this.loopLength)
) {
if (this.loop && this.state && this.cpu.currentCycles >= this.loopStart + this.loopLength) {
this.pause();
this.snapshot.load(this.state, this.cpu);
this.cpu.currentCycles = this.loopStart;
Expand Down
19 changes: 10 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ function programUrl(id) {

function updateUiForProgram(id, json, v) {
// Twitter
if (v == 1) {
if (v === 1) {
$("#like").html(
`<span class="heart">♥</span>code originally posted by ${json.author} on Twitter`,
);
}

// Mastodon
if (v == 3) {
if (v === 3) {
let author = /@\w+/g.exec(json.src);
$("#like").html(
`<a href='${json.src}'><span class="heart">♥</span> code posted by ${author} on Mastodon<a>`,
Expand Down Expand Up @@ -66,10 +66,10 @@ async function getInitialState(id) {
}

// Try decoding state from the location hash.
let maybeState = OwletEditor.decodeStateString(window.location.hash.substr(1));
let maybeState = OwletEditor.decodeStateString(window.location.hash.substring(1));

if (maybeState !== null) {
if (maybeState.v == 1) {
if (maybeState.v === 1) {
consumeHash();
if (maybeState.date < 1590994800) {
maybeState.program = backwardCompat(maybeState.program);
Expand All @@ -78,7 +78,7 @@ async function getInitialState(id) {
return maybeState;
}

if (maybeState.v == 3) {
if (maybeState.v === 3) {
consumeHash();
if (maybeState.src) updateUiForProgram(maybeState.src, maybeState, 3);

Expand Down Expand Up @@ -122,15 +122,16 @@ async function initialise() {
const urlParams = new URLSearchParams(queryString);
const t = urlParams.get("t");
if (t) {
$("#logo").attr("src", logo);
$("#logo").attr("height", "48px");
$("#logo").attr("alt", "BBC Microbot gallery");
const $logo = $("#logo");
$logo.attr("src", logo);
$logo.attr("height", "48px");
$logo.attr("alt", "BBC Microbot gallery");
const link = document.querySelector("link[rel*='icon']") || document.createElement("link");
link.type = "image/x-icon";
link.rel = "shortcut icon";
link.href = logo;
document.title = "BBC Microbot - Owlet Editor";
$("#logo").click(() => {
$logo.click(() => {
window.location.href = "https://www.bbcmicrobot.com";
});
}
Expand Down
9 changes: 5 additions & 4 deletions src/owlet.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class OwletEditor {
}

async setState(state) {
// eslint-disable-next-line no-control-regex
const basic = state.program.replace(/[\x00-\x09\x0b-\x1f\x7f-\u009f]/g, function (c) {
return String.fromCharCode(c.charCodeAt(0) | 0x100);
});
Expand All @@ -198,7 +199,6 @@ export class OwletEditor {
this.emulator.cpu.currentCycles = 2000000 * 60 * 60 * 3;
this.emulator.cpu.targetCycles = 2000000 * 60 * 60 * 3;
this.emulator.start();
return;
} else {
this.emulator.gxr();
await this.emulator.initialise();
Expand Down Expand Up @@ -346,10 +346,11 @@ export class OwletEditor {

async rocket() {
this.updateProgram();
$("#rocket").addClass("backgroundAnimated");
const $rocket = $("#rocket");
$rocket.addClass("backgroundAnimated");
const program = await this.tokeniser.tokenise(this.getBasicText());
await this.emulator.beebjit(program);
$("#rocket").removeClass("backgroundAnimated");
$rocket.removeClass("backgroundAnimated");
}

async downloadDisc() {
Expand Down Expand Up @@ -457,7 +458,7 @@ export class OwletEditor {
while (len--) {
let b = this.emulator.readmem(addr++);
if (b < 32 || (b >= 127 && b < 161)) {
if (b == 10 || b == 13) alert("problematic byte value " + b);
if (b === 10 || b === 13) alert("problematic byte value " + b);
b += 0x100;
}
data += String.fromCodePoint(b);
Expand Down
4 changes: 2 additions & 2 deletions src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ function detokeniseInternal(text, handler) {
if (
identifier === "REM" ||
identifier === "DATA" ||
(ch == "." && "DAT".startsWith(identifier))
(ch === "." && "DAT".startsWith(identifier))
) {
// Untokenised REM or DATA or abbreviated DATA.
leaveRestOfLine = true;
Expand All @@ -342,7 +342,7 @@ function detokeniseInternal(text, handler) {
if (
(ch >= "A" && ch <= "Z") ||
(ch >= "a" && ch <= "z") ||
ch == "_" ||
ch === "_" ||
(identifier !== undefined && ch >= "0" && ch <= "9")
) {
if (identifier === undefined) {
Expand Down
Loading

0 comments on commit 3349deb

Please sign in to comment.