Skip to content

Commit

Permalink
fix: patch new eslint options types (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood authored Mar 2, 2025
1 parent 17a60cd commit 340312e
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/release-please/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{".":"17.16.0"}
{ ".": "17.16.0" }
5 changes: 3 additions & 2 deletions lib/rules/hashbang.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ function isNodeShebang(shebang, executableName) {
*/
function getExpectedExecutableName(context) {
const extension = path.extname(context.filename ?? context.getFilename())
/** @type {{ executableMap: Record<string, string> }} */
const { executableMap = {} } = context.options?.[0] ?? {}
const { executableMap = {} } =
/** @type {[{ executableMap: Record<string, string> }]} */
(context.options)?.[0] ?? {}

return executableMap[extension] ?? "node"
}
Expand Down
5 changes: 4 additions & 1 deletion lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [])
Expand Down
4 changes: 3 additions & 1 deletion lib/util/check-restricted.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 4 additions & 1 deletion lib/util/check-unsupported-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions lib/util/get-allow-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
)
}
Expand Down
14 changes: 10 additions & 4 deletions lib/util/get-configured-node-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>|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) {
Expand Down Expand Up @@ -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
)
Expand Down
12 changes: 8 additions & 4 deletions lib/util/get-convert-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
)
}
Expand Down
9 changes: 7 additions & 2 deletions lib/util/get-resolve-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
14 changes: 10 additions & 4 deletions lib/util/get-resolver-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
)
}
Expand Down
9 changes: 7 additions & 2 deletions lib/util/get-try-extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/util/get-typescript-extension-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
6 changes: 5 additions & 1 deletion lib/util/import-target.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 340312e

Please sign in to comment.