diff --git a/.changeset/odd-experts-protect.md b/.changeset/odd-experts-protect.md new file mode 100644 index 00000000..b1e5a2d9 --- /dev/null +++ b/.changeset/odd-experts-protect.md @@ -0,0 +1,5 @@ +--- +"@bfra.me/eslint-config": patch +--- + +Improve error handling. diff --git a/.changeset/strange-coins-bake.md b/.changeset/strange-coins-bake.md new file mode 100644 index 00000000..71822f15 --- /dev/null +++ b/.changeset/strange-coins-bake.md @@ -0,0 +1,6 @@ +--- +"@bfra.me/eslint-config": patch +--- + +Improve types. + \ No newline at end of file diff --git a/packages/eslint-config/src/package-utils.ts b/packages/eslint-config/src/package-utils.ts index abfaba98..9bd71500 100644 --- a/packages/eslint-config/src/package-utils.ts +++ b/packages/eslint-config/src/package-utils.ts @@ -78,8 +78,10 @@ function installPackageSync(packages: string | string[], options: {cwd: string; {cwd: options.cwd, maxBuffer: Infinity, stdio: 'inherit', windowsHide: true}, ) - if (result.error) { - throw result.error + if (result.error || result.status !== 0) { + const errorMessage = + result.error?.message || `Package installation failed with status ${result.status}` + throw new Error(errorMessage) } return `${result.output}` diff --git a/packages/eslint-config/src/rules/missing-module-for-config.ts b/packages/eslint-config/src/rules/missing-module-for-config.ts index 787b311a..0dcccb10 100644 --- a/packages/eslint-config/src/rules/missing-module-for-config.ts +++ b/packages/eslint-config/src/rules/missing-module-for-config.ts @@ -1,4 +1,4 @@ -import {Linter, type Rule} from 'eslint' +import {Linter, type Rule, type SourceCode} from 'eslint' import {getPackageInstallCommand, tryInstall} from '../package-utils' // Whether to install the missing module(s) for the config @@ -10,19 +10,19 @@ let shouldFix = false Object.defineProperty(Linter.prototype, 'verify', { configurable: true, value( - textOrSourceCode: unknown, - config: unknown, - options: undefined | {fix?: boolean}, - ...args: unknown[] + code: string | SourceCode, + config: Linter.Config, + options: Linter.LintOptions | {fix?: boolean} | undefined, + ...args: Parameters ) { - shouldFix = Boolean(options && options.fix !== undefined && options.fix) - return verify.call(this, textOrSourceCode, config, options, ...args) + shouldFix = typeof options === 'object' && options !== null && 'fix' in options && options.fix + return verify.call(this, code, config, options, ...args) }, writable: true, }) })() -export const meta = { +export const meta: Rule.RuleMetaData = { docs: { description: 'Missing module for config', url: 'https://github.com/bfra-me/works',