diff --git a/.github/release-please/manifest.json b/.github/release-please/manifest.json index 3b4eedf3..c7179404 100644 --- a/.github/release-please/manifest.json +++ b/.github/release-please/manifest.json @@ -1 +1 @@ -{".":"17.16.0"} +{ ".": "17.16.0" } diff --git a/lib/rules/hashbang.js b/lib/rules/hashbang.js index 786287dc..e6a1c5ba 100644 --- a/lib/rules/hashbang.js +++ b/lib/rules/hashbang.js @@ -52,8 +52,9 @@ function isNodeShebang(shebang, executableName) { */ function getExpectedExecutableName(context) { const extension = path.extname(context.filename ?? context.getFilename()) - /** @type {{ executableMap: Record }} */ - const { executableMap = {} } = context.options?.[0] ?? {} + const { executableMap = {} } = + /** @type {[{ executableMap: Record }]} */ + (context.options)?.[0] ?? {} return executableMap[extension] ?? "node" } diff --git a/lib/rules/no-deprecated-api.js b/lib/rules/no-deprecated-api.js index a875c8d2..a7d63819 100644 --- a/lib/rules/no-deprecated-api.js +++ b/lib/rules/no-deprecated-api.js @@ -738,7 +738,10 @@ function toName(type, path) { * @returns {ParsedOptions} Parsed options */ function parseOptions(context) { - const raw = context.options[0] || {} + const raw = /** @type {{ + ignoreModuleItems?: string[]; + ignoreGlobalItems?: string[]; + }} */ (context.options[0] || {}) const version = getConfiguredNodeVersion(context) const ignoredModuleItems = new Set(raw.ignoreModuleItems || []) const ignoredGlobalItems = new Set(raw.ignoreGlobalItems || []) diff --git a/lib/util/check-restricted.js b/lib/util/check-restricted.js index d825aa68..5a68fedc 100644 --- a/lib/util/check-restricted.js +++ b/lib/util/check-restricted.js @@ -96,7 +96,9 @@ function createRestrictions(defs) { * @returns {void} */ exports.checkForRestriction = function checkForRestriction(context, targets) { - const restrictions = createRestrictions(context.options[0]) + const restrictions = createRestrictions( + /** @type {string[]} */ (context.options[0]) + ) for (const target of targets) { const restriction = restrictions.find(r => r.match(target)) diff --git a/lib/util/check-unsupported-builtins.js b/lib/util/check-unsupported-builtins.js index 8096edb5..ff86d795 100644 --- a/lib/util/check-unsupported-builtins.js +++ b/lib/util/check-unsupported-builtins.js @@ -22,7 +22,10 @@ const { getScope } = require("../util/eslint-compat") * }>} Parsed value. */ function parseOptions(context) { - const raw = context.options[0] || {} + const raw = /** @type {{ + * ignores?: string[]; + * allowExperimental?: boolean; + * }} */ (context.options[0] || {}) const version = getConfiguredNodeVersion(context) const ignores = new Set(raw.ignores || []) const allowExperimental = raw.allowExperimental ?? false diff --git a/lib/util/get-allow-modules.js b/lib/util/get-allow-modules.js index c022257a..6fab96df 100644 --- a/lib/util/get-allow-modules.js +++ b/lib/util/get-allow-modules.js @@ -9,10 +9,14 @@ */ const DEFAULT_VALUE = [] +/** + * @typedef {{allowModules:? string[]}|undefined} Option + */ + /** * Gets `allowModules` property from a given option object. * - * @param {{allowModules:? string[]}|undefined} option - An option object to get. + * @param {Option} option - An option object to get. * @returns {string[]|null} The `allowModules` value, or `null`. */ function get(option) { @@ -34,9 +38,9 @@ function get(option) { */ module.exports = function getAllowModules(context) { return ( - get(context.options[0]) ?? - get(context.settings?.n) ?? - get(context.settings?.node) ?? + get(/** @type {Option} */ (context.options[0])) ?? + get(/** @type {Option} */ (context.settings?.n)) ?? + get(/** @type {Option} */ (context.settings?.node)) ?? DEFAULT_VALUE ) } diff --git a/lib/util/get-configured-node-version.js b/lib/util/get-configured-node-version.js index b6c785ed..d4ef2f9d 100644 --- a/lib/util/get-configured-node-version.js +++ b/lib/util/get-configured-node-version.js @@ -10,10 +10,14 @@ const getSemverRange = require("./get-semver-range") const fallbackRange = new Range(">=16.0.0") +/** + * @typedef {{ version:? string } | undefined} VersionOption + */ + /** * Gets `version` property from a given option object. * - * @param {Record|undefined} option - An option object to get. + * @param {VersionOption} option - An option object to get. * @returns {import("semver").Range|undefined} The `allowModules` value, or `null`. */ function getVersionRange(option) { @@ -55,9 +59,11 @@ function getEnginesNode(context) { */ module.exports = function getConfiguredNodeVersion(context) { return ( - getVersionRange(context.options?.[0]) ?? - getVersionRange(context.settings?.n) ?? - getVersionRange(context.settings?.node) ?? + getVersionRange(/** @type {VersionOption} */ (context.options?.[0])) ?? + getVersionRange(/** @type {VersionOption} */ (context.settings?.n)) ?? + getVersionRange( + /** @type {VersionOption} */ (context.settings?.node) + ) ?? getEnginesNode(context) ?? fallbackRange ) diff --git a/lib/util/get-convert-path.js b/lib/util/get-convert-path.js index 7f5a813b..53b8ea8a 100644 --- a/lib/util/get-convert-path.js +++ b/lib/util/get-convert-path.js @@ -111,10 +111,14 @@ function combine(converters) { } } +/** + * @typedef {{ convertPath?: ConvertPath } | undefined} ConvertPathOption + */ + /** * Parses `convertPath` property from a given option object. * - * @param {{convertPath?: ConvertPath}|undefined} option - An option object to get. + * @param {ConvertPathOption} option - An option object to get. * @returns {Converter['convert']|null} A function which converts a path., or `null`. */ function parse(option) { @@ -148,9 +152,9 @@ function parse(option) { */ module.exports = function getConvertPath(context) { return ( - parse(context.options?.[0]) ?? - parse(context.settings?.n) ?? - parse(context.settings?.node) ?? + parse(/** @type {ConvertPathOption} */ (context.options?.[0])) ?? + parse(/** @type {ConvertPathOption} */ (context.settings?.n)) ?? + parse(/** @type {ConvertPathOption} */ (context.settings?.node)) ?? identity ) } diff --git a/lib/util/get-resolve-paths.js b/lib/util/get-resolve-paths.js index 6d043129..6f9655fd 100644 --- a/lib/util/get-resolve-paths.js +++ b/lib/util/get-resolve-paths.js @@ -10,11 +10,16 @@ const DEFAULT_VALUE = [] /** * Gets `resolvePaths` property from a given option object. * - * @param {{ resolvePaths: unknown[] } | undefined} option - An option object to get. + * @param {unknown} option - An option object to get. * @returns {string[] | undefined} The `allowModules` value, or `null`. */ function get(option) { - if (Array.isArray(option?.resolvePaths)) { + if ( + option != null && + typeof option === "object" && + "resolvePaths" in option && + Array.isArray(option?.resolvePaths) + ) { return option.resolvePaths.map(String) } } diff --git a/lib/util/get-resolver-config.js b/lib/util/get-resolver-config.js index d7fd95b9..dde11942 100644 --- a/lib/util/get-resolver-config.js +++ b/lib/util/get-resolver-config.js @@ -11,10 +11,14 @@ /** @type {ResolverConfig} */ const DEFAULT_VALUE = {} +/** + * @typedef {{ resolverConfig?: ResolverConfig } | undefined} ResolverConfigOption + */ + /** * Gets `resolverConfig` property from a given option object. * - * @param {{ resolverConfig: ResolverConfig } | undefined} option - An option object to get. + * @param {ResolverConfigOption} option - An option object to get. * @returns {ResolverConfig | undefined} The `allowModules` value, or `null`. */ function get(option) { @@ -33,9 +37,11 @@ function get(option) { */ module.exports = function getResolverConfig(context, optionIndex = 0) { return ( - get(context.options?.[optionIndex]) ?? - get(context.settings?.n) ?? - get(context.settings?.node) ?? + get( + /** @type {ResolverConfigOption} */ (context.options?.[optionIndex]) + ) ?? + get(/** @type {ResolverConfigOption} */ (context.settings?.n)) ?? + get(/** @type {ResolverConfigOption} */ (context.settings?.node)) ?? DEFAULT_VALUE ) } diff --git a/lib/util/get-try-extensions.js b/lib/util/get-try-extensions.js index 87bc1a00..f4e14670 100644 --- a/lib/util/get-try-extensions.js +++ b/lib/util/get-try-extensions.js @@ -24,11 +24,16 @@ const DEFAULT_TS_VALUE = [ /** * Gets `tryExtensions` property from a given option object. * - * @param {{ tryExtensions: unknown[] } | undefined} option - An option object to get. + * @param {unknown} option - An option object to get. * @returns {string[] | undefined} The `tryExtensions` value, or `null`. */ function get(option) { - if (Array.isArray(option?.tryExtensions)) { + if ( + option != null && + typeof option === "object" && + "tryExtensions" in option && + Array.isArray(option?.tryExtensions) + ) { return option.tryExtensions.map(String) } } diff --git a/lib/util/get-typescript-extension-map.js b/lib/util/get-typescript-extension-map.js index b9e8ef19..93a856e7 100644 --- a/lib/util/get-typescript-extension-map.js +++ b/lib/util/get-typescript-extension-map.js @@ -129,8 +129,12 @@ function getFromTSConfigFromFile(context) { */ module.exports = function getTypescriptExtensionMap(context) { return ( - get(context.options?.[0]) || - get(context.settings?.n ?? context.settings?.node) || + get(/** @type {Options} */ (context.options?.[0])) || + get( + /** @type {Options} */ ( + context.settings?.n ?? context.settings?.node + ) + ) || getFromTSConfigFromFile(context) || PRESERVE_MAPPING ) diff --git a/lib/util/import-target.js b/lib/util/import-target.js index c12a0e6b..db1f31ed 100644 --- a/lib/util/import-target.js +++ b/lib/util/import-target.js @@ -345,7 +345,11 @@ module.exports = class ImportTarget { const requireResolve = resolver.create.sync(this.resolverConfig) - const cwd = this.context.settings?.cwd ?? process.cwd() + const cwd = + typeof this.context.settings?.cwd === "string" + ? this.context.settings?.cwd + : process.cwd() + for (const directory of this.getPaths()) { const baseDir = resolve(cwd, directory)