Skip to content

Commit 340312e

Browse files
authored
fix: patch new eslint options types (#411)
1 parent 17a60cd commit 340312e

13 files changed

+76
-29
lines changed

.github/release-please/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{".":"17.16.0"}
1+
{ ".": "17.16.0" }

lib/rules/hashbang.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ function isNodeShebang(shebang, executableName) {
5252
*/
5353
function getExpectedExecutableName(context) {
5454
const extension = path.extname(context.filename ?? context.getFilename())
55-
/** @type {{ executableMap: Record<string, string> }} */
56-
const { executableMap = {} } = context.options?.[0] ?? {}
55+
const { executableMap = {} } =
56+
/** @type {[{ executableMap: Record<string, string> }]} */
57+
(context.options)?.[0] ?? {}
5758

5859
return executableMap[extension] ?? "node"
5960
}

lib/rules/no-deprecated-api.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,10 @@ function toName(type, path) {
738738
* @returns {ParsedOptions} Parsed options
739739
*/
740740
function parseOptions(context) {
741-
const raw = context.options[0] || {}
741+
const raw = /** @type {{
742+
ignoreModuleItems?: string[];
743+
ignoreGlobalItems?: string[];
744+
}} */ (context.options[0] || {})
742745
const version = getConfiguredNodeVersion(context)
743746
const ignoredModuleItems = new Set(raw.ignoreModuleItems || [])
744747
const ignoredGlobalItems = new Set(raw.ignoreGlobalItems || [])

lib/util/check-restricted.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ function createRestrictions(defs) {
9696
* @returns {void}
9797
*/
9898
exports.checkForRestriction = function checkForRestriction(context, targets) {
99-
const restrictions = createRestrictions(context.options[0])
99+
const restrictions = createRestrictions(
100+
/** @type {string[]} */ (context.options[0])
101+
)
100102

101103
for (const target of targets) {
102104
const restriction = restrictions.find(r => r.match(target))

lib/util/check-unsupported-builtins.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ const { getScope } = require("../util/eslint-compat")
2222
* }>} Parsed value.
2323
*/
2424
function parseOptions(context) {
25-
const raw = context.options[0] || {}
25+
const raw = /** @type {{
26+
* ignores?: string[];
27+
* allowExperimental?: boolean;
28+
* }} */ (context.options[0] || {})
2629
const version = getConfiguredNodeVersion(context)
2730
const ignores = new Set(raw.ignores || [])
2831
const allowExperimental = raw.allowExperimental ?? false

lib/util/get-allow-modules.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
*/
1010
const DEFAULT_VALUE = []
1111

12+
/**
13+
* @typedef {{allowModules:? string[]}|undefined} Option
14+
*/
15+
1216
/**
1317
* Gets `allowModules` property from a given option object.
1418
*
15-
* @param {{allowModules:? string[]}|undefined} option - An option object to get.
19+
* @param {Option} option - An option object to get.
1620
* @returns {string[]|null} The `allowModules` value, or `null`.
1721
*/
1822
function get(option) {
@@ -34,9 +38,9 @@ function get(option) {
3438
*/
3539
module.exports = function getAllowModules(context) {
3640
return (
37-
get(context.options[0]) ??
38-
get(context.settings?.n) ??
39-
get(context.settings?.node) ??
41+
get(/** @type {Option} */ (context.options[0])) ??
42+
get(/** @type {Option} */ (context.settings?.n)) ??
43+
get(/** @type {Option} */ (context.settings?.node)) ??
4044
DEFAULT_VALUE
4145
)
4246
}

lib/util/get-configured-node-version.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ const getSemverRange = require("./get-semver-range")
1010

1111
const fallbackRange = new Range(">=16.0.0")
1212

13+
/**
14+
* @typedef {{ version:? string } | undefined} VersionOption
15+
*/
16+
1317
/**
1418
* Gets `version` property from a given option object.
1519
*
16-
* @param {Record<string, string>|undefined} option - An option object to get.
20+
* @param {VersionOption} option - An option object to get.
1721
* @returns {import("semver").Range|undefined} The `allowModules` value, or `null`.
1822
*/
1923
function getVersionRange(option) {
@@ -55,9 +59,11 @@ function getEnginesNode(context) {
5559
*/
5660
module.exports = function getConfiguredNodeVersion(context) {
5761
return (
58-
getVersionRange(context.options?.[0]) ??
59-
getVersionRange(context.settings?.n) ??
60-
getVersionRange(context.settings?.node) ??
62+
getVersionRange(/** @type {VersionOption} */ (context.options?.[0])) ??
63+
getVersionRange(/** @type {VersionOption} */ (context.settings?.n)) ??
64+
getVersionRange(
65+
/** @type {VersionOption} */ (context.settings?.node)
66+
) ??
6167
getEnginesNode(context) ??
6268
fallbackRange
6369
)

lib/util/get-convert-path.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,14 @@ function combine(converters) {
111111
}
112112
}
113113

114+
/**
115+
* @typedef {{ convertPath?: ConvertPath } | undefined} ConvertPathOption
116+
*/
117+
114118
/**
115119
* Parses `convertPath` property from a given option object.
116120
*
117-
* @param {{convertPath?: ConvertPath}|undefined} option - An option object to get.
121+
* @param {ConvertPathOption} option - An option object to get.
118122
* @returns {Converter['convert']|null} A function which converts a path., or `null`.
119123
*/
120124
function parse(option) {
@@ -148,9 +152,9 @@ function parse(option) {
148152
*/
149153
module.exports = function getConvertPath(context) {
150154
return (
151-
parse(context.options?.[0]) ??
152-
parse(context.settings?.n) ??
153-
parse(context.settings?.node) ??
155+
parse(/** @type {ConvertPathOption} */ (context.options?.[0])) ??
156+
parse(/** @type {ConvertPathOption} */ (context.settings?.n)) ??
157+
parse(/** @type {ConvertPathOption} */ (context.settings?.node)) ??
154158
identity
155159
)
156160
}

lib/util/get-resolve-paths.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ const DEFAULT_VALUE = []
1010
/**
1111
* Gets `resolvePaths` property from a given option object.
1212
*
13-
* @param {{ resolvePaths: unknown[] } | undefined} option - An option object to get.
13+
* @param {unknown} option - An option object to get.
1414
* @returns {string[] | undefined} The `allowModules` value, or `null`.
1515
*/
1616
function get(option) {
17-
if (Array.isArray(option?.resolvePaths)) {
17+
if (
18+
option != null &&
19+
typeof option === "object" &&
20+
"resolvePaths" in option &&
21+
Array.isArray(option?.resolvePaths)
22+
) {
1823
return option.resolvePaths.map(String)
1924
}
2025
}

lib/util/get-resolver-config.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111
/** @type {ResolverConfig} */
1212
const DEFAULT_VALUE = {}
1313

14+
/**
15+
* @typedef {{ resolverConfig?: ResolverConfig } | undefined} ResolverConfigOption
16+
*/
17+
1418
/**
1519
* Gets `resolverConfig` property from a given option object.
1620
*
17-
* @param {{ resolverConfig: ResolverConfig } | undefined} option - An option object to get.
21+
* @param {ResolverConfigOption} option - An option object to get.
1822
* @returns {ResolverConfig | undefined} The `allowModules` value, or `null`.
1923
*/
2024
function get(option) {
@@ -33,9 +37,11 @@ function get(option) {
3337
*/
3438
module.exports = function getResolverConfig(context, optionIndex = 0) {
3539
return (
36-
get(context.options?.[optionIndex]) ??
37-
get(context.settings?.n) ??
38-
get(context.settings?.node) ??
40+
get(
41+
/** @type {ResolverConfigOption} */ (context.options?.[optionIndex])
42+
) ??
43+
get(/** @type {ResolverConfigOption} */ (context.settings?.n)) ??
44+
get(/** @type {ResolverConfigOption} */ (context.settings?.node)) ??
3945
DEFAULT_VALUE
4046
)
4147
}

lib/util/get-try-extensions.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,16 @@ const DEFAULT_TS_VALUE = [
2424
/**
2525
* Gets `tryExtensions` property from a given option object.
2626
*
27-
* @param {{ tryExtensions: unknown[] } | undefined} option - An option object to get.
27+
* @param {unknown} option - An option object to get.
2828
* @returns {string[] | undefined} The `tryExtensions` value, or `null`.
2929
*/
3030
function get(option) {
31-
if (Array.isArray(option?.tryExtensions)) {
31+
if (
32+
option != null &&
33+
typeof option === "object" &&
34+
"tryExtensions" in option &&
35+
Array.isArray(option?.tryExtensions)
36+
) {
3237
return option.tryExtensions.map(String)
3338
}
3439
}

lib/util/get-typescript-extension-map.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,12 @@ function getFromTSConfigFromFile(context) {
129129
*/
130130
module.exports = function getTypescriptExtensionMap(context) {
131131
return (
132-
get(context.options?.[0]) ||
133-
get(context.settings?.n ?? context.settings?.node) ||
132+
get(/** @type {Options} */ (context.options?.[0])) ||
133+
get(
134+
/** @type {Options} */ (
135+
context.settings?.n ?? context.settings?.node
136+
)
137+
) ||
134138
getFromTSConfigFromFile(context) ||
135139
PRESERVE_MAPPING
136140
)

lib/util/import-target.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,11 @@ module.exports = class ImportTarget {
345345

346346
const requireResolve = resolver.create.sync(this.resolverConfig)
347347

348-
const cwd = this.context.settings?.cwd ?? process.cwd()
348+
const cwd =
349+
typeof this.context.settings?.cwd === "string"
350+
? this.context.settings?.cwd
351+
: process.cwd()
352+
349353
for (const directory of this.getPaths()) {
350354
const baseDir = resolve(cwd, directory)
351355

0 commit comments

Comments
 (0)