Skip to content

feat(utils): add defaults for RuleContext type parameters #8148

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions packages/utils/src/eslint-utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,17 @@ import type { Scope, SourceCode } from '../ts-eslint';
import type { RuleContext } from '../ts-eslint/Rule';
import type { TSESTree } from '../ts-estree';

export function getAncestors(
context: Readonly<RuleContext<string, unknown[]>>,
): TSESTree.Node[] {
export function getAncestors(context: Readonly<RuleContext>): TSESTree.Node[] {
// TODO: Use `SourceCode#getAncestors` (we'll be forced to soon)
return context.getAncestors();
}

export function getCwd(
context: Readonly<RuleContext<string, unknown[]>>,
): string {
export function getCwd(context: Readonly<RuleContext>): string {
return context.cwd ?? context.getCwd();
}

export function getDeclaredVariables(
context: Readonly<RuleContext<string, unknown[]>>,
context: Readonly<RuleContext>,
node: TSESTree.Node,
): readonly Scope.Variable[] {
const sourceCode = getSourceCode(context);
Expand All @@ -29,9 +25,7 @@ export function getDeclaredVariables(
);
}

export function getFilename(
context: Readonly<RuleContext<string, unknown[]>>,
): string {
export function getFilename(context: Readonly<RuleContext>): string {
return context.filename ?? context.getFilename();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/utils/src/eslint-utils/getParserServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function getParserServices<
): ParserServices;

function getParserServices(
context: Readonly<TSESLint.RuleContext<string, unknown[]>>,
context: Readonly<TSESLint.RuleContext>,
allowWithoutFullTypeInformation = false,
): ParserServices {
// This check is unnecessary if the user is using the latest version of our parser.
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/ts-eslint/Rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ type ReportDescriptor<TMessageIds extends string> =
type SharedConfigurationSettings = Record<string, unknown>;

interface RuleContext<
TMessageIds extends string,
TOptions extends readonly unknown[],
TMessageIds extends string = string,
TOptions extends readonly unknown[] = unknown[],
> {
/**
* The rule ID.
Expand Down