-
Notifications
You must be signed in to change notification settings - Fork 535
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
eslint(container-loader): Prefix container-loader before enabling no-unchecked-record-access #23423
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,14 +67,15 @@ describe("Dehydrate Container", () => { | |
|
||
assert.strictEqual(Object.keys(baseSnapshot.trees).length, 2, "2 trees should be there"); | ||
assert.strictEqual( | ||
Object.keys(baseSnapshot.trees[".protocol"].blobs).length, | ||
Object.keys(baseSnapshot.trees[".protocol"]?.blobs).length, | ||
2, | ||
"2 protocol blobs should be there.", | ||
); | ||
|
||
// Validate the ".component" blob. | ||
const defaultDataStoreBlobId = baseSnapshot.trees.default.blobs[".component"]; | ||
const defaultDataStoreBlob = snapshotBlobs[defaultDataStoreBlobId]; | ||
const defaultDataStoreBlobId: string | undefined = | ||
baseSnapshot.trees.default?.blobs[".component"]; | ||
const defaultDataStoreBlob: string | undefined = snapshotBlobs[defaultDataStoreBlobId]; | ||
assert.strict(defaultDataStoreBlob, "defaultDataStoreBlob undefined"); | ||
assert.strictEqual( | ||
JSON.parse(defaultDataStoreBlob), | ||
|
@@ -83,37 +84,38 @@ describe("Dehydrate Container", () => { | |
); | ||
|
||
// Validate "root" sub-tree. | ||
const rootAttributesBlobId = baseSnapshot.trees.default.trees.root.blobs.attributes; | ||
const rootAttributesBlob = snapshotBlobs[rootAttributesBlobId]; | ||
const rootAttributesBlobId: string | undefined = | ||
baseSnapshot.trees.default.trees.root?.blobs.attributes; | ||
const rootAttributesBlob: string | undefined = snapshotBlobs[rootAttributesBlobId]; | ||
assert.strict(rootAttributesBlob, "rootAttributesBlob undefined"); | ||
assert.strictEqual( | ||
JSON.parse(rootAttributesBlob), | ||
"rootattributes", | ||
"The root sub-tree's content is incorrect", | ||
); | ||
assert.strictEqual( | ||
baseSnapshot.trees.default.trees.root.unreferenced, | ||
baseSnapshot.trees.default?.trees.root?.unreferenced, | ||
Comment on lines
-95
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RishhiB, what do this and other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe its because baseSnapshot.trees is of type [path: string]: ISnapshotTree, so default or root record access may not exist |
||
undefined, | ||
"The root sub-tree should not be marked as unreferenced", | ||
); | ||
|
||
// Validate "unref" sub-tree. | ||
assert.strictEqual( | ||
baseSnapshot.trees.default.trees.unref.unreferenced, | ||
baseSnapshot.trees.default?.trees.unref?.unreferenced, | ||
true, | ||
"The unref sub-tree should be marked as unreferenced", | ||
); | ||
|
||
// Validate "groupId" sub-tree. | ||
assert.strictEqual( | ||
baseSnapshot.trees.default.trees.groupId.groupId, | ||
baseSnapshot.trees.default?.trees.groupId?.groupId, | ||
"group", | ||
"The groupId sub-tree should have a groupId", | ||
); | ||
|
||
// Validate "groupId" sub-tree. | ||
assert.strictEqual( | ||
baseSnapshot.trees.default.trees.groupId.groupId, | ||
baseSnapshot.trees.default?.trees.groupId?.groupId, | ||
"group", | ||
"The groupId sub-tree should have a groupId", | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this pattern isn't actually working for us.
JSON.parse
does not acceptundefined
. It only acceptsstring
.If you hover on
attributes
on line 160 in VS Code, it will say the type isstring
. TypeScript appears to ignore the explicit type when it thinks it can successfully narrow the type to something more specific.It doesn't look like we can use this pattern to be safe. (It might be okay if the linter followed the uses of the variables to double check typing. I would guess that is pretty hard.)