Skip to content

Commit

Permalink
feat(eslint-config): update configs and improve type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
marcusrbrown committed Nov 3, 2024
1 parent becab16 commit 8af0af9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-dolls-confess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bfra.me/eslint-config": patch
---

Add epilogue override for sources of CLIs.
6 changes: 6 additions & 0 deletions .changeset/strange-windows-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@bfra.me/eslint-config": patch
---

Add missing config names for TypeScript typed linting.

2 changes: 1 addition & 1 deletion packages/eslint-config/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {composeConfig} from './src'
import {composeConfig} from './src/compose-config'
import config from '../../eslint.config'

export default composeConfig(
Expand Down
8 changes: 5 additions & 3 deletions packages/eslint-config/scripts/generate-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ const configs = await composer(
rules: Object.fromEntries(builtinRules),
},
},
typescript: {
tsconfigPath: 'tsconfig.json',
},
vitest: true,
}),
// TODO: The `vitest/valid-title` rule breaks the generated types if saved as a .ts instead of a .d.ts file.
Expand All @@ -28,8 +31,6 @@ const configs = await composer(

const rulesTypeName = 'Rules'
const configNames = configs.map(config => config.name).filter(Boolean) as string[]
const configNamesDts =
configNames.length > 0 ? `${configNames.map(name => `'${name}'`).join(' | ')}` : 'never'
const configType = `Linter.Config<Linter.RulesRecord & ${rulesTypeName}>`

let dts = await flatConfigsToRulesDTS(configs, {
Expand Down Expand Up @@ -64,7 +65,8 @@ export type Config = ${configType}
*/
export type FlatConfigComposer<
Config extends Linter.Config = ${configType},
ConfigNames extends string = ${configNamesDts} | (string & Record<never, never>)
ConfigNames extends string =
${configNames.length > 0 ? `${configNames.map(name => `'${name}'`).join(' |\n ')}` : 'never'}
> = FCUTypes.FlatConfigComposer<Config, ConfigNames>
/**
Expand Down
30 changes: 20 additions & 10 deletions packages/eslint-config/src/configs/epilogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import {GLOB_SRC, GLOB_SRC_EXT} from '../globs'
import type {Config} from '../types'

export async function epilogue(): Promise<Config[]> {
// @keep-sorted {"keys":["name"]}
return [
{
name: '@bfra.me/epilogue/commonjs',
files: ['**/*.js', '**/*.cjs'],
name: '@bfra.me/epilogue/cli',
files: [`**/cli/${GLOB_SRC}`, `**/cli.${GLOB_SRC_EXT}`],
rules: {
'@typescript-eslint/no-require-imports': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'no-console': 'off',
},
},
{
Expand All @@ -19,6 +19,21 @@ export async function epilogue(): Promise<Config[]> {
'no-console': 'off',
},
},
{
name: '@bfra.me/epilogue/scripts',
files: [`**/scripts/${GLOB_SRC}`],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'no-console': 'off',
},
},
{
name: '@bfra.me/epilogue/commonjs',
files: ['**/*.js', '**/*.cjs'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
{
name: '@bfra.me/epilogue/dts',
files: ['**/*.d.?([cm])ts'],
Expand All @@ -30,12 +45,7 @@ export async function epilogue(): Promise<Config[]> {
},
},
{
name: '@bfra.me/epilogue/scripts',
files: [`**/scripts/${GLOB_SRC}`],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'no-console': 'off',
},
name: '@bfra.me/epilogue',
},
]
}

0 comments on commit 8af0af9

Please sign in to comment.