Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 0fa7ab3

Browse files
authored
feat: types export, close #19 (#21)
1 parent 72fefea commit 0fa7ab3

File tree

19 files changed

+2719
-2659
lines changed

19 files changed

+2719
-2659
lines changed

scripts/generate-plugin-dts.ts

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,12 @@ export type ${pascalCase(ruleName)}RuleOptions = ${ruleOptionTypeValue};
124124

125125
const documentation: Rule.RuleMetaData['docs'] = meta.docs ?? {};
126126

127-
ruleDeclarations.push(`/**
128-
* ${documentation.description}
129-
*
130-
* @see [${ruleName}](${documentation.url})
131-
*/
132-
"${pluginPrefix}/${ruleName}": ${pascalCase(ruleName)}RuleOptions;`);
127+
ruleDeclarations.push(` /**
128+
* ${documentation.description}
129+
*
130+
* @see [${ruleName}](${documentation.url})
131+
*/
132+
"${pluginPrefix}/${ruleName}": ${pascalCase(ruleName)}RuleOptions;`);
133133
}
134134

135135
const hasPluginParsers = await stat(join(workspaceDirectory, 'parsers.d.ts'))
@@ -149,44 +149,54 @@ export type ${pascalCase(ruleName)}RuleOptions = ${ruleOptionTypeValue};
149149
.catch(() => false);
150150

151151
await writeFile(
152-
join(workspaceDirectory, 'index.d.ts'),
152+
join(workspaceDirectory, 'types.d.ts'),
153153
`${ruleOptionImports.join('\n')}
154-
${hasPluginParsers ? `import type { Parsers } "./parsers";` : ''}${
154+
${hasPluginParsers ? `export type { Parsers } "./parsers";` : ''}${
155155
hasPluginParserOptions
156-
? `import type { ParserOptions } "./parser-options";`
156+
? `export type { ParserOptions } "./parser-options";`
157157
: ''
158-
}${hasPluginSettings ? `import type { Settings } "./settings";` : ''}
158+
}${hasPluginSettings ? `export type { Settings } "./settings";` : ''}
159159
160-
declare module "eslint-define-config" {
161-
export interface CustomExtends {
162-
${pluginConfigs
163-
.map((config) => `"plugin:${pluginPrefix}/${config}": void;`)
164-
.join('\n')}
165-
}
160+
export interface Extends {
161+
${pluginConfigs
162+
.map((config) => `"plugin:${pluginPrefix}/${config}": void;`)
163+
.join('\n')}
164+
}
166165
167-
export interface CustomPlugins {
168-
"${pluginPrefix}": void;
169-
}
166+
export interface Plugins {
167+
"${pluginPrefix}": void;
168+
}
170169
171-
export interface CustomRuleOptions {
172-
${ruleDeclarations.join('\n')}
173-
}
170+
export interface RuleOptions {
171+
${ruleDeclarations.join('\n')}
172+
}
173+
`,
174+
{
175+
encoding: 'utf8',
176+
flag: 'w',
177+
},
178+
);
174179

175-
${
176-
hasPluginParsers ? 'export interface CustomParsers extends Parsers {};' : ''
177-
}
180+
const imports = [
181+
'Extends',
182+
'Plugins',
183+
'RuleOptions',
184+
hasPluginParsers ? 'Parsers' : '',
185+
hasPluginParserOptions ? 'ParserOptions' : '',
186+
hasPluginSettings ? 'Settings' : '',
187+
].filter(Boolean);
178188

179-
${
180-
hasPluginParserOptions
181-
? 'export interface CustomParserOptions extends ParserOptions {};'
182-
: ''
183-
}
189+
await writeFile(
190+
join(workspaceDirectory, 'index.d.ts'),
191+
`import type { ${imports.join(', ')} } from "./types";
184192
185-
${
186-
hasPluginSettings
187-
? 'export interface CustomSettings extends Settings {};'
188-
: ''
189-
}
193+
declare module 'eslint-define-config' {
194+
${imports
195+
.map(
196+
(importName) =>
197+
` export interface Custom${importName} extends ${importName} {}`,
198+
)
199+
.join('\n')}
190200
}
191201
`,
192202
{

types/deprecation/index.d.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
import type { DeprecationRuleOptions } from './rules/deprecation';
1+
import type { Extends, Plugins, RuleOptions } from './types';
22

33
declare module 'eslint-define-config' {
4-
export interface CustomExtends {
5-
'plugin:deprecation/recommended': void;
6-
}
7-
8-
export interface CustomPlugins {
9-
deprecation: void;
10-
}
11-
12-
export interface CustomRuleOptions {
13-
/**
14-
* Do not use deprecated APIs.
15-
*
16-
* @see [deprecation](https://github.com/gund/eslint-plugin-deprecation)
17-
*/
18-
'deprecation/deprecation': DeprecationRuleOptions;
19-
}
4+
export interface CustomExtends extends Extends {}
5+
export interface CustomPlugins extends Plugins {}
6+
export interface CustomRuleOptions extends RuleOptions {}
207
}

types/deprecation/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
".": {
2828
"types": "./index.d.ts"
2929
},
30+
"./types": {
31+
"types": "./types.d.ts"
32+
},
3033
"./package.json": "./package.json"
3134
}
3235
}

types/deprecation/types.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { DeprecationRuleOptions } from './rules/deprecation';
2+
3+
export interface Extends {
4+
'plugin:deprecation/recommended': void;
5+
}
6+
7+
export interface Plugins {
8+
deprecation: void;
9+
}
10+
11+
export interface RuleOptions {
12+
/**
13+
* Do not use deprecated APIs.
14+
*
15+
* @see [deprecation](https://github.com/gund/eslint-plugin-deprecation)
16+
*/
17+
'deprecation/deprecation': DeprecationRuleOptions;
18+
}

0 commit comments

Comments
 (0)