Skip to content

Commit

Permalink
feat(experimental-utils): use mergable interface for settings prope…
Browse files Browse the repository at this point in the history
…rty (#3556)
  • Loading branch information
G-Rath committed Jun 20, 2021
1 parent ac86a79 commit abfc19b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
9 changes: 7 additions & 2 deletions packages/experimental-utils/src/ts-eslint/Linter.ts
Expand Up @@ -3,7 +3,12 @@
import { Linter as ESLintLinter } from 'eslint';
import { TSESTree, ParserServices } from '../ts-estree';
import { ParserOptions as TSParserOptions } from './ParserOptions';
import { RuleCreateFunction, RuleFix, RuleModule } from './Rule';
import {
RuleCreateFunction,
RuleFix,
RuleModule,
SharedConfigurationSettings,
} from './Rule';
import { Scope } from './Scope';
import { SourceCode } from './SourceCode';

Expand Down Expand Up @@ -164,7 +169,7 @@ namespace Linter {
/**
* The shared settings.
*/
settings?: { [name: string]: unknown };
settings?: SharedConfigurationSettings;
}

export interface ConfigOverride extends BaseConfig {
Expand Down
11 changes: 10 additions & 1 deletion packages/experimental-utils/src/ts-eslint/Rule.ts
Expand Up @@ -165,6 +165,14 @@ type ReportDescriptor<TMessageIds extends string> =
ReportDescriptorWithSuggestion<TMessageIds> &
(ReportDescriptorNodeOptionalLoc | ReportDescriptorLocOnly);

/**
* Plugins can add their settings using declaration
* merging against this interface.
*/
interface SharedConfigurationSettings {
[name: string]: unknown;
}

interface RuleContext<
TMessageIds extends string,
TOptions extends readonly unknown[],
Expand Down Expand Up @@ -194,7 +202,7 @@ interface RuleContext<
* The shared settings from configuration.
* We do not have any shared settings in this plugin.
*/
settings: Record<string, unknown>;
settings: SharedConfigurationSettings;

/**
* Returns an array of the ancestors of the currently-traversed node, starting at
Expand Down Expand Up @@ -452,4 +460,5 @@ export {
RuleMetaData,
RuleMetaDataDocs,
RuleModule,
SharedConfigurationSettings,
};
8 changes: 6 additions & 2 deletions packages/experimental-utils/src/ts-eslint/RuleTester.ts
Expand Up @@ -2,7 +2,11 @@ import { RuleTester as ESLintRuleTester } from 'eslint';
import { AST_NODE_TYPES, AST_TOKEN_TYPES } from '../ts-estree';
import { ParserOptions } from './ParserOptions';
import { Linter } from './Linter';
import { RuleCreateFunction, RuleModule } from './Rule';
import {
RuleCreateFunction,
RuleModule,
SharedConfigurationSettings,
} from './Rule';

interface ValidTestCase<TOptions extends Readonly<unknown[]>> {
/**
Expand Down Expand Up @@ -36,7 +40,7 @@ interface ValidTestCase<TOptions extends Readonly<unknown[]>> {
/**
* Settings for the test case.
*/
readonly settings?: Readonly<Record<string, unknown>>;
readonly settings?: Readonly<SharedConfigurationSettings>;
/**
* Run this case exclusively for debugging in supported test frameworks.
*/
Expand Down

0 comments on commit abfc19b

Please sign in to comment.