Skip to content

Commit 17017c4

Browse files
authored
refactor(driver-utils): Promote eslint config from "minimalDeprecated" to "recommended" and fix violations (microsoft#26304)
Part of a larger effort to remove the "minimalDeprecated" configuration. Also adds a missing dev dependency on `@types/lz4js`.
1 parent 5e1efb8 commit 17017c4

35 files changed

+279
-195
lines changed

packages/loader/driver-utils/eslint.config.mts

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

66
import type { Linter } from "eslint";
7-
import { minimalDeprecated } from "../../../common/build/eslint-config-fluid/flat.mts";
7+
import { recommended } from "../../../common/build/eslint-config-fluid/flat.mts";
88

99
const config: Linter.Config[] = [
10-
...minimalDeprecated,
10+
...recommended,
1111
{
1212
rules: {
1313
"import-x/no-nodejs-modules": ["error"],

packages/loader/driver-utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
"@fluidframework/driver-utils-previous": "npm:@fluidframework/driver-utils@2.81.0",
134134
"@fluidframework/eslint-config-fluid": "workspace:~",
135135
"@microsoft/api-extractor": "7.52.11",
136+
"@types/lz4js": "^0.2.0",
136137
"@types/mocha": "^10.0.10",
137138
"@types/node": "~20.19.30",
138139
"@types/sinon": "^17.0.3",

packages/loader/driver-utils/src/adapters/compression/documentServiceCompressionAdapter.ts

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

6-
import {
6+
import type {
77
IDocumentService,
88
IDocumentStorageService,
99
} from "@fluidframework/driver-definitions/internal";
1010

1111
import { DocumentServiceProxy } from "../../documentServiceProxy.js";
1212

13-
import { ICompressionStorageConfig } from "./compressionTypes.js";
13+
import type { ICompressionStorageConfig } from "./compressionTypes.js";
1414
import { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from "./summaryblob/index.js";
1515

1616
export class DocumentServiceCompressionAdapter extends DocumentServiceProxy {

packages/loader/driver-utils/src/adapters/compression/documentServiceFactoryCompressionAdapter.ts

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

6-
import { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7-
import { ISummaryTree } from "@fluidframework/driver-definitions";
8-
import {
6+
import type { ITelemetryBaseLogger } from "@fluidframework/core-interfaces";
7+
import type { ISummaryTree } from "@fluidframework/driver-definitions";
8+
import type {
99
IDocumentService,
1010
IDocumentServiceFactory,
1111
IResolvedUrl,
1212
} from "@fluidframework/driver-definitions/internal";
1313

1414
import { DocumentServiceFactoryProxy } from "../../documentServiceFactoryProxy.js";
1515

16-
import { ICompressionStorageConfig } from "./compressionTypes.js";
16+
import type { ICompressionStorageConfig } from "./compressionTypes.js";
1717
import { DocumentServiceCompressionAdapter } from "./documentServiceCompressionAdapter.js";
1818
import { DocumentStorageServiceCompressionAdapter as DocumentStorageServiceSummaryBlobCompressionAdapter } from "./summaryblob/index.js";
1919

packages/loader/driver-utils/src/adapters/compression/index.ts

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

66
export {
77
SummaryCompressionAlgorithm,
8-
ICompressionStorageConfig,
8+
type ICompressionStorageConfig,
99
DefaultCompressionStorageConfig,
1010
} from "./compressionTypes.js";
1111
export { DocumentServiceFactoryCompressionAdapter } from "./documentServiceFactoryCompressionAdapter.js";

packages/loader/driver-utils/src/adapters/compression/summaryblob/documentStorageServiceSummaryBlobCompressionAdapter.ts

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import { type Buffer, IsoBuffer } from "@fluid-internal/client-utils";
77
import { assert } from "@fluidframework/core-utils/internal";
88
import {
9-
ISummaryBlob,
10-
ISummaryHandle,
11-
ISummaryTree,
12-
SummaryObject,
9+
type ISummaryBlob,
10+
type ISummaryHandle,
11+
type ISummaryTree,
12+
type SummaryObject,
1313
SummaryType,
1414
} from "@fluidframework/driver-definitions";
15-
import {
15+
import type {
1616
IDocumentStorageService,
1717
ISummaryContext,
1818
ISnapshotTree,
@@ -74,10 +74,10 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
7474
* @param blob - The maybe compressed blob.
7575
*/
7676
private static readAlgorithmFromBlob(blob: ArrayBufferLike): number {
77-
return !this.hasPrefix(blob)
78-
? SummaryCompressionAlgorithm.None
79-
: // eslint-disable-next-line no-bitwise
80-
IsoBuffer.from(blob)[0] & 0x0f;
77+
return this.hasPrefix(blob)
78+
? // eslint-disable-next-line no-bitwise
79+
IsoBuffer.from(blob)[0] & 0x0f
80+
: SummaryCompressionAlgorithm.None;
8181
}
8282

8383
/**
@@ -202,7 +202,7 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
202202
} else if (algorithm === SummaryCompressionAlgorithm.None) {
203203
maybeCompressed = file;
204204
} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {
205-
const compressed = compress(file) as ArrayBufferLike;
205+
const compressed = compress(file as Uint8Array) as ArrayBufferLike;
206206
maybeCompressed = compressed;
207207
} else {
208208
throw new Error(`Unknown Algorithm ${config.algorithm}`);
@@ -221,8 +221,9 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
221221
*/
222222
private static decodeBlob(file: ArrayBufferLike): ArrayBufferLike {
223223
let decompressed: ArrayBufferLike;
224-
let originalBlob;
225-
let algorithm;
224+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- TODO: use a real type
225+
let originalBlob: any;
226+
let algorithm: SummaryCompressionAlgorithm;
226227
if (this.hasPrefix(file)) {
227228
algorithm = DocumentStorageServiceCompressionAdapter.readAlgorithmFromBlob(file);
228229
originalBlob = this.removePrefixFromBlobIfPresent(file);
@@ -231,8 +232,10 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
231232
originalBlob = file;
232233
}
233234
if (algorithm === SummaryCompressionAlgorithm.None) {
235+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
234236
decompressed = originalBlob;
235237
} else if (algorithm === SummaryCompressionAlgorithm.LZ4) {
238+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment
236239
decompressed = decompress(originalBlob) as ArrayBufferLike;
237240
} else {
238241
throw new Error(`Unknown Algorithm ${algorithm}`);
@@ -267,12 +270,13 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
267270
}
268271
let clone: object | undefined;
269272
for (const key of Object.keys(input)) {
270-
const value = input[key];
273+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
274+
const value: SummaryObject = input[key];
271275

272276
if (Boolean(value) && typeof value === "object") {
273277
const replaced = this.recursivelyReplace(
274278
isEncode,
275-
value as SummaryObject,
279+
value,
276280
encoder,
277281
decoder,
278282
config,
@@ -396,13 +400,13 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
396400
*/
397401
public override async readBlob(id: string): Promise<ArrayBufferLike> {
398402
const originalBlob = await super.readBlob(id);
399-
if (!this._isCompressionEnabled) {
400-
return originalBlob;
401-
} else {
403+
if (this._isCompressionEnabled) {
402404
const decompressedBlob =
403405
DocumentStorageServiceCompressionAdapter.decodeBlob(originalBlob);
404406
// console.log(`Miso summary-blob Blob read END : ${id} ${decompressedBlob.byteLength}`);
405407
return decompressedBlob;
408+
} else {
409+
return originalBlob;
406410
}
407411
}
408412

@@ -451,14 +455,14 @@ export class DocumentStorageServiceCompressionAdapter extends DocumentStorageSer
451455
*/
452456
public override async downloadSummary(id: ISummaryHandle): Promise<ISummaryTree> {
453457
const summary = await super.downloadSummary(id);
454-
return !this._isCompressionEnabled
455-
? summary
456-
: (DocumentStorageServiceCompressionAdapter.recursivelyReplace(
458+
return this._isCompressionEnabled
459+
? (DocumentStorageServiceCompressionAdapter.recursivelyReplace(
457460
false,
458461
summary,
459462
DocumentStorageServiceCompressionAdapter.blobEncoder,
460463
DocumentStorageServiceCompressionAdapter.blobDecoder,
461464
this._config,
462-
) as ISummaryTree);
465+
) as ISummaryTree)
466+
: summary;
463467
}
464468
}

packages/loader/driver-utils/src/adapters/index.ts

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

66
export {
77
SummaryCompressionAlgorithm,
8-
ICompressionStorageConfig,
8+
type ICompressionStorageConfig,
99
DefaultCompressionStorageConfig,
1010
blobHeadersBlobName,
1111
} from "./compression/index.js";

packages/loader/driver-utils/src/adapters/predefinedAdapters.ts

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

66
import { assert } from "@fluidframework/core-utils/internal";
7-
import { IDocumentServiceFactory } from "@fluidframework/driver-definitions/internal";
7+
import type { IDocumentServiceFactory } from "@fluidframework/driver-definitions/internal";
88

99
import {
1010
DefaultCompressionStorageConfig,
1111
DocumentServiceFactoryCompressionAdapter,
12-
ICompressionStorageConfig,
12+
type ICompressionStorageConfig,
1313
} from "./compression/index.js";
1414

1515
/**
@@ -67,9 +67,12 @@ function applyStorageCompressionInternal(
6767
* This method checks whether given objects contains
6868
* a properties expected for the interface ICompressionStorageConfig.
6969
*/
70-
export function isCompressionConfig(config: any): config is ICompressionStorageConfig {
70+
export function isCompressionConfig(config: unknown): config is ICompressionStorageConfig {
7171
return (
7272
config !== undefined &&
73-
(config.algorithm !== undefined || config.minSizeToCompress !== undefined)
73+
typeof config === "object" &&
74+
config !== null &&
75+
((config as Partial<ICompressionStorageConfig>).algorithm !== undefined ||
76+
(config as Partial<ICompressionStorageConfig>).minSizeToCompress !== undefined)
7477
);
7578
}

packages/loader/driver-utils/src/blob.ts

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

6-
import {
7-
FileMode,
8-
IAttachment,
9-
IBlob,
10-
ITree,
11-
TreeEntry,
12-
} from "@fluidframework/driver-definitions/internal";
6+
import type { IAttachment, IBlob, ITree } from "@fluidframework/driver-definitions/internal";
7+
import { FileMode, TreeEntry } from "@fluidframework/driver-definitions/internal";
138

149
/**
1510
* Basic implementation of a blob ITreeEntry
@@ -29,6 +24,7 @@ export class BlobTreeEntry {
2924
constructor(
3025
public readonly path: string,
3126
contents: string,
27+
// eslint-disable-next-line unicorn/text-encoding-identifier-case
3228
encoding: "utf-8" | "base64" = "utf-8",
3329
) {
3430
this.value = { contents, encoding };

packages/loader/driver-utils/src/buildSnapshotTree.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { stringToBuffer } from "@fluid-internal/client-utils";
77
import { assert } from "@fluidframework/core-utils/internal";
88
import {
99
FileMode,
10-
IGitTree,
11-
IGitTreeEntry,
12-
ISnapshotTree,
13-
ITreeEntry,
10+
type IGitTree,
11+
type IGitTreeEntry,
12+
type ISnapshotTree,
13+
type ITreeEntry,
1414
TreeEntry,
1515
} from "@fluidframework/driver-definitions/internal";
1616
import { v4 as uuid } from "uuid";
@@ -33,7 +33,7 @@ function flattenCore(
3333
blobMap.set(id, buffer);
3434

3535
const entry: IGitTreeEntry = {
36-
mode: FileMode[treeEntry.mode],
36+
mode: FileMode[treeEntry.mode] as string,
3737
path: subPath,
3838
sha: id,
3939
size: 0,
@@ -48,7 +48,7 @@ function flattenCore(
4848
);
4949
const t = treeEntry.value;
5050
const entry: IGitTreeEntry = {
51-
mode: FileMode[treeEntry.mode],
51+
mode: FileMode[treeEntry.mode] as string,
5252
path: subPath,
5353
sha: "",
5454
size: -1,

0 commit comments

Comments
 (0)