diff --git a/src/index.ts b/src/index.ts index c8d887e..e202374 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,6 +70,25 @@ export default function createConfig({ }) } + // More meaningful error message for the user, in case they didn't know the correct config name. + for (const name of configNamesToExtend) { + if (!tseslint.configs[name]) { + const nameInCamelCase = name.replace(/-([a-z])/g, (_, letter) => + letter.toUpperCase(), + ) + + // @ts-expect-error + if (tseslint.configs[nameInCamelCase]) { + throw new Error( + `The config name "${name}" is not supported in "extends". ` + + `Please use "${nameInCamelCase}" instead.`, + ) + } + + throw new Error(`Unknown config name in "extends": ${name}.`) + } + } + const mayHaveJsxInSfc = supportedScriptLangs.jsx || supportedScriptLangs.tsx const needsTypeAwareLinting = configNamesToExtend.some( name => diff --git a/test/index.spec.ts b/test/index.spec.ts index babf340..86fe549 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -191,3 +191,14 @@ test('#87: should not error if the project root has an older version of espree i const { stdout } = await runLintAgainst('with-older-espree', FROM_FIXTURES) expect(stdout).toMatch(WHITESPACE_ONLY) }) + +test('should guide user to use camelCase names in "extends"', async () => { + const eslintConfigPath = path.join(__dirname, '../examples/type-checked/eslint.config.js') + const { modify, restore } = setupFileMutations(eslintConfigPath) + modify((oldContents) => oldContents.replace('recommendedTypeChecked', 'recommended-type-checked')) + const { failed, stderr } = await runLintAgainst('type-checked') + restore() + + expect(failed).toBe(true) + expect(stderr).contain('Please use "recommendedTypeChecked"') +})