From 62f5f0c291d549d1893601cf5effbd4fdf911358 Mon Sep 17 00:00:00 2001 From: Francesco Trotta Date: Mon, 10 Feb 2025 10:16:03 +0100 Subject: [PATCH] fix: fix `RuleContext` type --- lib/types/index.d.ts | 8 ++++++-- tests/lib/types/types.test.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 4fe2f80131a1..d7634a1d6ae6 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -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"; @@ -800,7 +801,10 @@ export namespace Rule { hasSuggestions?: boolean | undefined; } - interface RuleContext extends CoreRuleContext { + interface RuleContext extends CoreRuleContext { // report(descriptor: ReportDescriptor): void; } diff --git a/tests/lib/types/types.test.ts b/tests/lib/types/types.test.ts index fdb2f1a21b94..eba7cb8c58d2 100644 --- a/tests/lib/types/types.test.ts +++ b/tests/lib/types/types.test.ts @@ -436,7 +436,7 @@ rule = { }; rule = { - create(context) { + create(context: Rule.RuleContext) { context.getAncestors(); context.getDeclaredVariables(AST); @@ -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(); @@ -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" } }); 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