Skip to content

Commit 1d33e00

Browse files
authored
refactor(task-selection): Promote eslint config and fix linter violations (microsoft#25994)
Promotes the eslint config from `minimal-deprecated` to `recommended` and fixes resulting linter violations
1 parent 0b24d03 commit 1d33e00

File tree

6 files changed

+44
-36
lines changed

6 files changed

+44
-36
lines changed

examples/apps/task-selection/.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
module.exports = {
77
extends: [
8-
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
8+
require.resolve("@fluidframework/eslint-config-fluid"),
99
"prettier",
1010
"../../.eslintrc.cjs",
1111
],

examples/apps/task-selection/src/app.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { StaticCodeLoader, TinyliciousModelLoader } from "@fluid-example/example-utils";
77

88
import {
9-
ITaskSelectionAppModel,
9+
type ITaskSelectionAppModel,
1010
TaskSelectionContainerRuntimeFactory,
1111
} from "./containerCode.js";
1212
import { renderDiceRoller } from "./view.js";
@@ -16,7 +16,7 @@ import { renderDiceRoller } from "./view.js";
1616
*
1717
* @remarks We wrap this in an async function so we can await Fluid's async calls.
1818
*/
19-
async function start() {
19+
async function start(): Promise<void> {
2020
const tinyliciousModelLoader = new TinyliciousModelLoader<ITaskSelectionAppModel>(
2121
new StaticCodeLoader(new TaskSelectionContainerRuntimeFactory()),
2222
);
@@ -32,11 +32,12 @@ async function start() {
3232
model = createResponse.model;
3333
id = await createResponse.attach();
3434
} else {
35-
id = location.hash.substring(1);
35+
id = location.hash.slice(1);
3636
model = await tinyliciousModelLoader.loadExisting(id);
3737
}
3838

3939
// update the browser URL and the window title with the actual container ID
40+
// eslint-disable-next-line require-atomic-updates
4041
location.hash = id;
4142
document.title = id;
4243

@@ -62,8 +63,12 @@ async function start() {
6263
renderDiceRoller(model.oldestClientDiceRoller, oldestClientViewDiv);
6364
oldestClientDiv.append(oldestClientHeaderDiv, oldestClientViewDiv);
6465

65-
const div = document.getElementById("content") as HTMLDivElement;
66+
const div = document.querySelector("#content") as HTMLDivElement;
6667
div.append(taskManagerDiv, divider, oldestClientDiv);
6768
}
6869

69-
start().catch((error) => console.error(error));
70+
try {
71+
await start();
72+
} catch (error) {
73+
console.error(error);
74+
}

examples/apps/task-selection/src/containerCode.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
ModelContainerRuntimeFactory,
88
getDataStoreEntryPoint,
99
} from "@fluid-example/example-utils";
10-
import { IContainer } from "@fluidframework/container-definitions/legacy";
11-
import { IContainerRuntime } from "@fluidframework/container-runtime-definitions/legacy";
10+
import type { IContainer } from "@fluidframework/container-definitions/legacy";
11+
import type { IContainerRuntime } from "@fluidframework/container-runtime-definitions/legacy";
1212

13-
import { IDiceRoller } from "./interface.js";
13+
import type { IDiceRoller } from "./interface.js";
1414
import { OldestClientDiceRollerInstantiationFactory } from "./oldestClientDiceRoller.js";
1515
import { TaskManagerDiceRollerInstantiationFactory } from "./taskManagerDiceRoller.js";
1616

@@ -51,7 +51,7 @@ export class TaskSelectionContainerRuntimeFactory extends ModelContainerRuntimeF
5151
/**
5252
* {@inheritDoc ModelContainerRuntimeFactory.containerInitializingFirstTime}
5353
*/
54-
protected async containerInitializingFirstTime(runtime: IContainerRuntime) {
54+
protected async containerInitializingFirstTime(runtime: IContainerRuntime): Promise<void> {
5555
const taskManagerDiceRoller = await runtime.createDataStore(
5656
TaskManagerDiceRollerInstantiationFactory.type,
5757
);
@@ -65,7 +65,10 @@ export class TaskSelectionContainerRuntimeFactory extends ModelContainerRuntimeF
6565
/**
6666
* {@inheritDoc ModelContainerRuntimeFactory.createModel}
6767
*/
68-
protected async createModel(runtime: IContainerRuntime, container: IContainer) {
68+
protected async createModel(
69+
runtime: IContainerRuntime,
70+
container: IContainer,
71+
): Promise<ITaskSelectionAppModel> {
6972
return new TaskSelectionAppModel(
7073
await getDataStoreEntryPoint<IDiceRoller>(runtime, taskManagerDiceId),
7174
await getDataStoreEntryPoint<IDiceRoller>(runtime, oldestClientDiceId),

examples/apps/task-selection/src/oldestClientDiceRoller.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { OldestClientObserver } from "@fluid-experimental/oldest-client-observer
88
import { DataObject, DataObjectFactory } from "@fluidframework/aqueduct/legacy";
99
import { assert } from "@fluidframework/core-utils/legacy";
1010

11-
import { IDiceRoller } from "./interface.js";
11+
import type { IDiceRoller } from "./interface.js";
1212

1313
// The root is map-like, so we'll use this key for storing the value.
1414
const diceValueKey = "diceValue";
@@ -24,15 +24,15 @@ export class OldestClientDiceRoller extends DataObject implements IDiceRoller {
2424
* initializingFirstTime is run only once by the first client to create the DataObject. Here we use it to
2525
* initialize the state of the DataObject.
2626
*/
27-
protected async initializingFirstTime() {
27+
protected async initializingFirstTime(): Promise<void> {
2828
this.root.set(diceValueKey, 1);
2929
}
3030

3131
/**
3232
* hasInitialized is run by each client as they load the DataObject. Here we use it to set up usage of the
3333
* DataObject, by registering an event listener for dice rolls.
3434
*/
35-
protected async hasInitialized() {
35+
protected async hasInitialized(): Promise<void> {
3636
this.root.on("valueChanged", (changed) => {
3737
if (changed.key === diceValueKey) {
3838
// When we see the dice value change, we'll emit the diceRolled event we specified in our interface.
@@ -46,23 +46,23 @@ export class OldestClientDiceRoller extends DataObject implements IDiceRoller {
4646
this.volunteerForAutoRoll();
4747
}
4848

49-
private get oldestClientObserver() {
49+
private get oldestClientObserver(): OldestClientObserver {
5050
assert(this._oldestClientObserver !== undefined, "OldestClientObserver not initialized");
5151
return this._oldestClientObserver;
5252
}
5353

54-
public get value() {
54+
public get value(): number {
5555
const value = this.root.get<number>(diceValueKey);
5656
assert(value !== undefined, "Dice value not initialized");
5757
return value;
5858
}
5959

60-
public readonly roll = () => {
60+
public readonly roll = (): void => {
6161
const rollValue = Math.floor(Math.random() * 6) + 1;
6262
this.root.set(diceValueKey, rollValue);
6363
};
6464

65-
public volunteerForAutoRoll() {
65+
public volunteerForAutoRoll(): void {
6666
if (this.oldestClientObserver.isOldest()) {
6767
// If we're oldest, start the autoroll and watch for loss of oldest.
6868
this.oldestClientObserver.once("lostOldest", () => {
@@ -80,7 +80,7 @@ export class OldestClientDiceRoller extends DataObject implements IDiceRoller {
8080
}
8181
}
8282

83-
private startAutoRollTask() {
83+
private startAutoRollTask(): void {
8484
console.log("Starting autoroll from OldestClientDiceRoller");
8585
if (this.autoRollInterval === undefined) {
8686
this.autoRollInterval = setInterval(() => {
@@ -89,15 +89,15 @@ export class OldestClientDiceRoller extends DataObject implements IDiceRoller {
8989
}
9090
}
9191

92-
private endAutoRollTask() {
92+
private endAutoRollTask(): void {
9393
console.log("Ending autoroll from OldestClientDiceRoller");
9494
if (this.autoRollInterval !== undefined) {
9595
clearInterval(this.autoRollInterval);
9696
this.autoRollInterval = undefined;
9797
}
9898
}
9999

100-
public hasTask() {
100+
public hasTask(): boolean {
101101
return this.oldestClientObserver.isOldest();
102102
}
103103
}

examples/apps/task-selection/src/taskManagerDiceRoller.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
*/
55

66
import { DataObject, DataObjectFactory } from "@fluidframework/aqueduct/legacy";
7-
import { IFluidHandle } from "@fluidframework/core-interfaces";
7+
import type { IFluidHandle } from "@fluidframework/core-interfaces";
88
import { assert } from "@fluidframework/core-utils/legacy";
99
import { TaskManager } from "@fluidframework/task-manager/legacy";
1010

11-
import { IDiceRoller } from "./interface.js";
11+
import type { IDiceRoller } from "./interface.js";
1212

1313
const taskManagerKey = "taskManager";
1414
// The root is map-like, so we'll use this key for storing the value.
@@ -26,7 +26,7 @@ export class TaskManagerDiceRoller extends DataObject implements IDiceRoller {
2626
* initializingFirstTime is run only once by the first client to create the DataObject. Here we use it to
2727
* initialize the state of the DataObject.
2828
*/
29-
protected async initializingFirstTime() {
29+
protected async initializingFirstTime(): Promise<void> {
3030
this.root.set(diceValueKey, 1);
3131

3232
// We create a TaskManager just like any other DDS.
@@ -38,7 +38,7 @@ export class TaskManagerDiceRoller extends DataObject implements IDiceRoller {
3838
* hasInitialized is run by each client as they load the DataObject. Here we use it to set up usage of the
3939
* DataObject, by registering an event listener for dice rolls.
4040
*/
41-
protected async hasInitialized() {
41+
protected async hasInitialized(): Promise<void> {
4242
this.root.on("valueChanged", (changed) => {
4343
if (changed.key === diceValueKey) {
4444
// When we see the dice value change, we'll emit the diceRolled event we specified in our interface.
@@ -52,23 +52,23 @@ export class TaskManagerDiceRoller extends DataObject implements IDiceRoller {
5252
this.subscribeToAutoRoll();
5353
}
5454

55-
private get taskManager() {
55+
private get taskManager(): TaskManager {
5656
assert(this._taskManager !== undefined, "TaskManager not initialized");
5757
return this._taskManager;
5858
}
5959

60-
public get value() {
60+
public get value(): number {
6161
const value = this.root.get<number>(diceValueKey);
6262
assert(value !== undefined, "Dice value not initialized");
6363
return value;
6464
}
6565

66-
public readonly roll = () => {
66+
public readonly roll = (): void => {
6767
const rollValue = Math.floor(Math.random() * 6) + 1;
6868
this.root.set(diceValueKey, rollValue);
6969
};
7070

71-
public subscribeToAutoRoll() {
71+
public subscribeToAutoRoll(): void {
7272
// Subscribe to the auto roll task. This will constantly keep us in queue for the task until we get it. If we
7373
// lose the task assignment we will automatically re-enter queue.
7474

@@ -89,7 +89,7 @@ export class TaskManagerDiceRoller extends DataObject implements IDiceRoller {
8989
this.taskManager.subscribeToTask(autoRollTaskId);
9090
}
9191

92-
private startAutoRollTask() {
92+
private startAutoRollTask(): void {
9393
console.log("Starting autoroll from TaskManagerDiceRoller");
9494
if (this.autoRollInterval === undefined) {
9595
this.autoRollInterval = setInterval(() => {
@@ -98,15 +98,15 @@ export class TaskManagerDiceRoller extends DataObject implements IDiceRoller {
9898
}
9999
}
100100

101-
private endAutoRollTask() {
101+
private endAutoRollTask(): void {
102102
console.log("Ending autoroll from TaskManagerDiceRoller");
103103
if (this.autoRollInterval !== undefined) {
104104
clearInterval(this.autoRollInterval);
105105
this.autoRollInterval = undefined;
106106
}
107107
}
108108

109-
public hasTask() {
109+
public hasTask(): boolean {
110110
return this.taskManager.assigned(autoRollTaskId);
111111
}
112112
}

examples/apps/task-selection/src/view.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* Licensed under the MIT License.
44
*/
55

6-
import { IDiceRoller } from "./interface.js";
6+
import type { IDiceRoller } from "./interface.js";
77

88
/**
99
* Render an IDiceRoller into a given div as a text character, with a button to roll it.
1010
* @param diceRoller - The Data Object to be rendered
1111
* @param div - The div to render into
1212
*/
13-
export function renderDiceRoller(diceRoller: IDiceRoller, div: HTMLDivElement) {
13+
export function renderDiceRoller(diceRoller: IDiceRoller, div: HTMLDivElement): void {
1414
const wrapperDiv = document.createElement("div");
1515
wrapperDiv.style.textAlign = "center";
1616
div.append(wrapperDiv);
@@ -30,15 +30,15 @@ export function renderDiceRoller(diceRoller: IDiceRoller, div: HTMLDivElement) {
3030
wrapperDiv.append(diceCharDiv, rollButton, taskOwnerDiv);
3131

3232
// Get the current value of the shared data to update the view whenever it changes.
33-
const updateDiceChar = () => {
33+
const updateDiceChar = (): void => {
3434
// Unicode 0x2680-0x2685 are the sides of a dice (⚀⚁⚂⚃⚄⚅)
3535
diceCharDiv.textContent = String.fromCodePoint(0x267f + diceRoller.value);
3636
diceCharDiv.style.color = `hsl(${diceRoller.value * 60}, 70%, 50%)`;
3737
};
3838
updateDiceChar();
3939

4040
// Just showing visually whether we're the task owner or not.
41-
const updateTaskOwner = () => {
41+
const updateTaskOwner = (): void => {
4242
taskOwnerDiv.textContent = diceRoller.hasTask() ? "Task owner" : "Not task owner";
4343
};
4444
updateTaskOwner();

0 commit comments

Comments
 (0)