Skip to content

Commit

Permalink
refactor: improve generation of type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
azat-io committed Jul 20, 2024
1 parent ba31478 commit 563ba49
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { Linter, ESLint } from 'eslint'
import type {
ClassicConfig,
FlatConfig,
} from '@typescript-eslint/utils/ts-eslint'

import sortIntersectionTypes from './rules/sort-intersection-types'
import sortSvelteAttributes from './rules/sort-svelte-attributes'
Expand Down Expand Up @@ -52,24 +55,24 @@ let plugin = {
'sort-maps': sortMaps,
},
name,
} as unknown as ESLint.Plugin
}

let getRules = (options: BaseOptions): Record<string, RuleDeclaration> =>
Object.fromEntries(
Object.keys(plugin.rules!).map(rule => [
Object.keys(plugin.rules).map(rule => [
`${name}/${rule}`,
['error', options],
]),
)

let createConfig = (options: BaseOptions): Linter.FlatConfig => ({
let createConfig = (options: BaseOptions): FlatConfig.Config => ({
plugins: {
[name]: plugin,
},
rules: getRules(options),
})

let createLegacyConfig = (options: BaseOptions): Linter.Config => ({
let createLegacyConfig = (options: BaseOptions): ClassicConfig.Config => ({
rules: getRules(options),
plugins: [name],
})
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"target": "esnext",
"types": ["node"],
"allowJs": true,
"baseUrl": ".",
"strict": true,
"noEmit": true
}
Expand Down

0 comments on commit 563ba49

Please sign in to comment.