Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit abfc19b

Browse files
authored
feat(experimental-utils): use mergable interface for settings property (typescript-eslint#3556)
1 parent ac86a79 commit abfc19b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

packages/experimental-utils/src/ts-eslint/Linter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import { Linter as ESLintLinter } from 'eslint';
44
import { TSESTree, ParserServices } from '../ts-estree';
55
import { ParserOptions as TSParserOptions } from './ParserOptions';
6-
import { RuleCreateFunction, RuleFix, RuleModule } from './Rule';
6+
import {
7+
RuleCreateFunction,
8+
RuleFix,
9+
RuleModule,
10+
SharedConfigurationSettings,
11+
} from './Rule';
712
import { Scope } from './Scope';
813
import { SourceCode } from './SourceCode';
914

@@ -164,7 +169,7 @@ namespace Linter {
164169
/**
165170
* The shared settings.
166171
*/
167-
settings?: { [name: string]: unknown };
172+
settings?: SharedConfigurationSettings;
168173
}
169174

170175
export interface ConfigOverride extends BaseConfig {

packages/experimental-utils/src/ts-eslint/Rule.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ type ReportDescriptor<TMessageIds extends string> =
165165
ReportDescriptorWithSuggestion<TMessageIds> &
166166
(ReportDescriptorNodeOptionalLoc | ReportDescriptorLocOnly);
167167

168+
/**
169+
* Plugins can add their settings using declaration
170+
* merging against this interface.
171+
*/
172+
interface SharedConfigurationSettings {
173+
[name: string]: unknown;
174+
}
175+
168176
interface RuleContext<
169177
TMessageIds extends string,
170178
TOptions extends readonly unknown[],
@@ -194,7 +202,7 @@ interface RuleContext<
194202
* The shared settings from configuration.
195203
* We do not have any shared settings in this plugin.
196204
*/
197-
settings: Record<string, unknown>;
205+
settings: SharedConfigurationSettings;
198206

199207
/**
200208
* Returns an array of the ancestors of the currently-traversed node, starting at
@@ -452,4 +460,5 @@ export {
452460
RuleMetaData,
453461
RuleMetaDataDocs,
454462
RuleModule,
463+
SharedConfigurationSettings,
455464
};

packages/experimental-utils/src/ts-eslint/RuleTester.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import { RuleTester as ESLintRuleTester } from 'eslint';
22
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '../ts-estree';
33
import { ParserOptions } from './ParserOptions';
44
import { Linter } from './Linter';
5-
import { RuleCreateFunction, RuleModule } from './Rule';
5+
import {
6+
RuleCreateFunction,
7+
RuleModule,
8+
SharedConfigurationSettings,
9+
} from './Rule';
610

711
interface ValidTestCase<TOptions extends Readonly<unknown[]>> {
812
/**
@@ -36,7 +40,7 @@ interface ValidTestCase<TOptions extends Readonly<unknown[]>> {
3640
/**
3741
* Settings for the test case.
3842
*/
39-
readonly settings?: Readonly<Record<string, unknown>>;
43+
readonly settings?: Readonly<SharedConfigurationSettings>;
4044
/**
4145
* Run this case exclusively for debugging in supported test frameworks.
4246
*/

0 commit comments

Comments
 (0)