Skip to content

Commit bfa2446

Browse files
authored
Add type error reporting mode: never (#28)
1 parent 0dee177 commit bfa2446

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

src-runtime/createDiv.mjs

+32-17
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ function niceDiv(div) {
1313
div.style.borderRadius = "4px";
1414
}
1515
/**
16-
* @todo
17-
* Show number of validations too? Might be too noisy.
18-
* @returns {HTMLDivElement}
16+
* @returns {asserts mode is typeof typecheckOptions.mode} asd
17+
* @param {string} mode - The mode to test.
18+
*/
19+
function assertMode(mode) {
20+
switch (mode) {
21+
case 'spam':
22+
case 'once':
23+
case 'never':
24+
return;
25+
}
26+
throw new TypeError("wrong mode - either spam, once or never.");
27+
}
28+
/**
29+
* @returns {HTMLDivElement} The <div> at bottom/right position.
1930
*/
2031
function createDiv() {
2132
const div = document.createElement("div");
@@ -26,30 +37,34 @@ function createDiv() {
2637
niceDiv(div);
2738
const spanErrors = document.createElement("span");
2839
const span = document.createElement("span");
29-
span.innerText = " Spam type reports:";
30-
const input = document.createElement("input");
31-
input.type = "checkbox";
40+
span.innerText = " Type report mode:";
41+
const select = document.createElement("select");
42+
const option_spam = document.createElement('option');
43+
option_spam.text = 'spam';
44+
const option_once = document.createElement('option');
45+
option_once.text = 'once';
46+
const option_never = document.createElement('option');
47+
option_never.text = 'never';
48+
select.append(option_spam, option_once, option_never);
3249
const spamTypeReports = localStorage.getItem('rti-spam-type-reports');
33-
input.checked = true;
50+
select.value = typecheckOptions.mode;
3451
if (spamTypeReports !== null) {
35-
input.checked = spamTypeReports === 'spam' ? true : false;
52+
select.value = spamTypeReports;
3653
}
3754
const onchange = () => {
38-
localStorage.setItem('rti-spam-type-reports', input.checked ? 'spam' : 'once');
39-
if (input.checked) {
40-
typecheckOptions.mode = "spam";
41-
} else {
42-
typecheckOptions.mode = "once";
43-
}
55+
const {value} = select;
56+
localStorage.setItem('rti-spam-type-reports', value);
57+
assertMode(value);
58+
typecheckOptions.mode = value;
4459
};
45-
input.onchange = onchange;
46-
onchange(); // update mode from localStorage
60+
select.onchange = onchange;
61+
onchange(); // set mode in typecheckOptions
4762
const buttonHide = document.createElement("button");
4863
buttonHide.textContent = 'Hide';
4964
buttonHide.onclick = () => {
5065
div.style.display = 'none';
5166
};
52-
div.append(spanErrors, span, input, buttonHide, typecheckWarnedTable);
67+
div.append(spanErrors, span, select, buttonHide, typecheckWarnedTable);
5368
div.style.maxHeight = '200px';
5469
div.style.overflow = 'scroll';
5570
const finalFunc = () => document.body.append(div);

src-runtime/typecheckOptions.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function typecheckReset() {
1212
}
1313
const typecheckOptions = {
1414
/**
15-
* @type {'spam'|'once'} - In spam-mode every message is printed. In once-mode a cache is
15+
* @type {'spam'|'once'|'never'} - In spam-mode every message is printed. In once-mode a cache is
1616
* looked up to check if it was printed already. Spam can be too noisy if there are too
1717
* many type errors, so the best way to keep it quiet is to fix the noisiest type issues first.
1818
* Spam-mode basically retains the order, which mentally helps to figure out the actual issues.

src-runtime/typecheckWarn.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {typecheckOptions} from "./typecheckOptions.mjs";
22
/**
33
* @param {string} msg - The main message.
4-
* @param {...any} extra - Extra strings or objects etc.
4+
* @param {...any} extra - Extra strings or objects etc.
55
*/
66
function typecheckWarn(msg, ...extra) {
77
const { mode, warned } = typecheckOptions;
@@ -16,6 +16,8 @@ function typecheckWarn(msg, ...extra) {
1616
console.error(msg, ...extra);
1717
}
1818
break;
19+
case 'never':
20+
break;
1921
default:
2022
console.error("typecheckWarn> unsupported mode:", mode);
2123
}

0 commit comments

Comments
 (0)