Skip to content

Commit

Permalink
chore(eslint-config): make minor improvements (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown authored Dec 27, 2024
1 parent c6017de commit ee96238
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-experts-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bfra.me/eslint-config": patch
---

Improve error handling.
6 changes: 6 additions & 0 deletions .changeset/strange-coins-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bfra.me/eslint-config": patch
---

Improve types.

6 changes: 4 additions & 2 deletions packages/eslint-config/src/package-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
16 changes: 8 additions & 8 deletions packages/eslint-config/src/rules/missing-module-for-config.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<typeof verify>
) {
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',
Expand Down

0 comments on commit ee96238

Please sign in to comment.