Skip to content

Commit 0d70ed4

Browse files
committed
ESLint: add/fix src/runtime + some other ESLint fixes
1 parent f1172ff commit 0d70ed4

26 files changed

+112
-111
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"build:types": "npm run build:dts && rollup -c --environment target:types",
1212
"test": "npm run test:update && node test.mjs",
1313
"test:update": "node gen_tests.mjs > test/typechecking.json",
14-
"lint": "eslint --ext .js,.mjs,.cjs src-transpiler",
14+
"lint": "eslint --ext .js,.mjs,.cjs src-transpiler src-runtime",
1515
"docs": "echo todo docs using jsdoc"
1616
},
1717
"repository": {

plugin-parcel1/index.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { addTypeChecks } = require('runtime-type-inspector');
1+
const {addTypeChecks} = require('runtime-type-inspector');
22
const JSAsset = require('parcel-bundler/src/assets/JSAsset.js');
33
class JSAssetPlayCanvas extends JSAsset {
44
/**

repl/babel-core.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Instead of loading this as UMD module, we will soon integrate Babel 8, which
22
// finally ships as proper ESM modules. But it requires a bit more work (tm).
33
await import("../unpkg.com_@babel_standalone@7.22.17_babel.js");
4-
const { parseSync } = Babel._babel;
5-
export { parseSync };
4+
const {parseSync} = Babel._babel;
5+
export {parseSync};

repl/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
Right: <input id="right" type="checkbox" checked></input>
2727
<script type="module">
2828
import * as Index from "./index.mjs";
29-
Object.assign(window, { ...Index });
29+
Object.assign(window, {...Index});
3030
</script>
3131
</body>
3232
</html>

repl/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (!(inputRight instanceof HTMLInputElement)) {
3333
throw 'This module requires a <input id="right" ...';
3434
}
3535
inputLeft.onchange = (event) => {
36-
const { checked } = event.target;
36+
const {checked} = event.target;
3737
if (checked) {
3838
// Unhide right editor and resize right one to half size again
3939
aceDivLeft.style.display = "";
@@ -52,7 +52,7 @@ inputLeft.onchange = (event) => {
5252
}
5353
}
5454
inputRight.onchange = (event) => {
55-
const { checked } = event.target;
55+
const {checked} = event.target;
5656
if (checked) {
5757
// Unhide left editor and resize right one to half size again
5858
aceDivRight.style.display = "";

rollup.config.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { execSync } from 'child_process';
1+
import {execSync} from 'child_process';
22
import fs from 'fs';
33
import path from 'path';
44
// 1st party Rollup plugins
5-
import { createFilter } from '@rollup/pluginutils';
6-
import { babel } from '@rollup/plugin-babel';
7-
import { nodeResolve } from '@rollup/plugin-node-resolve';
5+
import {createFilter} from '@rollup/pluginutils';
6+
import {babel } from '@rollup/plugin-babel';
7+
import {nodeResolve } from '@rollup/plugin-node-resolve';
88
import terser from '@rollup/plugin-terser';
99
// 3rd party Rollup plugins
1010
import dts from 'rollup-plugin-dts';
11-
import { visualizer } from 'rollup-plugin-visualizer';
11+
import {visualizer} from 'rollup-plugin-visualizer';
1212
import json from '@rollup/plugin-json';
13-
//import { addTypeChecks } from "./src-transpiler/typeInserter.mjs";
14-
//const { addTypeChecks } = await import("runtime-type-inspector/src-transpiler/typeInserter.mjs");
13+
//import {addTypeChecks} from "./src-transpiler/typeInserter.mjs";
14+
//const {addTypeChecks} = await import("runtime-type-inspector/src-transpiler/typeInserter.mjs");
1515
import commonjs from '@rollup/plugin-commonjs';
16-
//import { runtimeTypeInspector } from './plugin-rollup/index.mjs';
16+
//import {runtimeTypeInspector} from './plugin-rollup/index.mjs';
1717
/** @typedef {import('rollup').RollupOptions} RollupOptions */
1818
/** @typedef {import('rollup').Plugin} Plugin */
1919
/** @typedef {import('rollup').OutputOptions} OutputOptions */
@@ -169,7 +169,7 @@ export default (args) => {
169169
const envTarget = process.env.target ? process.env.target.toLowerCase() : null;
170170
if ((envTarget === null) && fs.existsSync('build')) {
171171
// no targets specified, clean build directory
172-
fs.rmSync('build', { recursive: true });
172+
fs.rmSync('build', {recursive: true});
173173
}
174174
if (envTarget === 'types') {
175175
targets.push(target_types);

src-runtime/assertType.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function assertType(value, expect, loc, name, critical = true) {
2424
}
2525
expectStr = '';
2626
const msg = `${loc}> type of '${name}' is invalid${expectStr}`;
27-
typecheckWarn(msg, { expect, value });
27+
typecheckWarn(msg, {expect, value});
2828
const warnObj = typecheckOptions.warned[msg];
2929
if (!warnObj.tr) {
3030
const tr = document.createElement('tr');
@@ -33,7 +33,7 @@ export function assertType(value, expect, loc, name, critical = true) {
3333
dbgInput.type = "checkbox";
3434
dbgInput.onchange = () => {
3535
warnObj.dbg = dbgInput.checked;
36-
}
36+
};
3737
const count = document.createElement('td');
3838
const desc = document.createElement('td');
3939
desc.innerText = msg;

src-runtime/makeJSDoc.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/**
2-
* @type {Record<string, string>}
3-
*/
1+
/** @type {Record<string, string>} */
42
const jsdocCache = {};
53
/**
64
* @todo
@@ -24,11 +22,11 @@ function makeJSDoc(loc, names, values) {
2422
} else if (value instanceof Object) {
2523
type = value.constructor.name;
2624
}
27-
if (type !== 'string' && pc[type]) {
25+
if (type !== 'string' && window.pc[type]) {
2826
type = 'pc.' + type;
2927
}
3028
//debugger;
31-
jsdoc += ` * @param {${type}} ${name} - todo/jsdoc\n`
29+
jsdoc += ` * @param {${type}} ${name} - todo/jsdoc\n`;
3230
}
3331
jsdoc += ' */';
3432
if (!jsdocCache[loc]) {

src-runtime/typecheckEvery.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* @example
44
* const a = [];
55
* a.length = 10;
6-
* typecheckEvery(a, (e, i) => { console.log(e); return true; }
6+
* typecheckEvery(a, (e, i) => {console.log(e); return true;}
77
* @param {*[]} arr - The array to test.
88
* @param {Function} fn - The callback function to test each element with.
99
* @returns {boolean} True if every callback call is true aswell.

src-runtime/typecheckOptions.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
function typecheckReport() {
2-
console.table(typecheckOptions.warned);
3-
}
4-
/**
5-
* @param {Object<string, any>} obj - The object to clear.
6-
*/
7-
function clearObject(obj) {
8-
Object.keys(obj).forEach(_ => delete obj[_]);
9-
}
10-
function typecheckReset() {
11-
clearObject(typecheckOptions.warned);
12-
}
131
const typecheckOptions = {
142
/**
153
* @type {'spam'|'once'|'never'} - In spam-mode every message is printed. In once-mode a cache is
@@ -57,4 +45,16 @@ const typecheckOptions = {
5745
},
5846
count: 0,
5947
};
48+
function typecheckReport() {
49+
console.table(typecheckOptions.warned);
50+
}
51+
/**
52+
* @param {Object<string, any>} obj - The object to clear.
53+
*/
54+
function clearObject(obj) {
55+
Object.keys(obj).forEach(_ => delete obj[_]);
56+
}
57+
function typecheckReset() {
58+
clearObject(typecheckOptions.warned);
59+
}
6060
export {typecheckReport, clearObject, typecheckReset, typecheckOptions};

src-runtime/typecheckWarn.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import {typecheckOptions} from "./typecheckOptions.mjs";
44
* @param {...any} extra - Extra strings or objects etc.
55
*/
66
function typecheckWarn(msg, ...extra) {
7-
const { mode, warned } = typecheckOptions;
8-
warned[msg] = warned[msg] || { hits: 0 };
7+
const {mode, warned} = typecheckOptions;
8+
warned[msg] = warned[msg] || {hits: 0};
99
warned[msg].hits++;
1010
switch (mode) {
1111
case 'spam':

src-runtime/validateArray.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import {assertType } from "./assertType.mjs";
22
import {typecheckEvery} from "./typecheckEvery.mjs";
33
/**
4-
* @param {*} value
5-
* @param {*} expect
6-
* @param {*} loc
7-
* @param {*} name
8-
* @param {*} critical
9-
* @returns {boolean}
4+
* @param {*} value - The actual value that we need to validate.
5+
* @param {*} expect - The supposed type information of said value.
6+
* @param {string} loc - String like `BoundingBox#compute`
7+
* @param {string} name - Name of the argument
8+
* @param {boolean} critical - Only `false` for unions.
9+
* @returns {boolean} - Boolean indicating if a type is correct.
1010
*/
1111
function validateArray(value, expect, loc, name, critical) {
1212
if (value && value instanceof Array) {
13-
const { elementType } = expect;
13+
const {elementType} = expect;
1414
// some that not validate -> type error
1515
return typecheckEvery(value, (_, i) => assertType(
1616
_,

src-runtime/validateDivision.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ import {typecheckWarn} from "./typecheckWarn.mjs";
66
* validateDivision( 1 , 2 ); // Outputs: 0.5
77
* validateDivision( 1 , "2"); // Warns: validateDivision> incompatible type pair
88
* validateDivision(10n, 2n); // Outputs: 5n
9-
* @returns {number}
9+
* @returns {number} The division result.
1010
*/
1111
function validateDivision(lhs, rhs) {
1212
const ret = lhs / rhs;
1313
const twoNumbers = typeof lhs === 'number' && typeof rhs === 'number';
1414
const twoBigInts = typeof lhs === 'bigint' && typeof rhs === 'bigint';
1515
const valid = twoNumbers || twoBigInts;
1616
if (!valid) {
17-
typecheckWarn(`validateDivision> incompatible type pair`, { lhs, rhs, twoNumbers, twoBigInts });
17+
typecheckWarn(`validateDivision> incompatible type pair`, {lhs, rhs, twoNumbers, twoBigInts});
1818
}
1919
// If we got two bigint's, we are done, as isNaN and isFinite is only for "normal" numbers.
2020
if (twoBigInts) {
2121
return ret;
2222
}
2323
if (isNaN(ret)) {
24-
typecheckWarn(`validateDivision> NaN`, { lhs, rhs });
24+
typecheckWarn(`validateDivision> NaN`, {lhs, rhs});
2525
}
2626
if (!isFinite(ret)) {
27-
typecheckWarn(`validateDivision> +-Infinity`, { lhs, rhs });
27+
typecheckWarn(`validateDivision> +-Infinity`, {lhs, rhs});
2828
}
2929
return ret;
3030
}

src-runtime/validateMap.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import {assertType } from "./assertType.mjs";
22
import {typecheckWarn} from "./typecheckWarn.mjs";
33
/**
44
* @todo Implement checking all possible key/val types
5-
* @param {*} value
6-
* @param {*} expect
7-
* @param {*} loc
8-
* @param {*} name
9-
* @param {*} critical
10-
* @returns {boolean}
5+
* @param {*} value - The actual value that we need to validate.
6+
* @param {*} expect - The supposed type information of said value.
7+
* @param {string} loc - String like `BoundingBox#compute`
8+
* @param {string} name - Name of the argument
9+
* @param {boolean} critical - Only `false` for unions.
10+
* @returns {boolean} - Boolean indicating if a type is correct.
1111
*/
1212
function validateMap(value, expect, loc, name, critical) {
13-
const { key, val } = expect;
13+
const {key, val} = expect;
1414
if (key !== 'string') {
1515
typecheckWarn(`${loc}> validateType> map> unhandled key '${key}'`);
1616
return false;

src-runtime/validateNumber.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ function validateNumber(obj, prop) {
99
const val = obj[prop];
1010
const type = typeof obj;
1111
if (val === null) {
12-
typecheckWarn(`${type}#${prop} null`, { obj });
12+
typecheckWarn(`${type}#${prop} null`, {obj});
1313
return false;
1414
}
1515
if (val === undefined) {
16-
typecheckWarn(`${type}#${prop} undefined`, { obj });
16+
typecheckWarn(`${type}#${prop} undefined`, {obj});
1717
return false;
1818
}
1919
if (isNaN(val)) {
20-
typecheckWarn(`${type}#${prop} NaN`, { obj });
20+
typecheckWarn(`${type}#${prop} NaN`, {obj});
2121
return false;
2222
}
2323
if (!isFinite(val)) {
24-
typecheckWarn(`${type}#${prop} +-Infinity`, { obj });
24+
typecheckWarn(`${type}#${prop} +-Infinity`, {obj});
2525
return false;
2626
}
2727
return true;

src-runtime/validateObject.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {assertType } from "./assertType.mjs";
22
import {typecheckOptions} from "./typecheckOptions.mjs";
33
import {typecheckWarn } from "./typecheckWarn.mjs";
44
/**
5-
* @param {*} value
6-
* @param {*} properties
7-
* @param {*} loc
8-
* @param {*} name
9-
* @param {*} critical
10-
* @returns {boolean}
5+
* @param {*} value - The actual value that we need to validate.
6+
* @param {*} properties - The properties.
7+
* @param {string} loc - String like `BoundingBox#compute`
8+
* @param {string} name - Name of the argument
9+
* @param {boolean} critical - Only `false` for unions.
10+
* @returns {boolean} - Boolean indicating if a type is correct.
1111
*/
1212
function validateObject(value, properties, loc, name, critical) {
1313
if (!(value instanceof Object)) {
@@ -21,7 +21,7 @@ function validateObject(value, properties, loc, name, critical) {
2121
}
2222
if (!properties[key]) {
2323
if (typecheckOptions.logSuperfluousProperty) {
24-
typecheckWarn(`${loc}> superfluous property> ${name}.${key}`, { properties, value });
24+
typecheckWarn(`${loc}> superfluous property> ${name}.${key}`, {properties, value});
2525
}
2626
}
2727
});

src-runtime/validateRecord.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {assertType } from "./assertType.mjs";
22
import {typecheckWarn} from "./typecheckWarn.mjs";
33
/**
4-
* @param {*} value
5-
* @param {*} expect
6-
* @param {*} loc
7-
* @param {*} name
8-
* @param {*} critical
9-
* @returns {boolean}
4+
* @param {*} value - The actual value that we need to validate.
5+
* @param {*} expect - The supposed type information of said value.
6+
* @param {string} loc - String like `BoundingBox#compute`
7+
* @param {string} name - Name of the argument
8+
* @param {boolean} critical - Only `false` for unions.
9+
* @returns {boolean} - Boolean indicating if a type is correct.
1010
*/
1111
function validateRecord(value, expect, loc, name, critical) {
1212
const {key, val} = expect;

src-runtime/validateSet.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import {assertType } from "./assertType.mjs";
22
import {typecheckWarn} from "./typecheckWarn.mjs";
33
/**
4-
* @param {*} value
5-
* @param {*} expect
6-
* @param {*} loc
7-
* @param {*} name
8-
* @param {*} critical
9-
* @return {boolean}
4+
* @param {*} value - The actual value that we need to validate.
5+
* @param {*} expect - The supposed type information of said value.
6+
* @param {string} loc - String like `BoundingBox#compute`
7+
* @param {string} name - Name of the argument
8+
* @param {boolean} critical - Only `false` for unions.
9+
* @returns {boolean} - Boolean indicating if a type is correct.
1010
*/
1111
function validateSet(value, expect, loc, name, critical) {
1212
if (!(value instanceof Set)) {

src-runtime/validateTuple.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {assertType} from "./assertType.mjs";
22
/**
3-
* @param {*} value
4-
* @param {*} expect
5-
* @param {*} loc
6-
* @param {*} name
7-
* @param {*} critical
8-
* @returns {boolean}
3+
* @param {*} value - The actual value that we need to validate.
4+
* @param {*} expect - The supposed type information of said value.
5+
* @param {string} loc - String like `BoundingBox#compute`
6+
* @param {string} name - Name of the argument
7+
* @param {boolean} critical - Only `false` for unions.
8+
* @returns {boolean} - Boolean indicating if a type is correct.
99
*/
1010
function validateTuple(value, expect, loc, name, critical) {
1111
if (!value) {
@@ -14,7 +14,7 @@ function validateTuple(value, expect, loc, name, critical) {
1414
if (!(value instanceof Array)) {
1515
return false;
1616
}
17-
const { elements } = expect;
17+
const {elements} = expect;
1818
return elements.every((element, i) => {
1919
return assertType(
2020
value[i],

0 commit comments

Comments
 (0)