From 91aad253895b53e95abedfdd0f934f04b478053a Mon Sep 17 00:00:00 2001 From: David Anson Date: Sat, 27 Sep 2025 06:21:34 +0000 Subject: [PATCH] Address new code analysis issues from previous commit. --- lib/cache.mjs | 4 +++- lib/defer-require.cjs | 2 ++ schema/build-config-example.mjs | 4 ++-- test/esm-helpers.mjs | 2 ++ test/markdownlint-test-custom-rules.mjs | 12 +++++++++--- test/markdownlint-test.mjs | 3 ++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/cache.mjs b/lib/cache.mjs index c05b9927..43c44cce 100644 --- a/lib/cache.mjs +++ b/lib/cache.mjs @@ -36,11 +36,12 @@ export function micromarkTokens() { * Gets a cached object value - computes it and caches it. * * @param {string} name Cache object name. - * @param {Function} getValue Getter for object value. + * @param {() => Object} getValue Getter for object value. * @returns {Object} Object value. */ function getCached(name, getValue) { if (map.has(name)) { + // @ts-ignore return map.get(name); } const value = getValue(); @@ -56,6 +57,7 @@ function getCached(name, getValue) { * @returns {MicromarkToken[]} Filtered tokens. */ export function filterByTypesCached(types, htmlFlow) { + // @ts-ignore return getCached( // eslint-disable-next-line prefer-rest-params JSON.stringify(arguments), diff --git a/lib/defer-require.cjs b/lib/defer-require.cjs index dc87ebc4..f52a39bc 100644 --- a/lib/defer-require.cjs +++ b/lib/defer-require.cjs @@ -2,6 +2,8 @@ "use strict"; +/* eslint-disable jsdoc/reject-any-type */ + /** * Calls require for markdownit.cjs. Used to synchronously defer loading because module.createRequire is buggy under webpack (https://github.com/webpack/webpack/issues/16724). * diff --git a/schema/build-config-example.mjs b/schema/build-config-example.mjs index 766c4f23..6f9334c4 100644 --- a/schema/build-config-example.mjs +++ b/schema/build-config-example.mjs @@ -6,7 +6,7 @@ import yaml from "js-yaml"; import { __dirname, importWithTypeJson } from "../test/esm-helpers.mjs"; const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json"); -/** @type {Object} */ +/** @type {import("markdownlint").Configuration} */ const configExample = {}; for (const rule in configSchema.properties) { if (/^(?:MD\d{3}|default|extends)$/.test(rule)) { @@ -19,7 +19,7 @@ for (const rule in configSchema.properties) { ).filter(([ key ]) => ((key !== "enabled") && (key !== "severity"))) ); if (Object.keys(subproperties).length > 0) { - /** @type {Object} */ + /** @type {import("markdownlint").Configuration} */ const ruleExample = {}; // eslint-disable-next-line guard-for-in for (const property in subproperties) { diff --git a/test/esm-helpers.mjs b/test/esm-helpers.mjs index a31e4979..19f39af9 100644 --- a/test/esm-helpers.mjs +++ b/test/esm-helpers.mjs @@ -26,6 +26,8 @@ export const __filename = (meta) => fileURLToPath(meta.url); // eslint-disable-next-line no-underscore-dangle export const __dirname = (meta) => path.dirname(__filename(meta)); +/* eslint-disable jsdoc/reject-any-type */ + /** * Imports a file as JSON. * Avoids "ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time". diff --git a/test/markdownlint-test-custom-rules.mjs b/test/markdownlint-test-custom-rules.mjs index 780f710b..fc0723bf 100644 --- a/test/markdownlint-test-custom-rules.mjs +++ b/test/markdownlint-test-custom-rules.mjs @@ -1216,16 +1216,18 @@ test("customRulesOnErrorBad", (t) => { ]) { const { propertyName, subPropertyName, propertyValues } = testCase; for (const propertyValue of propertyValues) { - /** @type {Object} */ const badObject = { "lineNumber": 1 }; let propertyNames = null; if (subPropertyName) { + // @ts-ignore badObject[propertyName] = {}; + // @ts-ignore badObject[propertyName][subPropertyName] = propertyValue; propertyNames = `${propertyName}.${subPropertyName}`; } else { + // @ts-ignore badObject[propertyName] = propertyValue; propertyNames = propertyName; } @@ -1290,16 +1292,18 @@ test("customRulesOnErrorInvalid", (t) => { ]) { const { propertyName, subPropertyName, propertyValues } = testCase; for (const propertyValue of propertyValues) { - /** @type {Object} */ const badObject = { "lineNumber": 1 }; let propertyNames = null; if (subPropertyName) { + // @ts-ignore badObject[propertyName] = {}; + // @ts-ignore badObject[propertyName][subPropertyName] = propertyValue; propertyNames = `${propertyName}.${subPropertyName}`; } else { + // @ts-ignore badObject[propertyName] = propertyValue; propertyNames = propertyName; } @@ -1370,14 +1374,16 @@ test("customRulesOnErrorValid", (t) => { ]) { const { propertyName, subPropertyName, propertyValues } = testCase; for (const propertyValue of propertyValues) { - /** @type {Object} */ const goodObject = { "lineNumber": 1 }; if (subPropertyName) { + // @ts-ignore goodObject[propertyName] = {}; + // @ts-ignore goodObject[propertyName][subPropertyName] = propertyValue; } else { + // @ts-ignore goodObject[propertyName] = propertyValue; } /** @type {import("markdownlint").Options} */ diff --git a/test/markdownlint-test.mjs b/test/markdownlint-test.mjs index 62b1a0b2..b9f70572 100644 --- a/test/markdownlint-test.mjs +++ b/test/markdownlint-test.mjs @@ -24,7 +24,7 @@ import customRules from "./rules/rules.cjs"; import { __dirname, importWithTypeJson } from "./esm-helpers.mjs"; /** @type {{exports: Object., homepage: string, version: string}} */ const packageJson = await importWithTypeJson(import.meta, "../package.json"); -/** @type {{$id: string, properties: Object}} */ +/** @type {{$id: string, properties: Object}} */ const configSchema = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema.json"); const configSchemaStrict = await importWithTypeJson(import.meta, "../schema/markdownlint-config-schema-strict.json"); @@ -1190,6 +1190,7 @@ test("validateConfigExampleJson", (t) => { configSchema.$id.replace(/^.*\/v(?\d+\.\d+\.\d+)\/.*$/u, "$"), packageJson.version ); + // @ts-ignore t.is(configSchema.$id, configSchema.properties.$schema.default); // Validate JSONC