Skip to content

refactor(framework): Update eslint config in packages/framework/dds-interceptions to extend "recommended" base config #24806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2025
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
5 changes: 1 addition & 4 deletions packages/framework/dds-interceptions/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
*/

module.exports = {
extends: [
require.resolve("@fluidframework/eslint-config-fluid/minimal-deprecated"),
"prettier",
],
extends: [require.resolve("@fluidframework/eslint-config-fluid/recommended"), "prettier"],
parserOptions: {
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ function createSubDirectoryWithInterception<T extends IDirectory>(
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value: any,
value: unknown,
) => void,
): T {
const subDirectoryWithInterception = Object.create(subDirectory);
const subDirectoryWithInterception = Object.create(subDirectory) as T;

// executingCallback keeps track of whether set is called recursively from the setInterceptionCallback.
let executingCallback: boolean = false;

subDirectoryWithInterception.set = (key: string, value: any) => {
subDirectoryWithInterception.set = (key: string, value: unknown) => {
let directory;
// Set should not be called on the wrapped object from the interception callback as this will lead to
// infinite recursion.
Expand Down Expand Up @@ -162,7 +162,7 @@ export function createDirectoryWithInterception<T extends IDirectory>(
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value: any,
value: unknown,
) => void,
): T {
return createSubDirectoryWithInterception(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import { IFluidDataStoreContext } from "@fluidframework/runtime-definitions/inte
export function createSharedMapWithInterception(
sharedMap: ISharedMap,
context: IFluidDataStoreContext,
setInterceptionCallback: (sharedMap: ISharedMap, key: string, value: any) => void,
setInterceptionCallback: (sharedMap: ISharedMap, key: string, value: unknown) => void,
): ISharedMap {
const sharedMapWithInterception = Object.create(sharedMap);
const sharedMapWithInterception = Object.create(sharedMap) as ISharedMap;

// executingCallback keeps track of whether set is called recursively from the setInterceptionCallback.
let executingCallback: boolean = false;

sharedMapWithInterception.set = (key: string, value: any) => {
sharedMapWithInterception.set = (key: string, value: unknown) => {
let map;
// Set should not be called on the wrapped object from the interception callback as this will lead to
// infinite recursion.
Expand All @@ -54,5 +54,5 @@ export function createSharedMapWithInterception(
return map;
};

return sharedMapWithInterception as ISharedMap;
return sharedMapWithInterception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function createSharedStringWithInterception(
context: IFluidDataStoreContext,
propertyInterceptionCallback: (props?: MergeTree.PropertySet) => MergeTree.PropertySet,
): SharedString {
const sharedStringWithInterception = Object.create(sharedString);
const sharedStringWithInterception = Object.create(sharedString) as SharedString;

// executingCallback keeps track of whether a method on this wrapper object is called recursively
// from the propertyInterceptionCallback.
Expand Down Expand Up @@ -284,5 +284,5 @@ export function createSharedStringWithInterception(
});
};

return sharedStringWithInterception as SharedString;
return sharedStringWithInterception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { strict as assert } from "assert";
import { strict as assert } from "node:assert";

import {
IDirectory,
Expand All @@ -20,12 +20,12 @@ describe("Shared Directory with Interception", () => {
const userAttributes = { userId: "Fake User" };
const documentId = "fakeId";
const attributionDirectoryName = "attribution";
const attributionKey = (key: string) => `${key}.attribution`;
const attributionKey = (key: string): string => `${key}.attribution`;
let sharedDirectory: ISharedDirectory;
let dataStoreContext: IFluidDataStoreContext;

// This function gets / creates the attribution directory for the given subdirectory path.
function getAttributionDirectory(root: IDirectory, path: string) {
function getAttributionDirectory(root: IDirectory, path: string): IDirectory {
if (!root.hasSubDirectory(attributionDirectoryName)) {
root.createSubDirectory(attributionDirectoryName);
}
Expand All @@ -37,7 +37,7 @@ describe("Shared Directory with Interception", () => {
}

let prevSubDir = currentSubDir;
const subdirs = path.substr(1).split("/");
const subdirs = path.slice(1).split("/");
for (const subdir of subdirs) {
currentSubDir = currentSubDir.getSubDirectory(subdir);
if (currentSubDir === undefined) {
Expand All @@ -58,7 +58,7 @@ describe("Shared Directory with Interception", () => {
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value: any,
value: unknown,
): void {
const attributionDirectory: IDirectory = getAttributionDirectory(
baseDirectory,
Expand All @@ -76,7 +76,7 @@ describe("Shared Directory with Interception", () => {
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value: any,
value: unknown,
): void {
if (!subDirectory.hasSubDirectory(attributionDirectoryName)) {
subDirectory.createSubDirectory(attributionDirectoryName);
Expand All @@ -91,7 +91,7 @@ describe("Shared Directory with Interception", () => {
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value: any,
value: unknown,
): void {
subDirectory.set(attributionKey(key), userAttributes);
}
Expand All @@ -118,8 +118,8 @@ describe("Shared Directory with Interception", () => {
directory: IDirectory,
key: string,
value: string,
props?: any,
) {
props?: unknown,
): void {
assert.equal(
directory.get(key),
value,
Expand Down Expand Up @@ -149,8 +149,8 @@ describe("Shared Directory with Interception", () => {
directory: IDirectory,
key: string,
value: string,
props?: any,
) {
props?: unknown,
): void {
assert.equal(
directory.get(key),
value,
Expand Down Expand Up @@ -352,8 +352,13 @@ describe("Shared Directory with Interception", () => {
const userEmail = "test@microsoft.com";

// Interception callback for wrapping the subdirectory that adds user email to the attribution.
function interceptionCb(baseDirectory, subDirectory, key, value) {
const attributes = subDirectory.get(attributionKey(key));
function interceptionCb(
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value,
): void {
const attributes = subDirectory.get(attributionKey(key)) as IDirectory;
subDirectory.set(attributionKey(key), { ...attributes, userEmail });
}
const fooWithAttribution = createDirectoryWithInterception(
Expand Down Expand Up @@ -409,7 +414,12 @@ describe("Shared Directory with Interception", () => {
// If useWrapper above is true, this interception callback that calls a set on the wrapped object
// causing an infinite recursion.
// If useWrapper is false, it uses the passed subDirectory which does not cause recursion.
function recursiveInterceptionCb(baseDirectory, subDirectory, key, value) {
function recursiveInterceptionCb(
baseDirectory: IDirectory,
subDirectory: IDirectory,
key: string,
value: unknown,
): void {
const directory = useWrapper ? sharedDirectoryWithInterception : subDirectory;
directory.set(attributionKey(key), userAttributes);
}
Expand All @@ -425,9 +435,9 @@ describe("Shared Directory with Interception", () => {
let asserted: boolean = false;
try {
sharedDirectoryWithInterception.set("color", "green");
} catch (error: any) {
} catch (error: unknown) {
assert.strictEqual(
error.message,
(error as Error).message,
"0x0bf",
"We should have caught an assert in replaceText because it detects an infinite recursion",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { strict as assert } from "assert";
import { strict as assert } from "node:assert";

import { ISharedMap, SharedMap } from "@fluidframework/map/internal";
import { IFluidDataStoreContext } from "@fluidframework/runtime-definitions/internal";
Expand All @@ -20,15 +20,15 @@ describe("Shared Map with Interception", () => {
*/
const userAttributes = { userId: "Fake User" };
const documentId = "fakeId";
const attributionKey = (key: string) => `${key}.attribution`;
const attributionKey = (key: string): string => `${key}.attribution`;
let sharedMap: ISharedMap;
let dataStoreContext: IFluidDataStoreContext;

function orderSequentially(callback: () => void): void {
callback();
}

function interceptionCb(map: ISharedMap, key: string, value: any): void {
function interceptionCb(map: ISharedMap, key: string, value: unknown): void {
map.set(attributionKey(key), userAttributes);
}

Expand All @@ -46,7 +46,12 @@ describe("Shared Map with Interception", () => {

// Verifies that the props are stored correctly in the given map under a key derived from the
// given key - under attributionKey(key).
function verifyMapAttribution(map: ISharedMap, key: string, value: string, props?: any) {
function verifyMapAttribution(
map: ISharedMap,
key: string,
value: string,
props?: unknown,
): void {
assert.equal(
map.get(key),
value,
Expand Down Expand Up @@ -117,7 +122,7 @@ describe("Shared Map with Interception", () => {
// If useWrapper above is true, this interception callback that calls a set on the wrapped object
// causing an infinite recursion.
// If useWrapper is false, it uses the passed sharedMap which does not cause recursion.
function recursiveInterceptionCb(map: ISharedMap, key: string, value: any) {
function recursiveInterceptionCb(map: ISharedMap, key: string, value: unknown): void {
const localMap = useWrapper ? sharedMapWithInterception : sharedMap;
localMap.set(attributionKey(key), userAttributes);
}
Expand All @@ -132,9 +137,9 @@ describe("Shared Map with Interception", () => {
let asserted: boolean = false;
try {
sharedMapWithInterception.set("color", "green");
} catch (error: any) {
} catch (error: unknown) {
assert.strictEqual(
error.message,
(error as Error).message,
"0x0c0",
"We should have caught an assert in replaceText because it detects an infinite recursion",
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { strict as assert } from "assert";
import { strict as assert } from "node:assert";

import { PropertySet } from "@fluidframework/merge-tree/internal";
import { IFluidDataStoreContext } from "@fluidframework/runtime-definitions/internal";
Expand Down Expand Up @@ -41,7 +41,7 @@ describe("Shared String with Interception", () => {
text: string,
props: PropertySet,
position: number,
) {
): void {
assert.equal(ss.getText(), text, "The retrieved text should match the inserted text");
assert.deepEqual(
{ ...ss.getPropertiesAtPosition(position) },
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("Shared String with Interception", () => {
// If useWrapper above is true, this interception callback calls a method on the wrapped object
// causing an infinite recursion.
// If useWrapper is false, it uses the passed shared string which does not cause recursion.
function recursiveInterceptionCb(properties?: PropertySet) {
function recursiveInterceptionCb(properties?: PropertySet): PropertySet {
const ss = useWrapper ? sharedStringWithInterception : sharedString;
ss.annotateRange(0, 1, propsInRecursiveCb);
return { ...properties, ...userAttributes };
Expand All @@ -197,9 +197,9 @@ describe("Shared String with Interception", () => {
text = "abc";
// Try to replace text.
sharedStringWithInterception.replaceText(1, 2, text);
} catch (error: any) {
} catch (error: unknown) {
assert.strictEqual(
error.message,
(error as Error).message,
"0x0c8",
"We should have caught an assert in replaceText because it detects an infinite recursion",
);
Expand Down
Loading