Skip to content

Commit 6f66c0a

Browse files
committed
fix: linters
1 parent 47036d9 commit 6f66c0a

4 files changed

Lines changed: 25 additions & 10 deletions

File tree

packages/lsp-server/src/common/features/diagnostics.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ const ROOT_OPTION_NAMES = [
4444
] as const;
4545

4646
const DEFAULT_ROOT_NAMES = new Set(['Assets', 'Liabilities', 'Equity', 'Income', 'Expenses']);
47-
const NON_ASCII_RE = /[^\x00-\x7F]/;
4847
const INVALID_ACCOUNT_NAME_RE = /^Invalid account name:\s*(.+)$/;
4948
const INVALID_UNKNOWN_ACCOUNT_RE = /^Invalid reference to unknown account ['"](.+?)['"]$/;
5049

50+
function hasNonAscii(text: string): boolean {
51+
for (let i = 0; i < text.length; i++) {
52+
if (text.charCodeAt(i) > 0x7F) {
53+
return true;
54+
}
55+
}
56+
return false;
57+
}
58+
5159
function isNotGitUri(uri: string): boolean {
5260
return URI.parse(uri).scheme !== 'git';
5361
}
@@ -298,7 +306,7 @@ export class DiagnosticsFeature implements Feature {
298306
for (const name of ROOT_OPTION_NAMES) {
299307
const option = this.optionsManager.getOption(name);
300308
const value = option.asString();
301-
if (option.isDefault || !NON_ASCII_RE.test(value) || DEFAULT_ROOT_NAMES.has(value)) {
309+
if (option.isDefault || !hasNonAscii(value) || DEFAULT_ROOT_NAMES.has(value)) {
302310
continue;
303311
}
304312
customNonAsciiRoots.add(value);

packages/lsp-server/src/test/features/references-rename.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ describe('references + rename correctness', () => {
173173
expect(Object.values(tagEdit.changes).flat().some((e: any) => e.newText === '#newtag')).toBe(true);
174174
const linkEdit = await (rename as any).onRename({ textDocument: { uri }, position: linkPos, newName: '^newlink' });
175175
expect(Object.values(linkEdit.changes).flat().some((e: any) => e.newText === '^newlink')).toBe(true);
176-
const payeeEdit = await (rename as any).onRename({ textDocument: { uri }, position: payeePos, newName: '\"ACME \\\"Store\\\"\"' });
176+
const payeeEdit = await (rename as any).onRename({ textDocument: { uri }, position: payeePos, newName: '"ACME \\"Store\\""' });
177177
expect(Object.values(payeeEdit.changes).flat().some((e: any) => e.newText === '"ACME \\"Store\\""')).toBe(true);
178-
const narrationEdit = await (rename as any).onRename({ textDocument: { uri }, position: narrationPos, newName: '\"New Narration\"' });
178+
const narrationEdit = await (rename as any).onRename({ textDocument: { uri }, position: narrationPos, newName: '"New Narration"' });
179179
expect(Object.values(narrationEdit.changes).flat().some((e: any) => e.newText === '"New Narration"')).toBe(true);
180180
});
181181

packages/lsp-server/src/test/utils/test-server-harness.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export class InMemoryDocumentStore {
5757
}
5858
}
5959

60+
type ListenerFn = (...args: unknown[]) => unknown;
61+
6062
export function positionAt(text: string, needle: string, offsetInNeedle = 0): { line: number; character: number } {
6163
const index = text.indexOf(needle);
6264
if (index < 0) {
@@ -96,7 +98,7 @@ export function makeFakeConnection(options?: {
9698
}) {
9799
const sentDiagnostics: Array<{ uri: string; diagnostics: Diagnostic[] }> = [];
98100
const configurationRequests: Array<unknown> = [];
99-
const listeners: Record<string, Function[]> = {};
101+
const listeners: Record<string, ListenerFn[]> = {};
100102

101103
const connection = {
102104
workspace: {
@@ -114,16 +116,16 @@ export function makeFakeConnection(options?: {
114116
sendDiagnostics(payload: { uri: string; diagnostics: Diagnostic[] }) {
115117
sentDiagnostics.push(payload);
116118
},
117-
onExit(cb: Function) {
119+
onExit(cb: ListenerFn) {
118120
(listeners['exit'] ||= []).push(cb);
119121
},
120-
onReferences(cb: Function) {
122+
onReferences(cb: ListenerFn) {
121123
(listeners['references'] ||= []).push(cb);
122124
},
123-
onRenameRequest(cb: Function) {
125+
onRenameRequest(cb: ListenerFn) {
124126
(listeners['rename'] ||= []).push(cb);
125127
},
126-
onPrepareRename(cb: Function) {
128+
onPrepareRename(cb: ListenerFn) {
127129
(listeners['prepareRename'] ||= []).push(cb);
128130
},
129131
} as unknown as import('vscode-languageserver').Connection;

packages/playground/src/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ function debugLog(...args: unknown[]) {
7272
}
7373

7474
function hasNonAscii(text: string): boolean {
75-
return /[^\x00-\x7F]/.test(text);
75+
for (let i = 0; i < text.length; i++) {
76+
if (text.charCodeAt(i) > 0x7F) {
77+
return true;
78+
}
79+
}
80+
return false;
7681
}
7782

7883
async function sha256Hex(text: string): Promise<string> {

0 commit comments

Comments
 (0)