Skip to content
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
3 changes: 2 additions & 1 deletion apps/oxlint/conformance/src/rule_tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ function addBeforeHook<T extends TestCase>(test: T): T {
const clonedTest = { ...test };

if (Object.hasOwn(test, "before")) {
const originalBefore = test.before;
// oxlint-disable-next-line typescript/unbound-method - called with `.call`
const originalBefore = test.before as () => void;
test.before = function (this) {
setCurrentTest(clonedTest);
originalBefore!.call(this);
Expand Down
16 changes: 8 additions & 8 deletions apps/oxlint/src-js/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ let loadJsConfigs: typeof import("./js_config.ts").loadJsConfigs | null = null;
*/
function loadPluginWrapper(
path: string,
pluginName: string | null,
pluginName: string | null | undefined,
pluginNameIsAlias: boolean,
workspaceUri: string | null,
workspaceUri: string | null | undefined,
): Promise<string> {
if (loadPlugin === null) {
// Use promises here instead of making `loadPluginWrapper` an async function,
// to avoid a micro-tick and extra wrapper `Promise` in all later calls to `loadPluginWrapper`
return import("./plugins/index.ts").then((mod) => {
({ loadPlugin, lintFile, setupRuleConfigs } = mod);
return loadPlugin(path, pluginName, pluginNameIsAlias, workspaceUri);
return loadPlugin(path, pluginName ?? null, pluginNameIsAlias, workspaceUri ?? null);
});
}
return loadPlugin(path, pluginName, pluginNameIsAlias, workspaceUri);
return loadPlugin(path, pluginName ?? null, pluginNameIsAlias, workspaceUri ?? null);
}

/**
Expand Down Expand Up @@ -71,25 +71,25 @@ function setupRuleConfigsWrapper(optionsJSON: string): string | null {
function lintFileWrapper(
filePath: string,
bufferId: number,
buffer: Uint8Array | null,
buffer: Uint8Array | null | undefined,
ruleIds: number[],
optionsIds: number[],
settingsJSON: string,
globalsJSON: string,
workspaceUri: string | null,
workspaceUri: string | null | undefined,
): string | null {
// `lintFileWrapper` is never called without `loadPluginWrapper` being called first,
// so `lintFile` must be defined here
debugAssertIsNonNull(lintFile);
return lintFile(
filePath,
bufferId,
buffer,
buffer ?? null,
ruleIds,
optionsIds,
settingsJSON,
globalsJSON,
workspaceUri,
workspaceUri ?? null,
);
}

Expand Down
3 changes: 2 additions & 1 deletion apps/oxlint/src-js/generated/deserialize.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// To edit this generated file you have to edit `tasks/ast_tools/src/generators/raw_transfer.rs`.

import type { Program } from "./types.d.ts";
import type { Node, Comment } from "../plugins/types.ts";
import type { Location as SourceLocation } from "../plugins/location.ts";

type BufferWithArrays = Uint8Array & { uint32: Uint32Array; float64: Float64Array };
type GetLoc = (node: { range: [number, number] }) => SourceLocation;
type GetLoc = (node: Node | Comment) => SourceLocation;

export declare function deserializeProgramOnly(
buffer: BufferWithArrays,
Expand Down
10 changes: 6 additions & 4 deletions apps/oxlint/src-js/package/rule_tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type ItFn = ((text: string, fn: () => void) => void) & { only?: ItFn };
* @param method - Test case logic
* @returns Returned value of `method`
*/
function defaultDescribe<R>(text: string, method: () => R): R {
function defaultDescribe<T, R>(this: T, text: string, method: (this: T) => R): R {
return method.call(this);
}

Expand All @@ -58,7 +58,7 @@ let describe: DescribeFn =
* @throws {Error} Any error upon execution of `method`
* @returns Returned value of `method`
*/
function defaultIt<R>(text: string, method: () => R): R {
function defaultIt<T, R>(this: T, text: string, method: (this: T) => R): R {
try {
return method.call(this);
} catch (err) {
Expand Down Expand Up @@ -320,8 +320,8 @@ interface TestCase extends Config {
filename?: string;
options?: Options;
settings?: Settings;
before?: (this: this) => void;
after?: (this: this) => void;
before?(this: this): void;
after?(this: this): void;
}

/**
Expand Down Expand Up @@ -1566,6 +1566,7 @@ function getTestName(test: TestCase): string {
* @throws {*} - Value thrown by the hook function
*/
function runBeforeHook(test: TestCase): void {
// oxlint-disable-next-line typescript/unbound-method - bound in `runHook`
if (Object.hasOwn(test, "before")) runHook(test, test.before, "before");
}

Expand All @@ -1576,6 +1577,7 @@ function runBeforeHook(test: TestCase): void {
* @throws {*} - Value thrown by the hook function
*/
function runAfterHook(test: TestCase): void {
// oxlint-disable-next-line typescript/unbound-method - bound in `runHook`
if (Object.hasOwn(test, "after")) runHook(test, test.after, "after");
}

Expand Down
6 changes: 3 additions & 3 deletions apps/oxlint/src-js/plugins/cfg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { ancestors } from "../generated/walk.js";
import { debugAssert, debugAssertIsFunction } from "../utils/asserts.ts";

import type { EnterExit } from "./visitor.ts";
import type { CfgVisitFn, EnterExit } from "./visitor.ts";
import type { Node, Program } from "../generated/types.d.ts";
import type { CompiledVisitors } from "../generated/walk.js";

Expand Down Expand Up @@ -139,10 +139,10 @@ export function walkProgramWithCfg(ast: Program, visitors: CompiledVisitors): vo
// Call method (CFG event). `typeId` is event type ID.
debugAssert(Array.isArray(stepData[i]), "`stepData` should contain an array for CFG events");

const visit = visitors[typeId];
const visit = visitors[typeId] as CfgVisitFn;
if (visit !== null) {
debugAssertIsFunction(visit);
visit.apply(undefined, stepData[i]);
visit.apply(undefined, stepData[i] as unknown[]);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions apps/oxlint/src-js/plugins/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import type { Node, Visitor } from "./types.ts";
export type VisitFn = (node: Node) => void;

// Visit function for a specific CFG event.
type CfgVisitFn = (...args: unknown[]) => void;
export type CfgVisitFn = (...args: unknown[]) => void;

// Enter+exit pair, for non-leaf nodes in compiled visitor.
export interface EnterExit {
Expand Down Expand Up @@ -268,7 +268,7 @@ export function addVisitorToCompiled(visitor: Visitor): void {
for (let i = 0; i < keysLen; i++) {
let name = keys[i];

const visitFn = visitor[name];
const visitFn = visitor[name] as VisitFn;
if (typeof visitFn !== "function") {
throw new TypeError(`'${name}' property of visitor object is not a function`);
}
Expand Down Expand Up @@ -649,7 +649,7 @@ function mergeCfgVisitFns(visitProps: VisitProp[]): CfgVisitFn {
if (numVisitFns === 1) {
// Only 1 visit function, so no need to merge
debugAssertIsNonNull(visitProps[0].fn);
mergedFn = visitProps[0].fn;
mergedFn = visitProps[0].fn as CfgVisitFn;
} else {
// No need to sort in order of specificity, because each rule can only have 1 handler for each CFG event

Expand All @@ -675,7 +675,7 @@ function mergeCfgVisitFns(visitProps: VisitProp[]): CfgVisitFn {
debugAssertIsNonNull(visitProps[i].fn);
visitFns.push(visitProps[i].fn!);
}
mergedFn = merger(...visitFns);
mergedFn = merger(...(visitFns as CfgVisitFn[]));

visitFns.length = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/oxlint/test/tokens.type_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ declare const node: Node;

// Options with `filter` only -> `Token[]`
{
const opts = { filter: (token: Token) => token.type === "Keyword" };
const opts = { filter: (token: TokenOrComment) => token.type === "Keyword" };
const result = getTokens(node, opts);
true satisfies IsExact<typeof result, Token[]>;
}
Expand Down Expand Up @@ -277,7 +277,7 @@ declare const node: Node;

// Options with `filter` only -> `Token | null`
{
const opts = { filter: (token: Token) => token.type === "Keyword" };
const opts = { filter: (token: TokenOrComment) => token.type === "Keyword" };
const result = getFirstToken(node, opts);
true satisfies IsExact<typeof result, Token | null>;
}
Expand Down
7 changes: 2 additions & 5 deletions apps/oxlint/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@
"noEmit": true,
"target": "ESNext",
"allowImportingTsExtensions": true,
"strict": false,
"noImplicitAny": true,
"strictNullChecks": true,
"strict": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"useUnknownInCatchVariables": true
"noUnusedLocals": true
},
"exclude": ["node_modules", "fixtures", "test/fixtures/*/files", "conformance/submodules"]
}
3 changes: 2 additions & 1 deletion tasks/ast_tools/src/generators/raw_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,11 @@ fn generate_deserializers(
#[rustfmt::skip]
let code_type_definition_linter = "
import type { Program } from './types.d.ts';
import type { Node, Comment } from '../plugins/types.ts';
import type { Location as SourceLocation } from '../plugins/location.ts';

type BufferWithArrays = Uint8Array & { uint32: Uint32Array; float64: Float64Array };
type GetLoc = (node: { range: [number, number] }) => SourceLocation;
type GetLoc = (node: Node | Comment) => SourceLocation;

export declare function deserializeProgramOnly(
buffer: BufferWithArrays,
Expand Down
Loading