Skip to content

Commit 2aec397

Browse files
[pre-commit.ci lite] apply automatic fixes
1 parent 25adbca commit 2aec397

10 files changed

+292
-253
lines changed
+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint-disable */
22
export default {
3-
displayName: 'generate-examples',
4-
preset: '../../jest.preset.js',
3+
displayName: "generate-examples",
4+
preset: "../../jest.preset.js",
55
globals: {
6-
'ts-jest': {
7-
tsconfig: '<rootDir>/tsconfig.spec.json',
6+
"ts-jest": {
7+
tsconfig: "<rootDir>/tsconfig.spec.json",
88
},
99
},
1010
transform: {
11-
'^.+\\.[tj]s$': 'ts-jest',
11+
"^.+\\.[tj]s$": "ts-jest",
1212
},
13-
moduleFileExtensions: ['ts', 'js', 'html'],
14-
coverageDirectory: '../../coverage/libs/generate-examples',
13+
moduleFileExtensions: ["ts", "js", "html"],
14+
coverageDirectory: "../../coverage/libs/generate-examples",
1515
};
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './lib/generate-examples';
1+
export * from "./lib/generate-examples";
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
import { loadFixture } from './loadFixture.js';
1+
import { loadFixture } from "./loadFixture.js";
22

33
Promise.all([
4-
loadFixture('actions', 'bringArgMadeAfterLook'),
5-
loadFixture('decorations', 'chuckBlockAirUntilBatt'),
6-
loadFixture('decorations', 'cutFine'),
7-
loadFixture('decorations', 'chuckLineFine'),
8-
loadFixture('actions', 'bringAirAndBatAndCapToAfterItemEach'),
4+
loadFixture("actions", "bringArgMadeAfterLook"),
5+
loadFixture("decorations", "chuckBlockAirUntilBatt"),
6+
loadFixture("decorations", "cutFine"),
7+
loadFixture("decorations", "chuckLineFine"),
8+
loadFixture("actions", "bringAirAndBatAndCapToAfterItemEach"),
99
]).then((allItems) => {
1010
allItems.forEach((item) => {
11-
if (item)
11+
if (item) {
1212
console.log(`
1313
.wrapper
1414
.before
15-
${item.before.replace(/\n/gi, '\n ')}
15+
${item.before.replace(/\n/gi, "\n ")}
1616
.during
17-
${(item.during || item.before).replace(/\n/gi, '\n ')}
17+
${(item.during || item.before).replace(/\n/gi, "\n ")}
1818
.command ${item.command}
1919
.after
20-
${item.after.replace(/\n/gi, '\n ')}
20+
${item.after.replace(/\n/gi, "\n ")}
2121
`);
22+
}
2223
});
2324
});

packages/generate-examples/src/lib/buildSpokenForm.ts

+75-58
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import path from 'path';
2-
import fs from 'fs-extra';
3-
const cursorlessRoot = path.resolve('../../../src');
1+
import path from "path";
2+
import fs from "fs-extra";
3+
const cursorlessRoot = path.resolve("../../../src");
44

55
const commandDictionaryJson = fs.readJSONSync(
66
path.join(
77
cursorlessRoot,
8-
'../cursorless-nx/libs/cheatsheet/src/lib/data/sampleSpokenFormInfos/defaults.json'
9-
)
10-
) as typeof import('../../../cheatsheet/src/lib/data/sampleSpokenFormInfos/defaults.json');
8+
"../cursorless-nx/libs/cheatsheet/src/lib/data/sampleSpokenFormInfos/defaults.json",
9+
),
10+
) as typeof import("../../../cheatsheet/src/lib/data/sampleSpokenFormInfos/defaults.json");
1111

12-
const letters = 'abcdefghijklmnopqrstuvwxyz'.split('');
12+
const letters = "abcdefghijklmnopqrstuvwxyz".split("");
1313
const defaultAlphabet =
14-
'air bat cap drum each fine gust harp sit jury crunch look made near odd pit quench red sun trap urge vest whale plex yank zip'
15-
.split(' ')
14+
"air bat cap drum each fine gust harp sit jury crunch look made near odd pit quench red sun trap urge vest whale plex yank zip"
15+
.split(" ")
1616
.map((word, index) => [letters[index], word] as const);
1717

18-
const defaultDigits = 'zero one two three four five six seven eight nine'
19-
.split(' ')
18+
const defaultDigits = "zero one two three four five six seven eight nine"
19+
.split(" ")
2020
.map((word, index) => [`${index}`, word] as const);
2121

2222
const letterDictionary = defaultAlphabet
@@ -32,48 +32,48 @@ const commandDictionary = commandDictionaryJson.sections.reduce(
3232
...r,
3333
[id]: variations[0].spokenForm,
3434
}),
35-
{}
35+
{},
3636
),
3737
};
3838
},
3939
{} as Record<
40-
typeof commandDictionaryJson['sections'][number]['id'],
40+
(typeof commandDictionaryJson)["sections"][number]["id"],
4141
Record<
42-
typeof commandDictionaryJson['sections'][number]['items'][number]['id'],
43-
typeof commandDictionaryJson['sections'][number]['items'][number]['variations'][0]['spokenForm']
42+
(typeof commandDictionaryJson)["sections"][number]["items"][number]["id"],
43+
(typeof commandDictionaryJson)["sections"][number]["items"][number]["variations"][0]["spokenForm"]
4444
>
45-
>
45+
>,
4646
);
4747

4848
type CommandDictionary = typeof commandDictionary;
4949

5050
interface Modifier {
51-
type: 'position' | 'containingScope';
52-
position: keyof CommandDictionary['positions'];
51+
type: "position" | "containingScope";
52+
position: keyof CommandDictionary["positions"];
5353
scopeType: {
54-
type: keyof CommandDictionary['scopes'];
54+
type: keyof CommandDictionary["scopes"];
5555
};
5656
}
5757
type PrimitiveTarget = {
58-
type: 'primitive';
58+
type: "primitive";
5959
modifiers?: Modifier[];
60-
position?: keyof CommandDictionary['positions'];
60+
position?: keyof CommandDictionary["positions"];
6161
mark?: {
62-
type: 'decoratedSymbol';
62+
type: "decoratedSymbol";
6363
character: keyof typeof letterDictionary;
6464
};
6565
};
6666

6767
type RangeTarget = {
68-
type: 'range';
68+
type: "range";
6969
excludeAnchor?: boolean;
7070
excludeActive?: boolean;
7171
anchor: Target;
7272
active: Target;
7373
};
7474

7575
type ListTarget = {
76-
type: 'list';
76+
type: "list";
7777
elements: Target[];
7878
};
7979

@@ -82,7 +82,7 @@ type Command = { action: { name: string }; targets: Target[] };
8282

8383
function interpolate(
8484
template: string,
85-
handleAction: (counter: number) => string
85+
handleAction: (counter: number) => string,
8686
) {
8787
let counter = -1;
8888
return template.replace(/<[a-z0-9]+>/gi, () => handleAction(++counter));
@@ -97,22 +97,24 @@ class SpokenForm {
9797

9898
public build() {
9999
return interpolate(this.getTemplate(), (counter) =>
100-
this.parseTarget(this.command.targets[counter])
100+
this.parseTarget(this.command.targets[counter]),
101101
);
102102
}
103103

104104
private getTemplate() {
105-
return commandDictionary['actions'][this.command.action.name];
105+
return commandDictionary["actions"][this.command.action.name];
106106
}
107107

108108
private parseTarget(target: Target): string {
109-
if (!target) throw new Error(`Excess mark`);
109+
if (!target) {
110+
throw new Error(`Excess mark`);
111+
}
110112
switch (target.type) {
111-
case 'primitive':
113+
case "primitive":
112114
return this.parsePrimitiveTarget(target);
113-
case 'range':
115+
case "range":
114116
return this.parseRangeTarget(target);
115-
case 'list':
117+
case "list":
116118
return this.parseListTarget(target);
117119
default: {
118120
// @ts-expect-error - if this is hit we need to add new cases and types
@@ -126,58 +128,73 @@ class SpokenForm {
126128
?.filter((v): v is Modifier => !!v)
127129
?.map((mod) => {
128130
switch (mod.type) {
129-
case 'position':
130-
return commandDictionary['positions'][mod.position];
131-
case 'containingScope':
132-
return commandDictionary['scopes'][mod.scopeType.type];
131+
case "position":
132+
return commandDictionary["positions"][mod.position];
133+
case "containingScope":
134+
return commandDictionary["scopes"][mod.scopeType.type];
133135
}
134136
throw new Error(`Unknown modifier type ${mod.type}`);
135137
})
136-
.join(' ') || '';
138+
.join(" ") || "";
137139
if (target.position) {
138-
prefix = `${commandDictionary['positions'][target.position]} ${prefix}`;
140+
prefix = `${commandDictionary["positions"][target.position]} ${prefix}`;
139141
}
140142
if (target.mark) {
141-
if (target.mark.type !== 'decoratedSymbol')
143+
if (target.mark.type !== "decoratedSymbol") {
142144
throw new Error(`Unknown target type ${target.mark.type}`);
145+
}
143146
return (
144-
(prefix ? prefix + ' ' : '') + letterDictionary[target.mark.character]
147+
(prefix ? prefix + " " : "") + letterDictionary[target.mark.character]
145148
);
146149
}
147-
if (!prefix) throw new Error(`Unknown mark`);
150+
if (!prefix) {
151+
throw new Error(`Unknown mark`);
152+
}
148153
return prefix;
149154
}
150155

151156
parseRangeTarget(target: RangeTarget) {
152157
let compoundTargetKey;
153-
if (target.excludeAnchor && target.excludeActive)
154-
compoundTargetKey = 'rangeExclusive';
155-
else if (!target.excludeAnchor && !target.excludeActive)
156-
compoundTargetKey = 'rangeInclusive';
157-
else if (!target.excludeAnchor && target.excludeActive)
158-
compoundTargetKey = 'rangeExcludingEnd';
159-
else throw new Error(`Bad inclusion range`);
158+
if (target.excludeAnchor && target.excludeActive) {
159+
compoundTargetKey = "rangeExclusive";
160+
} else if (!target.excludeAnchor && !target.excludeActive) {
161+
compoundTargetKey = "rangeInclusive";
162+
} else if (!target.excludeAnchor && target.excludeActive) {
163+
compoundTargetKey = "rangeExcludingEnd";
164+
} else {
165+
throw new Error(`Bad inclusion range`);
166+
}
160167
return interpolate(
161-
commandDictionary['compoundTargets'][compoundTargetKey],
168+
commandDictionary["compoundTargets"][compoundTargetKey],
162169
(index) => {
163-
if (index === 0) return this.parseTarget(target.anchor);
164-
if (index === 1) return this.parseTarget(target.active);
165-
return '';
166-
}
170+
if (index === 0) {
171+
return this.parseTarget(target.anchor);
172+
}
173+
if (index === 1) {
174+
return this.parseTarget(target.active);
175+
}
176+
return "";
177+
},
167178
);
168179
}
169180
parseListTarget(target: ListTarget) {
170181
return target.elements.reduce((result, element) => {
171-
if (!result) return this.parseTarget(element);
182+
if (!result) {
183+
return this.parseTarget(element);
184+
}
172185
return interpolate(
173-
commandDictionary['compoundTargets']['listConnective'],
186+
commandDictionary["compoundTargets"]["listConnective"],
174187
(index) => {
175-
if (index === 0) return result;
176-
if (index === 1) return this.parseTarget(element);
188+
if (index === 0) {
189+
return result;
190+
}
191+
if (index === 1) {
192+
return this.parseTarget(element);
193+
}
177194
throw Error(`Invalid List`);
178-
}
195+
},
179196
);
180-
}, '');
197+
}, "");
181198
}
182199
}
183200

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export function generateExamples(): string {
2-
return 'generate-examples';
2+
return "generate-examples";
33
}

0 commit comments

Comments
 (0)