Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(experimental-utils): use mergable interface for settings property #3556

Merged
merged 1 commit into from Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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