Skip to content

Commit 955fc56

Browse files
committed
chore: Lint fixes.
1 parent fad610f commit 955fc56

23 files changed

+402
-235
lines changed

src/screenreader/aria_monkey_patcher.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@
1010
*/
1111

1212
import * as aria from './aria';
13-
import './stuboverrides/override_block_svg'
14-
import './stuboverrides/override_collapsible_toolbox_category'
15-
import './stuboverrides/override_comment_icon'
16-
import './stuboverrides/override_field_checkbox'
17-
import './stuboverrides/override_field_dropdown'
18-
import './stuboverrides/override_field_image'
19-
import './stuboverrides/override_field_input'
20-
import './stuboverrides/override_field_label'
21-
import './stuboverrides/override_field'
22-
import './stuboverrides/override_flyout_button'
23-
import './stuboverrides/override_icon'
24-
import './stuboverrides/override_mutator_icon'
25-
import './stuboverrides/override_rendered_connection'
26-
import './stuboverrides/override_rendered_workspace_comment'
27-
import './stuboverrides/override_toolbox_category'
28-
import './stuboverrides/override_toolbox_separator'
29-
import './stuboverrides/override_toolbox'
30-
import './stuboverrides/override_warning_icon'
31-
import './stuboverrides/override_workspace_svg'
13+
import './stuboverrides/override_block_svg';
14+
import './stuboverrides/override_collapsible_toolbox_category';
15+
import './stuboverrides/override_comment_icon';
16+
import './stuboverrides/override_field_checkbox';
17+
import './stuboverrides/override_field_dropdown';
18+
import './stuboverrides/override_field_image';
19+
import './stuboverrides/override_field_input';
20+
import './stuboverrides/override_field_label';
21+
import './stuboverrides/override_field';
22+
import './stuboverrides/override_flyout_button';
23+
import './stuboverrides/override_icon';
24+
import './stuboverrides/override_mutator_icon';
25+
import './stuboverrides/override_rendered_connection';
26+
import './stuboverrides/override_rendered_workspace_comment';
27+
import './stuboverrides/override_toolbox_category';
28+
import './stuboverrides/override_toolbox_separator';
29+
import './stuboverrides/override_toolbox';
30+
import './stuboverrides/override_warning_icon';
31+
import './stuboverrides/override_workspace_svg';
3232

3333
const oldCreateElementNS = document.createElementNS;
3434

src/screenreader/block_svg_utilities.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export function computeBlockAriaLabel(block: Blockly.BlockSvg): string {
88
// Shadow blocks are best represented directly by their field since they
99
// effectively operate like a field does for keyboard navigation purposes.
1010
const field = Array.from(block.getFields())[0];
11-
return aria.getState(field.getFocusableElement(), aria.State.LABEL) ?? 'Unknown?';
11+
return (
12+
aria.getState(field.getFocusableElement(), aria.State.LABEL) ?? 'Unknown?'
13+
);
1214
}
1315

1416
const fieldLabels = [];
@@ -18,9 +20,12 @@ export function computeBlockAriaLabel(block: Blockly.BlockSvg): string {
1820
}
1921
}
2022
return fieldLabels.join(' ');
21-
};
23+
}
2224

23-
function collectSiblingBlocks(block: Blockly.BlockSvg, surroundParent: Blockly.BlockSvg | null): Blockly.BlockSvg[] {
25+
function collectSiblingBlocks(
26+
block: Blockly.BlockSvg,
27+
surroundParent: Blockly.BlockSvg | null,
28+
): Blockly.BlockSvg[] {
2429
// NOTE TO DEVELOPERS: it's very important that these are NOT sorted. The
2530
// returned list needs to be relatively stable for consistency block indexes
2631
// read out to users via screen readers.
@@ -29,7 +34,7 @@ function collectSiblingBlocks(block: Blockly.BlockSvg, surroundParent: Blockly.B
2934
const firstSibling: Blockly.BlockSvg = surroundParent.getChildren(false)[0];
3035
const siblings: Blockly.BlockSvg[] = [firstSibling];
3136
let nextSibling: Blockly.BlockSvg | null = firstSibling;
32-
while (nextSibling = nextSibling.getNextBlock()) {
37+
while ((nextSibling = nextSibling.getNextBlock())) {
3338
siblings.push(nextSibling);
3439
}
3540
return siblings;
@@ -42,10 +47,12 @@ function collectSiblingBlocks(block: Blockly.BlockSvg, surroundParent: Blockly.B
4247
function computeLevelInWorkspace(block: Blockly.BlockSvg): number {
4348
const surroundParent = block.getSurroundParent();
4449
return surroundParent ? computeLevelInWorkspace(surroundParent) + 1 : 0;
45-
};
50+
}
4651

4752
// TODO: Do this efficiently (probably centrally).
48-
export function recomputeAriaTreeItemDetailsRecursively(block: Blockly.BlockSvg) {
53+
export function recomputeAriaTreeItemDetailsRecursively(
54+
block: Blockly.BlockSvg,
55+
) {
4956
const elem = block.getFocusableElement();
5057
const connection = (block as any).currentConnectionCandidate;
5158
let childPosition: number;
@@ -69,7 +76,9 @@ export function recomputeAriaTreeItemDetailsRecursively(block: Blockly.BlockSvg)
6976
childPosition = siblingBlocks.indexOf(connection.sourceBlock_) + 2;
7077
}
7178
parentsChildCount = siblingBlocks.length + 1;
72-
hierarchyDepth = surroundParent ? computeLevelInWorkspace(surroundParent) + 1 : 1;
79+
hierarchyDepth = surroundParent
80+
? computeLevelInWorkspace(surroundParent) + 1
81+
: 1;
7382
} else {
7483
const surroundParent = block.getSurroundParent();
7584
const siblingBlocks = collectSiblingBlocks(block, surroundParent);
@@ -80,10 +89,17 @@ export function recomputeAriaTreeItemDetailsRecursively(block: Blockly.BlockSvg)
8089
aria.setState(elem, aria.State.POSINSET, childPosition);
8190
aria.setState(elem, aria.State.SETSIZE, parentsChildCount);
8291
aria.setState(elem, aria.State.LEVEL, hierarchyDepth);
83-
block.getChildren(false).forEach((child) => recomputeAriaTreeItemDetailsRecursively(child));
92+
block
93+
.getChildren(false)
94+
.forEach((child) => recomputeAriaTreeItemDetailsRecursively(child));
8495
}
8596

86-
export function announceDynamicAriaStateForBlock(block: Blockly.BlockSvg, isMoving: boolean, isCanceled: boolean, newLoc?: Blockly.utils.Coordinate) {
97+
export function announceDynamicAriaStateForBlock(
98+
block: Blockly.BlockSvg,
99+
isMoving: boolean,
100+
isCanceled: boolean,
101+
newLoc?: Blockly.utils.Coordinate,
102+
) {
87103
const connection = (block as any).currentConnectionCandidate;
88104
if (isCanceled) {
89105
aria.announceDynamicAriaState('Canceled movement');
@@ -93,7 +109,7 @@ export function announceDynamicAriaStateForBlock(block: Blockly.BlockSvg, isMovi
93109
if (connection) {
94110
// TODO: Figure out general detachment.
95111
// TODO: Figure out how to deal with output connections.
96-
let surroundParent: Blockly.BlockSvg | null = connection.sourceBlock_;
112+
const surroundParent: Blockly.BlockSvg | null = connection.sourceBlock_;
97113
const announcementContext = [];
98114
announcementContext.push('Moving'); // TODO: Specialize for inserting?
99115
// NB: Old code here doesn't seem to handle parents correctly.
@@ -111,6 +127,8 @@ export function announceDynamicAriaStateForBlock(block: Blockly.BlockSvg, isMovi
111127
aria.announceDynamicAriaState(announcementContext.join(' '));
112128
} else if (newLoc) {
113129
// The block is being freely dragged.
114-
aria.announceDynamicAriaState(`Moving unconstrained to coordinate x ${Math.round(newLoc.x)} and y ${Math.round(newLoc.y)}.`);
130+
aria.announceDynamicAriaState(
131+
`Moving unconstrained to coordinate x ${Math.round(newLoc.x)} and y ${Math.round(newLoc.y)}.`,
132+
);
115133
}
116134
}

src/screenreader/function_stubber_registry.ts

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,37 @@ class Registration<T> {
77
readonly callback: StubCallback<T>,
88
readonly methodNameToOverride: string,
99
readonly classPrototype: T,
10-
readonly ensureOneCall: boolean
10+
readonly ensureOneCall: boolean,
1111
) {}
1212

1313
stubPrototype(): void {
1414
// TODO: Figure out how to make this work with minification.
1515
if (this.oldMethod) {
16-
throw new Error(`Function is already stubbed: ${this.methodNameToOverride}.`);
16+
throw new Error(
17+
`Function is already stubbed: ${this.methodNameToOverride}.`,
18+
);
1719
}
1820
const genericPrototype = this.classPrototype as any;
19-
const oldMethod =
20-
genericPrototype[this.methodNameToOverride] as (...args: any) => any;
21+
const oldMethod = genericPrototype[this.methodNameToOverride] as (
22+
...args: any
23+
) => any;
2124
this.oldMethod = oldMethod;
25+
// eslint-disable-next-line @typescript-eslint/no-this-alias
2226
const registration = this;
2327
genericPrototype[this.methodNameToOverride] = function (...args: any): any {
24-
let stubsCalled =
25-
this._internalStubsCalled as {[key: string]: boolean} | undefined;
28+
let stubsCalled = this._internalStubsCalled as
29+
| {[key: string]: boolean}
30+
| undefined;
2631
if (!stubsCalled) {
2732
stubsCalled = {};
2833
this._internalStubsCalled = stubsCalled;
2934
}
3035

3136
const result = oldMethod.call(this, ...args);
32-
if (!registration.ensureOneCall || !stubsCalled[registration.methodNameToOverride]) {
37+
if (
38+
!registration.ensureOneCall ||
39+
!stubsCalled[registration.methodNameToOverride]
40+
) {
3341
registration.callback(this as unknown as T, ...args);
3442
stubsCalled[registration.methodNameToOverride] = true;
3543
}
@@ -39,7 +47,9 @@ class Registration<T> {
3947

4048
unstubPrototype(): void {
4149
if (this.oldMethod) {
42-
throw new Error(`Function is not currently stubbed: ${this.methodNameToOverride}.`);
50+
throw new Error(
51+
`Function is not currently stubbed: ${this.methodNameToOverride}.`,
52+
);
4353
}
4454
const genericPrototype = this.classPrototype as any;
4555
genericPrototype[this.methodNameToOverride] = this.oldMethod;
@@ -48,40 +58,56 @@ class Registration<T> {
4858
}
4959

5060
export class FunctionStubber {
51-
private registrations: Registration<any>[] = [];
52-
private isFinalized: boolean = false;
61+
private registrations: Array<Registration<any>> = [];
62+
private isFinalized = false;
5363

54-
public registerInitializationStub<T>(
64+
registerInitializationStub<T>(
5565
callback: StubCallback<T>,
5666
methodNameToOverride: string,
57-
classPrototype: T
67+
classPrototype: T,
5868
) {
5969
if (this.isFinalized) {
60-
throw new Error('Cannot register a stub after initialization has been completed.');
70+
throw new Error(
71+
'Cannot register a stub after initialization has been completed.',
72+
);
6173
}
62-
const registration = new Registration(callback, methodNameToOverride, classPrototype, true);
74+
const registration = new Registration(
75+
callback,
76+
methodNameToOverride,
77+
classPrototype,
78+
true,
79+
);
6380
this.registrations.push(registration);
6481
}
6582

66-
public registerMethodStub<T>(
83+
registerMethodStub<T>(
6784
callback: StubCallback<T>,
6885
methodNameToOverride: string,
69-
classPrototype: T
86+
classPrototype: T,
7087
) {
7188
if (this.isFinalized) {
72-
throw new Error('Cannot register a stub after initialization has been completed.');
89+
throw new Error(
90+
'Cannot register a stub after initialization has been completed.',
91+
);
7392
}
74-
const registration = new Registration(callback, methodNameToOverride, classPrototype, false);
93+
const registration = new Registration(
94+
callback,
95+
methodNameToOverride,
96+
classPrototype,
97+
false,
98+
);
7599
this.registrations.push(registration);
76100
}
77101

78-
public stubPrototypes() {
102+
stubPrototypes() {
79103
this.isFinalized = true;
80104
this.registrations.forEach((registration) => registration.stubPrototype());
81105
}
82106

83-
public unstubPrototypes() {
84-
this.registrations.forEach((registration) => registration.unstubPrototype());
107+
unstubPrototypes() {
108+
this.registrations.forEach((registration) =>
109+
registration.unstubPrototype(),
110+
);
85111
this.isFinalized = false;
86112
}
87113

0 commit comments

Comments
 (0)