UNPKG

eslint-plugin-sonarjs

Version:
34 lines (33 loc) • 1.69 kB
/** * `node:test`'s built-in assertions, reached through the `TestContext` the runner passes to a test * callback: * * ```js * import test from 'node:test'; * test('t', t => { t.assert.equal(actual, expected); }); * ``` * * `TestContext.assert` (Node 22+) re-exposes the `node:assert` methods bound to the test, so * `t.assert.equal` fails the test exactly as `assert.equal` would. It is nonetheless invisible to * the `node:assert` detectors: the file imports `node:test`, never `node:assert`, and the receiver * is a callback parameter rather than a module binding. */ import type { Rule } from 'eslint'; import type estree from 'estree'; import type { ParserServicesWithTypeInformation } from '@typescript-eslint/utils'; import ts from 'typescript'; /** * Whether `node` is a `<context>.assert.<method>(...)` call whose receiver is the context parameter * of an enclosing `node:test` callback. Pure-AST: does not require type information. */ export declare function isAssertion(context: Rule.RuleContext, node: estree.Node): boolean; /** * Counterpart of {@link isAssertion} for the type-aware visitor, which walks TypeScript nodes and * never reaches the ESTree detector above. * * Deliberately structural rather than type-based: `TestContext` only resolves when `@types/node` is * part of the program, and the context parameter is plain `any` when it is not — including in this * repository's own type-aware rule tests. Matching the shape keeps the two paths in agreement * instead of making recognition depend on whether types happen to be installed. */ export declare function isTSAssertion(services: ParserServicesWithTypeInformation, node: ts.Node): boolean;