import type { ReadonlyRecord } from 'ts-type-forge'; import { tsFortressRules } from './rules/index.mjs'; import type { ESLintFlatConfig, ESLintPlugin } from './types.mjs'; /** * Every rule this plugin ships, at `error`. * * The `satisfies` clause below is keyed off {@link tsFortressRules}, so leaving * a rule out, naming one that does not exist, or setting one to anything but * `error` fails to type-check. That is the whole check; no test repeats it. */ const recommendedRules = { 'ts-fortress/no-type-only-codec': 'error', 'ts-fortress/prefer-canonical-length-constrained-type': 'error', 'ts-fortress/prefer-namespace-import': 'error', 'ts-fortress/prefer-schema-over-guard-chain': 'error', } as const satisfies ReadonlyRecord< `ts-fortress/${keyof typeof tsFortressRules}`, 'error' >; const recommendedConfig = { name: 'ts-fortress/recommended', plugins: { // Resolved lazily so that this config registers the *same* object that // `eslintPluginTsFortress` refers to. ESLint rejects a plugin name that // maps to two different objects with `Cannot redefine plugin`, which is // what a user combining this preset with their own // `plugins: { 'ts-fortress': eslintPluginTsFortress }` entry would hit if // the preset embedded a separate copy of the plugin. get 'ts-fortress'(): ESLintPlugin { return eslintPluginTsFortress; }, }, rules: recommendedRules, } as const satisfies ESLintFlatConfig; export const eslintPluginTsFortress = { meta: { name: 'eslint-plugin-ts-fortress', }, rules: tsFortressRules, configs: { /** Enables every rule of this plugin at `error`. */ recommended: recommendedConfig, }, } as const satisfies ESLintPlugin;