Skip to content

Add type error reporting mode: never #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions src-runtime/createDiv.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,20 @@ function niceDiv(div) {
div.style.borderRadius = "4px";
}
/**
* @todo
* Show number of validations too? Might be too noisy.
* @returns {HTMLDivElement}
* @returns {asserts mode is typeof typecheckOptions.mode} asd
* @param {string} mode - The mode to test.
*/
function assertMode(mode) {
switch (mode) {
case 'spam':
case 'once':
case 'never':
return;
}
throw new TypeError("wrong mode - either spam, once or never.");
}
/**
* @returns {HTMLDivElement} The <div> at bottom/right position.
*/
function createDiv() {
const div = document.createElement("div");
Expand All @@ -26,30 +37,34 @@ function createDiv() {
niceDiv(div);
const spanErrors = document.createElement("span");
const span = document.createElement("span");
span.innerText = " Spam type reports:";
const input = document.createElement("input");
input.type = "checkbox";
span.innerText = " Type report mode:";
const select = document.createElement("select");
const option_spam = document.createElement('option');
option_spam.text = 'spam';
const option_once = document.createElement('option');
option_once.text = 'once';
const option_never = document.createElement('option');
option_never.text = 'never';
select.append(option_spam, option_once, option_never);
const spamTypeReports = localStorage.getItem('rti-spam-type-reports');
input.checked = true;
select.value = typecheckOptions.mode;
if (spamTypeReports !== null) {
input.checked = spamTypeReports === 'spam' ? true : false;
select.value = spamTypeReports;
}
const onchange = () => {
localStorage.setItem('rti-spam-type-reports', input.checked ? 'spam' : 'once');
if (input.checked) {
typecheckOptions.mode = "spam";
} else {
typecheckOptions.mode = "once";
}
const {value} = select;
localStorage.setItem('rti-spam-type-reports', value);
assertMode(value);
typecheckOptions.mode = value;
};
input.onchange = onchange;
onchange(); // update mode from localStorage
select.onchange = onchange;
onchange(); // set mode in typecheckOptions
const buttonHide = document.createElement("button");
buttonHide.textContent = 'Hide';
buttonHide.onclick = () => {
div.style.display = 'none';
};
div.append(spanErrors, span, input, buttonHide, typecheckWarnedTable);
div.append(spanErrors, span, select, buttonHide, typecheckWarnedTable);
div.style.maxHeight = '200px';
div.style.overflow = 'scroll';
const finalFunc = () => document.body.append(div);
Expand Down
2 changes: 1 addition & 1 deletion src-runtime/typecheckOptions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function typecheckReset() {
}
const typecheckOptions = {
/**
* @type {'spam'|'once'} - In spam-mode every message is printed. In once-mode a cache is
* @type {'spam'|'once'|'never'} - In spam-mode every message is printed. In once-mode a cache is
* looked up to check if it was printed already. Spam can be too noisy if there are too
* many type errors, so the best way to keep it quiet is to fix the noisiest type issues first.
* Spam-mode basically retains the order, which mentally helps to figure out the actual issues.
Expand Down
4 changes: 3 additions & 1 deletion src-runtime/typecheckWarn.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {typecheckOptions} from "./typecheckOptions.mjs";
/**
* @param {string} msg - The main message.
* @param {...any} extra - Extra strings or objects etc.
* @param {...any} extra - Extra strings or objects etc.
*/
function typecheckWarn(msg, ...extra) {
const { mode, warned } = typecheckOptions;
Expand All @@ -16,6 +16,8 @@ function typecheckWarn(msg, ...extra) {
console.error(msg, ...extra);
}
break;
case 'never':
break;
default:
console.error("typecheckWarn> unsupported mode:", mode);
}
Expand Down