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

fix: fix RuleContext type #19417

Merged
merged 1 commit into from
Feb 11, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import type {
TraversalStep,
LanguageOptions as GenericLanguageOptions,
RuleDefinition,
RuleContext as CoreRuleContext
RuleContext as CoreRuleContext,
RuleContextTypeOptions
} from "@eslint/core";
import { JSONSchema4 } from "json-schema";
import { LegacyESLint } from "./use-at-your-own-risk.js";
Expand Down Expand Up @@ -800,7 +801,10 @@ export namespace Rule {
hasSuggestions?: boolean | undefined;
}

interface RuleContext extends CoreRuleContext {
interface RuleContext extends CoreRuleContext<RuleContextTypeOptions & {
LangOptions: Linter.LanguageOptions;
Code: SourceCode;
Node: ESTree.Node; }> {
// report(descriptor: ReportDescriptor): void;
}

Expand Down
10 changes: 9 additions & 1 deletion tests/lib/types/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ rule = {
};

rule = {
create(context) {
create(context: Rule.RuleContext) {
context.getAncestors();

context.getDeclaredVariables(AST);
Expand All @@ -453,9 +453,14 @@ rule = {

context.getCwd();

context.languageOptions;
context.languageOptions.ecmaVersion satisfies Linter.LanguageOptions["ecmaVersion"];

context.sourceCode;
context.sourceCode.getLocFromIndex(42);

context.getSourceCode();
context.getSourceCode().getLocFromIndex(42);

context.getScope();

Expand All @@ -467,6 +472,9 @@ rule = {

context.markVariableAsUsed("foo");

// @ts-expect-error wrong `node` type
context.report({ message: "foo", node: {} });

context.report({ message: "foo", node: AST });
context.report({ message: "foo", loc: { start: {line: 0, column: 0}, end: { line: 1, column: 1 } } });
context.report({ message: "foo", node: AST, data: { foo: "bar" } });
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy