From 13278a5cf67de69678d8c4c5fb97e6eb00c94c11 Mon Sep 17 00:00:00 2001 From: James Maa Date: Thu, 9 May 2024 15:42:35 +0800 Subject: Update eslint unsafe rule (#887) * Enable @typescript-eslint/no-unsafe-assignment * Updates * Add missing import * Updates * Fix types? * Fix tests * Address comments * Move TextProcessorVariant to types * Update types/ext/translation-internal.d.ts Co-authored-by: StefanVukovic99 Signed-off-by: James Maa --------- Signed-off-by: James Maa Co-authored-by: toasted-nutbread Co-authored-by: StefanVukovic99 --- test/dom-text-scanner.test.js | 7 ++++++- test/fixtures/dom-test.js | 2 ++ test/handlebars.test.js | 24 ++++++++++++++++++++---- 3 files changed, 28 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/dom-text-scanner.test.js b/test/dom-text-scanner.test.js index b366cadd..4ec3a44d 100644 --- a/test/dom-text-scanner.test.js +++ b/test/dom-text-scanner.test.js @@ -85,8 +85,13 @@ function createAbsoluteGetComputedStyle(window) { return (element, ...args) => { const style = getComputedStyleOld(element, ...args); return new Proxy(style, { + /** + * @param {CSSStyleDeclaration} target + * @param {string|symbol} property + * @returns {unknown} + */ get: (target, property) => { - let result = /** @type {import('core').SafeAny} */ (target)[property]; + let result = /** @type {Record} */ (/** @type {unknown} */ (target))[property]; if (typeof result === 'string') { /** * @param {string} g0 diff --git a/test/fixtures/dom-test.js b/test/fixtures/dom-test.js index 459383cc..364612f6 100644 --- a/test/fixtures/dom-test.js +++ b/test/fixtures/dom-test.js @@ -28,7 +28,9 @@ function prepareWindow(window) { // Define innerText setter as an alias for textContent setter Object.defineProperty(window.HTMLDivElement.prototype, 'innerText', { + /** @returns {string} */ get() { return this.textContent; }, + /** @param {string} value */ set(value) { this.textContent = value; } }); diff --git a/test/handlebars.test.js b/test/handlebars.test.js index d65e8c42..8a566f4c 100644 --- a/test/handlebars.test.js +++ b/test/handlebars.test.js @@ -18,6 +18,22 @@ import {describe, test} from 'vitest'; import {Handlebars} from '../ext/lib/handlebars.js'; +/** + * @param {string} template + * @returns {import('handlebars').TemplateDelegate} + */ +function compile(template) { + return Handlebars.compile(template); +} + +/** + * @param {string} template + * @returns {import('handlebars').TemplateDelegate} + */ +function compileAST(template) { + return Handlebars.compileAST(template); +} + describe('Handlebars', () => { test('compile vs compileAST 1', ({expect}) => { const template = '{{~test1~}}'; @@ -26,8 +42,8 @@ describe('Handlebars', () => { test1: '
Test
' }; - const instance1 = Handlebars.compile(template); - const instance2 = Handlebars.compileAST(template); + const instance1 = compile(template); + const instance2 = compileAST(template); const result1 = instance1(data); const result2 = instance2(data); @@ -44,8 +60,8 @@ describe('Handlebars', () => { } }; - const instance1 = Handlebars.compile(template); - const instance2 = Handlebars.compileAST(template); + const instance1 = compile(template); + const instance2 = compileAST(template); const result1 = instance1(data); const result2 = instance2(data); -- cgit v1.2.3