Skip to content

Commit

Permalink
Merge pull request #1908 from mightyiam/less-detailed-resolved
Browse files Browse the repository at this point in the history
chore: no check resolved rule options
  • Loading branch information
mightyiam authored Nov 19, 2024
2 parents 10dd099 + f6c39de commit 652d763
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/test/resolved-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ test('languageOptions', async (t) => {
})
})

test('rules', async (t) => {
test('rule levels', async (t) => {
// @ts-expect-error type seems wrong
const actual: TSESLint.FlatConfig.Config = await actualP
if (expectedExportedValue.rules === undefined) throw new Error()
const { rules } = expectedExportedValue
const normalized = Object.fromEntries(
Object.entries(rules).map(([name, value]) => {
if (value === undefined) throw new Error()
if (!Array.isArray(value)) throw new Error()
const [level, ...options] = value
if (typeof level === 'number') throw new Error()
enum Level {
error = 2,
warn = 1,
off = 0,
}
return [name, [Level[level], ...options]] as const
}),
)
t.deepEqual(actual.rules, normalized)
t.deepEqual(normalize(actual.rules), normalize(expectedExportedValue.rules))

function normalize(
rules?: TSESLint.SharedConfig.RulesRecord,
): Record<string, string> {
if (rules === undefined) throw new Error()
return Object.fromEntries(
Object.entries(rules).map(([name, value]) => {
if (value === undefined) throw new Error()
if (!Array.isArray(value)) throw new Error()
const [level] = value
return [
name,
typeof level === 'string'
? level
: { '0': 'off', '1': 'warn', '2': 'error' }[level],
]
}),
)
}
})

0 comments on commit 652d763

Please sign in to comment.