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
4 changes: 2 additions & 2 deletions dist/lib.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/lib.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/snippetFormatter.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/snippetFormatter.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/talonFormatter.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/talonFormatter.js.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions dist/treeSitterFormatter.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/treeSitterFormatter.js.map

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions dist/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export declare function isKnownArgument(value: string): value is KnownArgument;
export interface CLI {
binName: "snippet-fmt" | "talon-fmt" | "tree-sitter-fmt";
fileEndings: readonly string[];
getStdinFileEnding(text: string): string;
format(text: string, options: Options, filePath: string, debug: boolean): Promise<string>;
getStdinFileEnding: (text: string) => string;
format: (text: string, options: Options, filePath: string, debug: boolean) => Promise<string>;
}
export type EndOfLine = "lf" | "crlf";
export interface Options {
Expand All @@ -32,15 +32,15 @@ export interface LoggerEntry {
message: string;
}
export interface Logger {
log(message: string): void;
warn(message: string): void;
error(message: string): void;
log: (message: string) => void;
warn: (message: string) => void;
error: (message: string) => void;
}
export interface TestLogger extends Logger {
getEntries(): readonly LoggerEntry[];
getEntries: () => readonly LoggerEntry[];
}
export interface DebugLogger {
debug(message: string): void;
debug: (message: string) => void;
}
export interface EditorConfigOptions extends KnownProps {
max_line_length?: number | "unset";
Expand Down
4 changes: 4 additions & 0 deletions oxlint.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const disabledRules = [
"eslint/no-undefined",
"eslint/no-use-before-define",
"eslint/no-void",
"eslint/one-var",
"eslint/prefer-destructuring",
"eslint/prefer-named-capture-group",
"eslint/sort-imports",
"eslint/sort-keys",
"func-style",
Expand All @@ -35,6 +37,8 @@ const disabledRules = [
"import/no-namespace",
"import/no-relative-parent-imports",
"import/prefer-default-export",
"node/callback-return",
"node/no-sync",
"oxc/no-async-await",
"oxc/no-optional-chaining",
"oxc/no-rest-spread-properties",
Expand Down
2,559 changes: 845 additions & 1,714 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@
"test:subset": "tsx src/test/runAllTests.ts --subset"
},
"dependencies": {
"@cursorless/tree-sitter-wasms": "^0.9.0",
"@cursorless/tree-sitter-wasms": "^0.12.0",
"editorconfig": "^3.0.2",
"fast-glob": "^3.3.3",
"get-stdin": "^10.0.0",
"web-tree-sitter": "^0.26.8"
"web-tree-sitter": "^0.27.1"
},
"devDependencies": {
"@types/mocha": "^10.0.10",
"@types/node": "^24.12.2",
"esbuild": "^0.28.0",
"mocha": "^11.7.5",
"oxfmt": "^0.47.0",
"oxlint-tsgolint": "^0.22.1",
"oxlint": "^1.62.0",
"tsx": "^4.21.0",
"typescript": "^6.0.3"
"@types/node": "^24.19.2",
"esbuild": "^0.28.2",
"mocha": "^12.0.3",
"oxfmt": "^0.74.0",
"oxlint-tsgolint": "^7.0.2004",
"oxlint": "^1.89.0",
"tsx": "^4.23.15",
"typescript": "^7.0.2"
}
}
1 change: 1 addition & 0 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async function build(): Promise<void> {
}

try {
// oxlint-disable-next-line node/no-top-level-await
await build();
} catch (error) {
console.error(error);
Expand Down
6 changes: 3 additions & 3 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "node:fs/promises";
import * as path from "node:path";
import * as process from "node:process";
import fs from "node:fs/promises";
import path from "node:path";
import process from "node:process";
import type { Readable } from "node:stream";
import getStdin from "get-stdin";
import type { CLI, Logger, ParsedArgs } from "../types.js";
Expand Down
2 changes: 1 addition & 1 deletion src/node/normalizeToPosix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from "node:path";
import path from "node:path";

/**
* Replace `\` with `/` on Windows
Expand Down
2 changes: 1 addition & 1 deletion src/node/parseFilePatterns.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from "node:path";
import path from "node:path";
import type { Options } from "fast-glob";
import fastGlob from "fast-glob";
import type { CLI } from "../types.js";
Expand Down
4 changes: 2 additions & 2 deletions src/node/parseText.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "node:fs";
import * as path from "node:path";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { Language, Parser } from "web-tree-sitter";
import type { SyntaxNode } from "../types.js";
Expand Down
16 changes: 8 additions & 8 deletions src/snippet/parseSnippetFile.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Snippet, SnippetFile, SnippetVariable } from "./snippetTypes.js";

export function parseSnippetFile(content: string): SnippetFile {
const documentContents = content.split(/^---$/m);
const documentContents = content.split(/^---$/mu);
const file: SnippetFile = { snippets: [] };

for (const text of documentContents) {
const match = /^-$/m.exec(text);
const contextText = match != null ? text.slice(0, match.index) : text;
const match = /^-$/mu.exec(text);
const contextText = match == null ? text : text.slice(0, match.index);
const bodyText =
match != null ? text.slice(match.index + match[0].length) : null;
const body = bodyText != null ? parseBody(bodyText) : null;
match == null ? null : text.slice(match.index + match[0].length);
const body = bodyText == null ? null : parseBody(bodyText);
let context = parseContext(contextText);

// Snippet with body
Expand Down Expand Up @@ -74,7 +74,7 @@ function parseContext(text: string): Context | undefined {

function parseContextPairs(text: string): Record<string, string> {
const lines = text
.split(/\r?\n/)
.split(/\r?\n/u)
.map((l) => l.trim())
.filter(Boolean);
const pairs: Record<string, string> = {};
Expand Down Expand Up @@ -134,14 +134,14 @@ function parseVariables(variables: Record<string, string>): SnippetVariable[] {

function parseBody(text: string): string[] | undefined {
// Find first line that is not empty. Preserve indentation.
const matchLeading = /^[ \t]*\S/m.exec(text);
const matchLeading = /^[ \t]*\S/mu.exec(text);
if (matchLeading?.index == null) {
return undefined;
}
return text
.slice(matchLeading.index)
.trimEnd()
.split(/\r?\n/)
.split(/\r?\n/u)
.map((l) => l.trimEnd());
}

Expand Down
2 changes: 1 addition & 1 deletion src/talon/parseTalonList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface TalonList {
}

export function parseTalonList(text: string): TalonList {
const lines = text.split(/\r?\n/).map((l) => l.trim());
const lines = text.split(/\r?\n/u).map((l) => l.trim());
const separatorIndex = lines.indexOf("-");

if (separatorIndex === -1) {
Expand Down
6 changes: 3 additions & 3 deletions src/talon/talonFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ class TalonFormatter {
) {
const right = this.getNodeText(rightNode.children[0]);
const leftWithPadding =
this.columnWidth != null
? `${left}: `.padEnd(this.columnWidth)
: `${left}: `;
this.columnWidth == null
? `${left}: `
: `${left}: `.padEnd(this.columnWidth);
if (
leftWithPadding.length + right.length <=
this.maxLineLength
Expand Down
12 changes: 6 additions & 6 deletions src/talon/talonListFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export function talonListFormatter(
lines.push(item.text);
continue;
}
if (item.value != null) {
if (item.value == null) {
lines.push(item.key);
} else {
const keyWithColon =
columnWidth != null
? `${item.key}: `.padEnd(columnWidth)
: `${item.key}: `;
columnWidth == null
? `${item.key}: `
: `${item.key}: `.padEnd(columnWidth);
const value = convertQuotes(item.value);
lines.push(`${keyWithColon}${value}`);
} else {
lines.push(item.key);
}
}

Expand Down
20 changes: 6 additions & 14 deletions src/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ suite("CLI", () => {
debug: false,
filePath: fileName,
}),
/boom/,
/boom/u,
);
} finally {
await cleanupTempFile(fileName);
Expand Down Expand Up @@ -635,7 +635,7 @@ suite("CLI", () => {
});

assert.equal(output.result, EXIT_OK);
assert.match(output.stdoutText, /^\d+\.\d+\.\d+\n$/);
assert.match(output.stdoutText, /^\d+\.\d+\.\d+\n$/u);
assert.equal(output.stderrText, "");
} finally {
process.argv = originalArgv;
Expand Down Expand Up @@ -708,7 +708,7 @@ suite("CLI", () => {
test("Rejects unknown arguments", () => {
assert.throws(
() => parseArgs(["--check", "--write"]),
/Unknown argument: --write/,
/Unknown argument: --write/u,
);
});
});
Expand Down Expand Up @@ -785,9 +785,7 @@ async function captureStreamWrite<T>(
const originalWrite = stream.write.bind(stream);

// oxlint-disable-next-line typescript/no-unsafe-type-assertion
(stream.write as unknown as (chunk: string) => boolean) = (
chunk: string | Uint8Array,
) => {
stream.write = (chunk: string | Uint8Array) => {
text += chunk.toString();
return true;
};
Expand All @@ -808,18 +806,12 @@ async function captureStdoutAndStderr<T>(
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
const originalStderrWrite = process.stderr.write.bind(process.stderr);

// oxlint-disable-next-line typescript/no-unsafe-type-assertion
(process.stdout.write as unknown as (chunk: string) => boolean) = (
chunk: string | Uint8Array,
) => {
process.stdout.write = (chunk: string | Uint8Array) => {
stdoutText += chunk.toString();
return true;
};

// oxlint-disable-next-line typescript/no-unsafe-type-assertion
(process.stderr.write as unknown as (chunk: string) => boolean) = (
chunk: string | Uint8Array,
) => {
process.stderr.write = (chunk: string | Uint8Array) => {
stderrText += chunk.toString();
return true;
};
Expand Down
4 changes: 2 additions & 2 deletions src/test/parseTalonList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ bat: b
test("Throws when separator is missing", () => {
assert.throws(
() => parseTalonList("list: user.my_list"),
/Separator not found in talon list/,
/Separator not found in talon list/u,
);
});

test("Throws when a header value is missing", () => {
assert.throws(
() => parseTalonList("list\n-\na: b"),
/Header value missing/,
/Header value missing/u,
);
});
});
16 changes: 8 additions & 8 deletions src/test/snippetParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ function testWhitespace() {
const fixture = `
name: foo
-
foo
bar

foo

bar
baz `;

const expected: SnippetFile = {
Expand Down Expand Up @@ -119,7 +119,7 @@ function testEmpty() {
function testMultipleDocuments() {
const fixture = `\
name: mySnippet
phrase: first
phrase: first
-
foo
---
Expand Down Expand Up @@ -208,14 +208,14 @@ b
function testInvalidKey() {
assert.throws(
() => parseSnippetFile("unknown: test"),
/Invalid key 'unknown'/,
/Invalid key 'unknown'/u,
);
}

function testInvalidVariableKey() {
assert.throws(
() => parseSnippetFile("$0.invalidField: test"),
/Invalid variable key '\$0\.invalidField'/,
/Invalid variable key '\$0\.invalidField'/u,
);
}

Expand All @@ -231,6 +231,6 @@ name: header

assert.throws(
() => parseSnippetFile(fixture),
/Header snippet must be first in file/,
/Header snippet must be first in file/u,
);
}
10 changes: 4 additions & 6 deletions src/test/testUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from "node:fs";
import * as path from "node:path";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import fastGlob from "fast-glob";
import type { SyntaxNode } from "../types.js";
Expand Down Expand Up @@ -27,9 +27,7 @@ export async function captureStreamWrite<T>(
const originalWrite = stream.write.bind(stream);

// oxlint-disable-next-line typescript/no-unsafe-type-assertion
(stream.write as unknown as (chunk: string) => boolean) = (
chunk: string | Uint8Array,
) => {
stream.write = (chunk: string | Uint8Array) => {
text += chunk.toString();
return true;
};
Expand Down Expand Up @@ -89,7 +87,7 @@ export function getGrep(): string | undefined {
);
const content = fs.readFileSync(subsetFile, "utf8");
const pattern = content
.split(/\r?\n/)
.split(/\r?\n/u)
.map((line) => line.trim())
.filter((line) => line.length > 0 && !line.startsWith("//"))
.join("|");
Expand Down
Loading
Loading