Start to enable default javscript/typescript lint rules

This enables the recommended rules useConst and useImportType
This commit is contained in:
Nigel Breslaw 2024-09-12 16:08:52 +02:00 committed by GitHub
parent 8d9c041aa4
commit 2bee820ccf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 197 additions and 185 deletions

View file

@ -11,11 +11,11 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
// loadFile api
test("loadFile", (t) => {
let demo = loadFile(path.join(dirname, "resources/test.slint")) as any;
let test = new demo.Test();
const demo = loadFile(path.join(dirname, "resources/test.slint")) as any;
const test = new demo.Test();
t.is(test.check, "Test");
let errorPath = path.join(dirname, "resources/error.slint");
const errorPath = path.join(dirname, "resources/error.slint");
const error = t.throws(
() => {
@ -63,11 +63,11 @@ test("loadFile", (t) => {
});
test("loadFile constructor parameters", (t) => {
let demo = loadFile(
const demo = loadFile(
path.join(dirname, "resources/test-constructor.slint"),
) as any;
let hello = "";
let test = new demo.Test({
const test = new demo.Test({
say_hello: function () {
hello = "hello";
},
@ -82,7 +82,7 @@ test("loadFile constructor parameters", (t) => {
test("loadFile component instances and modules are sealed", (t) => {
"use strict";
let demo = loadFile(path.join(dirname, "resources/test.slint")) as any;
const demo = loadFile(path.join(dirname, "resources/test.slint")) as any;
t.throws(
() => {
@ -91,7 +91,7 @@ test("loadFile component instances and modules are sealed", (t) => {
{ instanceOf: TypeError },
);
let test = new demo.Test();
const test = new demo.Test();
t.is(test.check, "Test");
t.throws(
@ -108,8 +108,8 @@ test("loadSource", (t) => {
out property <string> check: "Test";
}`;
const path = "api.spec.ts";
let demo = loadSource(source, path) as any;
let test = new demo.Test();
const demo = loadSource(source, path) as any;
const test = new demo.Test();
t.is(test.check, "Test");
const errorSource = `export component Error {
@ -166,9 +166,9 @@ test("loadSource constructor parameters", (t) => {
in-out property <string> check;
}`;
const path = "api.spec.ts";
let demo = loadSource(source, path) as any;
const demo = loadSource(source, path) as any;
let hello = "";
let test = new demo.Test({
const test = new demo.Test({
say_hello: function () {
hello = "hello";
},
@ -187,7 +187,7 @@ test("loadSource component instances and modules are sealed", (t) => {
out property <string> check: "Test";
}`;
const path = "api.spec.ts";
let demo = loadSource(source, path) as any;
const demo = loadSource(source, path) as any;
t.throws(
() => {
@ -196,7 +196,7 @@ test("loadSource component instances and modules are sealed", (t) => {
{ instanceOf: TypeError },
);
let test = new demo.Test();
const test = new demo.Test();
t.is(test.check, "Test");
t.throws(

View file

@ -6,7 +6,7 @@ import test from "ava";
import { private_api } from "../index.js";
test("get/set include paths", (t) => {
let compiler = new private_api.ComponentCompiler();
const compiler = new private_api.ComponentCompiler();
t.is(compiler.includePaths.length, 0);
@ -20,7 +20,7 @@ test("get/set include paths", (t) => {
});
test("get/set library paths", (t) => {
let compiler = new private_api.ComponentCompiler();
const compiler = new private_api.ComponentCompiler();
compiler.libraryPaths = {
"libfile.slint": "third_party/libfoo/ui/lib.slint",
@ -34,7 +34,7 @@ test("get/set library paths", (t) => {
});
test("get/set style", (t) => {
let compiler = new private_api.ComponentCompiler();
const compiler = new private_api.ComponentCompiler();
t.is(compiler.style, null);
@ -43,8 +43,8 @@ test("get/set style", (t) => {
});
test("get/set build from source", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(`export component App {}`, "");
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(`export component App {}`, "");
t.not(definition.App, null);
t.is(definition.App!.name, "App");
});
@ -68,8 +68,8 @@ test("constructor error ComponentDefinition and ComponentInstance", (t) => {
});
test("properties ComponentDefinition", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`export struct Struct {}
export component App {
in-out property <bool> bool-property;
@ -86,7 +86,7 @@ test("properties ComponentDefinition", (t) => {
);
t.not(definition.App, null);
let properties = definition.App!.properties;
const properties = definition.App!.properties;
t.is(properties.length, 9);
properties.sort((a, b) => {
@ -125,8 +125,8 @@ test("properties ComponentDefinition", (t) => {
});
test("callbacks ComponentDefinition", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
callback first-callback();
@ -136,7 +136,7 @@ test("callbacks ComponentDefinition", (t) => {
);
t.not(definition.App, null);
let callbacks = definition.App!.callbacks;
const callbacks = definition.App!.callbacks;
t.is(callbacks.length, 2);
callbacks.sort();
@ -146,8 +146,8 @@ test("callbacks ComponentDefinition", (t) => {
});
test("globalProperties ComponentDefinition", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`export struct Struct {}
export global TestGlobal {
@ -171,7 +171,7 @@ test("globalProperties ComponentDefinition", (t) => {
t.is(definition.App!.globalProperties("NonExistent"), null);
let properties = definition.App!.globalProperties("TestGlobal");
const properties = definition.App!.globalProperties("TestGlobal");
t.not(properties, null);
t.is(properties!.length, 9);
@ -212,8 +212,8 @@ test("globalProperties ComponentDefinition", (t) => {
});
test("globalCallbacks ComponentDefinition", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export global TestGlobal {
callback first-callback();
@ -227,7 +227,7 @@ test("globalCallbacks ComponentDefinition", (t) => {
t.is(definition.App!.globalCallbacks("NonExistent"), null);
let callbacks = definition.App!.globalCallbacks("TestGlobal");
const callbacks = definition.App!.globalCallbacks("TestGlobal");
t.not(callbacks, null);
t.is(callbacks!.length, 2);
@ -238,7 +238,7 @@ test("globalCallbacks ComponentDefinition", (t) => {
});
test("compiler diagnostics", (t) => {
let compiler = new private_api.ComponentCompiler();
const compiler = new private_api.ComponentCompiler();
t.deepEqual(
compiler.buildFromSource(
`export component App {
@ -261,8 +261,8 @@ test("compiler diagnostics", (t) => {
});
test("non-existent properties and callbacks", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
@ -271,7 +271,7 @@ test("non-existent properties and callbacks", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
const prop_err = t.throws(() => {

View file

@ -32,8 +32,8 @@ test.serial("merged event loops with networking", async (t) => {
await runEventLoop(() => {
const server = http.createServer(listener);
server.listen(async () => {
let host = "localhost";
let port = (server.address() as any).port;
const host = "localhost";
const port = (server.address() as any).port;
console.log(`server ready at ${host}:${port}`);
(fetch as any)(`http://${host}:${port}/`)
@ -55,8 +55,8 @@ test.serial("merged event loops with networking", async (t) => {
test.serial(
"quit event loop on last window closed with callback",
async (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App inherits Window {
@ -67,7 +67,7 @@ test.serial(
);
t.not(definition.App, null);
let instance = definition.App!.create() as any;
const instance = definition.App!.create() as any;
t.not(instance, null);
instance.window().show();

View file

@ -6,8 +6,8 @@ import test from "ava";
import { private_api } from "../index.js";
test("get/set global properties", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export global Global { in-out property <string> name: "Initial"; }
export component App {}`,
@ -15,7 +15,7 @@ test("get/set global properties", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.is(instance!.getGlobalProperty("Global", "name"), "Initial");
@ -85,8 +85,8 @@ test("get/set global properties", (t) => {
});
test("invoke global callback", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export struct Person {
name: string
@ -114,7 +114,7 @@ test("invoke global callback", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.throws(

View file

@ -12,14 +12,14 @@ const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
test("get/set string properties", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`export component App { in-out property <string> name: "Initial"; }`,
"",
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.is(instance!.getProperty("name"), "Initial");
@ -49,8 +49,8 @@ test("get/set string properties", (t) => {
});
test("get/set number properties", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
in-out property <float> age: 42;
@ -59,7 +59,7 @@ test("get/set number properties", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.is(instance!.getProperty("age"), 42);
@ -89,14 +89,14 @@ test("get/set number properties", (t) => {
});
test("get/set bool properties", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`export component App { in-out property <bool> ready: true; }`,
"",
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.is(instance!.getProperty("ready"), true);
@ -126,8 +126,8 @@ test("get/set bool properties", (t) => {
});
test("set struct properties", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export struct Player {
name: string,
@ -146,7 +146,7 @@ test("set struct properties", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.deepEqual(instance!.getProperty("player"), {
@ -190,8 +190,8 @@ test("set struct properties", (t) => {
});
test("get/set image properties", async (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
in-out property <image> image: @image-url("resources/rgb.png");
@ -202,16 +202,16 @@ test("get/set image properties", async (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let slintImage = instance!.getProperty("image");
const slintImage = instance!.getProperty("image");
if (t.true(slintImage instanceof private_api.SlintImageData)) {
t.deepEqual((slintImage as private_api.SlintImageData).width, 64);
t.deepEqual((slintImage as private_api.SlintImageData).height, 64);
t.true((slintImage as ImageData).path.endsWith("rgb.png"));
let image = await Jimp.read(path.join(dirname, "resources/rgb.png"));
const image = await Jimp.read(path.join(dirname, "resources/rgb.png"));
// Sanity check: setProperty fails when passed definitely a non-image
t.throws(
@ -273,8 +273,8 @@ test("get/set image properties", async (t) => {
});
test("get/set brush properties", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
in-out property <brush> black: #000000;
@ -289,37 +289,37 @@ test("get/set brush properties", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let black = instance!.getProperty("black");
const black = instance!.getProperty("black");
t.is((black as private_api.SlintBrush).toString(), "#000000ff");
if (t.true(black instanceof private_api.SlintBrush)) {
let blackSlintRgbaColor = (black as private_api.SlintBrush).color;
const blackSlintRgbaColor = (black as private_api.SlintBrush).color;
t.deepEqual(blackSlintRgbaColor.red, 0);
t.deepEqual(blackSlintRgbaColor.green, 0);
t.deepEqual(blackSlintRgbaColor.blue, 0);
}
instance?.setProperty("black", "#ffffff");
let white = instance!.getProperty("black");
const white = instance!.getProperty("black");
if (t.true(white instanceof private_api.SlintBrush)) {
let whiteSlintRgbaColor = (white as private_api.SlintBrush).color;
const whiteSlintRgbaColor = (white as private_api.SlintBrush).color;
t.deepEqual(whiteSlintRgbaColor.red, 255);
t.deepEqual(whiteSlintRgbaColor.green, 255);
t.deepEqual(whiteSlintRgbaColor.blue, 255);
}
let transparent = instance!.getProperty("trans");
const transparent = instance!.getProperty("trans");
if (t.true(black instanceof private_api.SlintBrush)) {
t.assert((transparent as private_api.SlintBrush).isTransparent);
}
let ref = new private_api.SlintBrush({
const ref = new private_api.SlintBrush({
red: 100,
green: 110,
blue: 120,
@ -330,7 +330,7 @@ test("get/set brush properties", (t) => {
let instance_ref = instance!.getProperty("ref");
if (t.true(instance_ref instanceof private_api.SlintBrush)) {
let ref_color = (instance_ref as private_api.SlintBrush).color;
const ref_color = (instance_ref as private_api.SlintBrush).color;
t.deepEqual(ref_color.red, 100);
t.deepEqual(ref_color.green, 110);
t.deepEqual(ref_color.blue, 120);
@ -344,7 +344,7 @@ test("get/set brush properties", (t) => {
instance_ref = instance!.getProperty("ref");
if (t.true(instance_ref instanceof private_api.SlintBrush)) {
let ref_color = (instance_ref as private_api.SlintBrush).color;
const ref_color = (instance_ref as private_api.SlintBrush).color;
t.deepEqual(ref_color.red, 110);
t.deepEqual(ref_color.green, 120);
t.deepEqual(ref_color.blue, 125);
@ -361,7 +361,7 @@ test("get/set brush properties", (t) => {
instance_ref = instance!.getProperty("ref");
if (t.true(instance_ref instanceof private_api.SlintBrush)) {
let ref_color = (instance_ref as private_api.SlintBrush).color;
const ref_color = (instance_ref as private_api.SlintBrush).color;
t.deepEqual(ref_color.red, 110);
t.deepEqual(ref_color.green, 120);
t.deepEqual(ref_color.blue, 125);
@ -373,14 +373,14 @@ test("get/set brush properties", (t) => {
instance_ref = instance!.getProperty("ref");
if (t.true(instance_ref instanceof private_api.SlintBrush)) {
let ref_color = (instance_ref as private_api.SlintBrush).color;
const ref_color = (instance_ref as private_api.SlintBrush).color;
t.deepEqual(ref_color.red, 0);
t.deepEqual(ref_color.green, 0);
t.deepEqual(ref_color.blue, 0);
t.deepEqual(ref_color.alpha, 0);
}
let radialGradient = instance!.getProperty("radial-gradient");
const radialGradient = instance!.getProperty("radial-gradient");
if (t.true(radialGradient instanceof private_api.SlintBrush)) {
t.is(
@ -389,7 +389,7 @@ test("get/set brush properties", (t) => {
);
}
let linearGradient = instance!.getProperty("linear-gradient");
const linearGradient = instance!.getProperty("linear-gradient");
if (t.true(linearGradient instanceof private_api.SlintBrush)) {
t.is(
@ -484,7 +484,7 @@ test("get/set brush properties", (t) => {
instance_ref = instance!.getProperty("ref-color");
if (t.true(instance_ref instanceof private_api.SlintBrush)) {
let ref_color = (instance_ref as private_api.SlintBrush).color;
const ref_color = (instance_ref as private_api.SlintBrush).color;
t.deepEqual(ref_color.red, 0);
t.deepEqual(ref_color.green, 0);
t.deepEqual(ref_color.blue, 0);
@ -493,8 +493,8 @@ test("get/set brush properties", (t) => {
});
test("ArrayModel", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export struct Player {
name: string,
@ -510,14 +510,14 @@ test("ArrayModel", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
t.deepEqual(Array.from(new ArrayModel([3, 2, 1])), [3, 2, 1]);
instance!.setProperty("int-model", new ArrayModel([10, 9, 8]));
let intArrayModel = instance!.getProperty(
const intArrayModel = instance!.getProperty(
"int-model",
) as ArrayModel<number>;
t.deepEqual(intArrayModel.rowCount(), 3);
@ -528,7 +528,7 @@ test("ArrayModel", (t) => {
new ArrayModel(["Simon", "Olivier", "Auri", "Tobias", "Florian"]),
);
let stringArrayModel = instance!.getProperty(
const stringArrayModel = instance!.getProperty(
"string-model",
) as ArrayModel<number>;
t.deepEqual(
@ -550,7 +550,7 @@ test("ArrayModel", (t) => {
]),
);
let structArrayModel = instance!.getProperty(
const structArrayModel = instance!.getProperty(
"struct-model",
) as ArrayModel<object>;
t.deepEqual(
@ -563,8 +563,8 @@ test("ArrayModel", (t) => {
});
test("MapModel", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
in-out property <[string]> model;
@ -573,7 +573,7 @@ test("MapModel", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
interface Name {
@ -602,10 +602,10 @@ test("MapModel", (t) => {
});
test("MapModel undefined rowData sourcemodel", (t) => {
const nameModel: ArrayModel<Number> = new ArrayModel([1, 2, 3]);
const nameModel: ArrayModel<number> = new ArrayModel([1, 2, 3]);
let mapFunctionCallCount = 0;
const mapModel = new private_api.MapModel<Number, String>(
const mapModel = new private_api.MapModel<number, string>(
nameModel,
(data) => {
mapFunctionCallCount++;
@ -625,8 +625,8 @@ test("MapModel undefined rowData sourcemodel", (t) => {
});
test("ArrayModel rowCount", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
out property <int> model-length: model.length;
@ -636,10 +636,10 @@ test("ArrayModel rowCount", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let model = new ArrayModel([10, 9, 8]);
const model = new ArrayModel([10, 9, 8]);
instance!.setProperty("model", model);
t.is(3, model.rowCount());
@ -647,8 +647,8 @@ test("ArrayModel rowCount", (t) => {
});
test("ArrayModel rowData/setRowData", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
callback data(int) -> int;
@ -663,10 +663,10 @@ test("ArrayModel rowData/setRowData", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let model = new ArrayModel([10, 9, 8]);
const model = new ArrayModel([10, 9, 8]);
instance!.setProperty("model", model);
t.is(9, model.rowData(1));
@ -678,8 +678,8 @@ test("ArrayModel rowData/setRowData", (t) => {
});
test("Model notify", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
width: 300px;
@ -704,10 +704,10 @@ test("Model notify", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let model = new ArrayModel([100, 0]);
const model = new ArrayModel([100, 0]);
instance!.setProperty("fixed-height-model", model);
t.is(100, instance!.getProperty("layout-height") as number);
@ -720,8 +720,8 @@ test("Model notify", (t) => {
});
test("model from array", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App {
in-out property <[int]> int-array;
@ -731,11 +731,11 @@ test("model from array", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
instance!.setProperty("int-array", [10, 9, 8]);
let wrapped_int_model = instance!.getProperty("int-array");
const wrapped_int_model = instance!.getProperty("int-array");
t.deepEqual(Array.from(wrapped_int_model), [10, 9, 8]);
t.deepEqual(wrapped_int_model.rowCount(), 3);
t.deepEqual(wrapped_int_model.rowData(0), 10);
@ -750,7 +750,7 @@ test("model from array", (t) => {
"Tobias",
"Florian",
]);
let wrapped_string_model = instance!.getProperty("string-array");
const wrapped_string_model = instance!.getProperty("string-array");
t.deepEqual(wrapped_string_model.rowCount(), 5);
t.deepEqual(wrapped_string_model.rowData(0), "Simon");
t.deepEqual(wrapped_string_model.rowData(1), "Olivier");
@ -760,8 +760,8 @@ test("model from array", (t) => {
});
test("invoke callback", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export struct Person {
name: string
@ -787,7 +787,7 @@ test("invoke callback", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let speakTest;

View file

@ -6,7 +6,7 @@ import test from "ava";
import { private_api, ArrayModel } from "../index.js";
test("SlintColor from fromRgb", (t) => {
let color = private_api.SlintRgbaColor.fromRgb(100, 110, 120);
const color = private_api.SlintRgbaColor.fromRgb(100, 110, 120);
t.deepEqual(color.red, 100);
t.deepEqual(color.green, 110);
@ -14,7 +14,7 @@ test("SlintColor from fromRgb", (t) => {
});
test("SlintColor from fromArgb", (t) => {
let color = private_api.SlintRgbaColor.fromArgb(120, 100, 110, 120);
const color = private_api.SlintRgbaColor.fromArgb(120, 100, 110, 120);
t.deepEqual(color.red, 100);
t.deepEqual(color.green, 110);
@ -22,7 +22,9 @@ test("SlintColor from fromArgb", (t) => {
});
test("SlintColor brighter", (t) => {
let color = private_api.SlintRgbaColor.fromRgb(100, 110, 120).brighter(0.1);
const color = private_api.SlintRgbaColor.fromRgb(100, 110, 120).brighter(
0.1,
);
t.deepEqual(color.red, 110);
t.deepEqual(color.green, 121);
@ -30,7 +32,7 @@ test("SlintColor brighter", (t) => {
});
test("SlintColor darker", (t) => {
let color = private_api.SlintRgbaColor.fromRgb(100, 110, 120).darker(0.1);
const color = private_api.SlintRgbaColor.fromRgb(100, 110, 120).darker(0.1);
t.deepEqual(color.red, 91);
t.deepEqual(color.green, 100);
@ -38,7 +40,7 @@ test("SlintColor darker", (t) => {
});
test("private_api.SlintBrush from RgbaColor", (t) => {
let brush = new private_api.SlintBrush({
const brush = new private_api.SlintBrush({
red: 100,
green: 110,
blue: 120,
@ -66,7 +68,7 @@ test("private_api.SlintBrush from RgbaColor", (t) => {
});
test("private_api.SlintBrush from Brush", (t) => {
let brush = private_api.SlintBrush.fromBrush({
const brush = private_api.SlintBrush.fromBrush({
color: { red: 100, green: 110, blue: 120, alpha: 255 },
});
@ -88,7 +90,7 @@ test("private_api.SlintBrush from Brush", (t) => {
});
test("ArrayModel push", (t) => {
let arrayModel = new ArrayModel([0]);
const arrayModel = new ArrayModel([0]);
t.is(arrayModel.rowCount(), 1);
t.is(arrayModel.rowData(0), 0);
@ -99,7 +101,7 @@ test("ArrayModel push", (t) => {
});
test("ArrayModel setRowData", (t) => {
let arrayModel = new ArrayModel([0]);
const arrayModel = new ArrayModel([0]);
t.is(arrayModel.rowCount(), 1);
t.is(arrayModel.rowData(0), 0);
@ -110,7 +112,7 @@ test("ArrayModel setRowData", (t) => {
});
test("ArrayModel remove", (t) => {
let arrayModel = new ArrayModel([0, 2, 1]);
const arrayModel = new ArrayModel([0, 2, 1]);
t.is(arrayModel.rowCount(), 3);
t.is(arrayModel.rowData(0), 0);

View file

@ -18,8 +18,8 @@ test("Window constructor", (t) => {
});
test("Window show / hide", (t) => {
let compiler = new private_api.ComponentCompiler();
let definition = compiler.buildFromSource(
const compiler = new private_api.ComponentCompiler();
const definition = compiler.buildFromSource(
`
export component App inherits Window {
@ -30,10 +30,10 @@ test("Window show / hide", (t) => {
);
t.not(definition.App, null);
let instance = definition.App!.create();
const instance = definition.App!.create();
t.not(instance, null);
let window = instance!.window();
const window = instance!.window();
t.is(window.visible, false);
window.show();
t.is(window.visible, true);

View file

@ -11,7 +11,7 @@
"useArrowFunction": "off",
"noForEach": "off",
"noUselessConstructor": "off",
"noBannedTypes": "off"
"noBannedTypes": "warn"
},
"style": {
"noNonNullAssertion": "off",
@ -29,7 +29,6 @@
"noExplicitAny": "off",
"noAssignInExpressions": "off",
"noImplicitAnyLet": "off",
"noDoubleEquals": "warn",
"noRedundantUseStrict": "off"
}
}

View file

@ -126,7 +126,7 @@ class ModelIterator<T> implements Iterator<T> {
public next(): IteratorResult<T> {
if (this.row < this.model.rowCount()) {
let row = this.row;
const row = this.row;
this.row++;
return {
done: false,
@ -341,7 +341,7 @@ export class ArrayModel<T> extends Model<T> {
* @param values list of values that will be pushed to the array.
*/
push(...values: T[]) {
let size = this.#array.length;
const size = this.#array.length;
Array.prototype.push.apply(this.#array, values);
this.notifyRowAdded(size, arguments.length);
}
@ -352,7 +352,7 @@ export class ArrayModel<T> extends Model<T> {
* @returns The removed element or undefined if the array is empty.
*/
pop(): T | undefined {
let last = this.#array.pop();
const last = this.#array.pop();
if (last !== undefined) {
this.notifyRowRemoved(this.#array.length, 1);
}
@ -367,7 +367,7 @@ export class ArrayModel<T> extends Model<T> {
* @param size number of rows to remove.
*/
remove(index: number, size: number) {
let r = this.#array.splice(index, size);
const r = this.#array.splice(index, size);
this.notifyRowRemoved(index, size);
}
@ -535,7 +535,7 @@ export namespace private_api {
* @returns undefined if row is out of range otherwise the data.
*/
rowData(row: number): U | undefined {
let data = this.sourceModel.rowData(row);
const data = this.sourceModel.rowData(row);
if (data === undefined) {
return undefined;
}
@ -692,7 +692,7 @@ type LoadData =
function loadSlint(loadData: LoadData): Object {
const { filePath, options } = loadData.fileData;
let compiler = new napi.ComponentCompiler();
const compiler = new napi.ComponentCompiler();
if (typeof options !== "undefined") {
if (typeof options.style !== "undefined") {
@ -706,14 +706,14 @@ function loadSlint(loadData: LoadData): Object {
}
}
let definitions =
const definitions =
loadData.from === "file"
? compiler.buildFromPath(filePath)
: compiler.buildFromSource(loadData.fileData.source, filePath);
let diagnostics = compiler.diagnostics;
const diagnostics = compiler.diagnostics;
if (diagnostics.length > 0) {
let warnings = diagnostics.filter(
const warnings = diagnostics.filter(
(d) => d.level === napi.DiagnosticLevel.Warning,
);
@ -721,7 +721,7 @@ function loadSlint(loadData: LoadData): Object {
warnings.forEach((w) => console.warn("Warning: " + w));
}
let errors = diagnostics.filter(
const errors = diagnostics.filter(
(d) => d.level === napi.DiagnosticLevel.Error,
);
@ -730,17 +730,17 @@ function loadSlint(loadData: LoadData): Object {
}
}
let slint_module = Object.create({});
const slint_module = Object.create({});
Object.keys(definitions).forEach((key) => {
let definition = definitions[key];
const definition = definitions[key];
Object.defineProperty(
slint_module,
definition.name.replace(/-/g, "_"),
{
value: function (properties: any) {
let instance = definition.create();
const instance = definition.create();
if (instance == null) {
throw Error(
@ -750,7 +750,7 @@ function loadSlint(loadData: LoadData): Object {
}
for (var key in properties) {
let value = properties[key];
const value = properties[key];
if (value instanceof Function) {
instance.setCallback(key, value);
@ -759,9 +759,9 @@ function loadSlint(loadData: LoadData): Object {
}
}
let componentHandle = new Component(instance!);
const componentHandle = new Component(instance!);
instance!.definition().properties.forEach((prop) => {
let propName = prop.name.replace(/-/g, "_");
const propName = prop.name.replace(/-/g, "_");
if (componentHandle[propName] !== undefined) {
console.warn(
@ -781,7 +781,7 @@ function loadSlint(loadData: LoadData): Object {
});
instance!.definition().callbacks.forEach((cb) => {
let callbackName = cb.replace(/-/g, "_");
const callbackName = cb.replace(/-/g, "_");
if (componentHandle[callbackName] !== undefined) {
console.warn(
@ -810,7 +810,7 @@ function loadSlint(loadData: LoadData): Object {
});
instance!.definition().functions.forEach((cb) => {
let functionName = cb.replace(/-/g, "_");
const functionName = cb.replace(/-/g, "_");
if (componentHandle[functionName] !== undefined) {
console.warn(
@ -842,13 +842,16 @@ function loadSlint(loadData: LoadData): Object {
"Duplicated property name " + globalName,
);
} else {
let globalObject = Object.create({});
const globalObject = Object.create({});
instance!
.definition()
.globalProperties(globalName)
.forEach((prop) => {
let propName = prop.name.replace(/-/g, "_");
const propName = prop.name.replace(
/-/g,
"_",
);
if (globalObject[propName] !== undefined) {
console.warn(
@ -885,7 +888,7 @@ function loadSlint(loadData: LoadData): Object {
.definition()
.globalCallbacks(globalName)
.forEach((cb) => {
let callbackName = cb.replace(/-/g, "_");
const callbackName = cb.replace(/-/g, "_");
if (
globalObject[callbackName] !== undefined
@ -929,7 +932,7 @@ function loadSlint(loadData: LoadData): Object {
.definition()
.globalFunctions(globalName)
.forEach((cb) => {
let functionName = cb.replace(/-/g, "_");
const functionName = cb.replace(/-/g, "_");
if (
globalObject[functionName] !== undefined
@ -1089,7 +1092,7 @@ class EventLoop {
// Give the nodejs event loop 16 ms to tick. This polling is sub-optimal, but it's the best we
// can do right now.
const nodejsPollInterval = 16;
let id = setInterval(() => {
const id = setInterval(() => {
if (
napi.processEvents() === napi.ProcessEventsResult.Exited ||
this.#quit_loop