Skip to content

Commit 65a063d

Browse files
Brian M Huntclaude
authored andcommitted
Apply Biome formatting and safe lint fixes
Format all files with Biome (matches Prettier settings). Safe auto-fixes applied by `biome check --fix`: unused imports removed, unused variables prefixed, getter returns made explicit, switch fallthroughs annotated. Skipped unsafe fixes (useLiteralKeys, useOptionalChain, useTemplate) as they surface latent type errors when converting bracket to dot notation. Disabled organizeImports (reorders break TS inference in some files). All 2679 tests pass, tsc 0 errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 993ea2d commit 65a063d

135 files changed

Lines changed: 18298 additions & 16846 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

builds/knockout/helpers/mocha-test-helpers.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ function detectIEVersion() {
4949
const div = document.createElement('div')
5050
const iElems = div.getElementsByTagName('i')
5151

52-
while ((div.innerHTML = '<!--[if gt IE ' + ++version + ']><i></i><![endif]-->'), iElems[0]) {}
52+
while (((div.innerHTML = '<!--[if gt IE ' + ++version + ']><i></i><![endif]-->'), iElems[0])) {}
5353
return version > 4 ? version : undefined
5454
}
5555

5656
function expectEqualOneOf(actual, expectedPossibilities) {
57-
const matches = expectedPossibilities.some(function (expected) { return chai.util.eql(actual, expected) })
57+
const matches = expectedPossibilities.some(function (expected) {
58+
return chai.util.eql(actual, expected)
59+
})
5860
expect(matches, 'expected value to deeply equal one of the provided possibilities').to.equal(true)
5961
}
6062

@@ -93,18 +95,31 @@ function expectHaveTexts(actual, expectedTexts) {
9395
}
9496

9597
function expectHaveValues(actual, expectedValues) {
96-
const values = ko.utils.arrayFilter(ko.utils.arrayMap(actual.childNodes, function (node) { return node.value }), function (value) { return value !== undefined })
98+
const values = ko.utils.arrayFilter(
99+
ko.utils.arrayMap(actual.childNodes, function (node) {
100+
return node.value
101+
}),
102+
function (value) {
103+
return value !== undefined
104+
}
105+
)
97106
expect(values).to.deep.equal(expectedValues)
98107
}
99108

100109
function expectHaveCheckedStates(actual, expectedValues) {
101-
const values = ko.utils.arrayMap(actual.childNodes, function (node) { return node.checked })
110+
const values = ko.utils.arrayMap(actual.childNodes, function (node) {
111+
return node.checked
112+
})
102113
expect(values).to.deep.equal(expectedValues)
103114
}
104115

105116
function expectHaveSelectedValues(actual, expectedValues) {
106-
const selectedNodes = ko.utils.arrayFilter(actual.childNodes, function (node) { return node.selected })
107-
const selectedValues = ko.utils.arrayMap(selectedNodes, function (node) { return ko.selectExtensions.readValue(node) })
117+
const selectedNodes = ko.utils.arrayFilter(actual.childNodes, function (node) {
118+
return node.selected
119+
})
120+
const selectedValues = ko.utils.arrayMap(selectedNodes, function (node) {
121+
return ko.selectExtensions.readValue(node)
122+
})
108123
expect(selectedValues).to.deep.equal(expectedValues)
109124
}
110125

Lines changed: 101 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,111 @@
1+
describe('Compare Arrays', function () {
2+
it('Should recognize when two arrays have the same contents', function () {
3+
var subject = ['A', {}, function () {}]
4+
var compareResult = ko.utils.compareArrays(subject, subject.slice(0))
15

2-
describe('Compare Arrays', function() {
3-
it('Should recognize when two arrays have the same contents', function () {
4-
var subject = ["A", {}, function () { } ];
5-
var compareResult = ko.utils.compareArrays(subject, subject.slice(0));
6+
expect(compareResult.length).to.deep.equal(subject.length)
7+
for (var i = 0; i < subject.length; i++) {
8+
expect(compareResult[i].status).to.deep.equal('retained')
9+
expect(compareResult[i].value).to.deep.equal(subject[i])
10+
}
11+
})
612

7-
expect(compareResult.length).to.deep.equal(subject.length);
8-
for (var i = 0; i < subject.length; i++) {
9-
expect(compareResult[i].status).to.deep.equal("retained");
10-
expect(compareResult[i].value).to.deep.equal(subject[i]);
11-
}
12-
});
13+
it('Should recognize added items', function () {
14+
var oldArray = ['A', 'B']
15+
var newArray = ['A', 'A2', 'A3', 'B', 'B2']
16+
var compareResult = ko.utils.compareArrays(oldArray, newArray)
17+
expect(compareResult).to.deep.equal([
18+
{ status: 'retained', value: 'A' },
19+
{ status: 'added', value: 'A2', index: 1 },
20+
{ status: 'added', value: 'A3', index: 2 },
21+
{ status: 'retained', value: 'B' },
22+
{ status: 'added', value: 'B2', index: 4 }
23+
])
24+
})
1325

14-
it('Should recognize added items', function () {
15-
var oldArray = ["A", "B"];
16-
var newArray = ["A", "A2", "A3", "B", "B2"];
17-
var compareResult = ko.utils.compareArrays(oldArray, newArray);
18-
expect(compareResult).to.deep.equal([
19-
{ status: "retained", value: "A" },
20-
{ status: "added", value: "A2", index: 1 },
21-
{ status: "added", value: "A3", index: 2 },
22-
{ status: "retained", value: "B" },
23-
{ status: "added", value: "B2", index: 4 }
24-
]);
25-
});
26+
it('Should recognize deleted items', function () {
27+
var oldArray = ['A', 'B', 'C', 'D', 'E']
28+
var newArray = ['B', 'C', 'E']
29+
var compareResult = ko.utils.compareArrays(oldArray, newArray)
30+
expect(compareResult).to.deep.equal([
31+
{ status: 'deleted', value: 'A', index: 0 },
32+
{ status: 'retained', value: 'B' },
33+
{ status: 'retained', value: 'C' },
34+
{ status: 'deleted', value: 'D', index: 3 },
35+
{ status: 'retained', value: 'E' }
36+
])
37+
})
2638

27-
it('Should recognize deleted items', function () {
28-
var oldArray = ["A", "B", "C", "D", "E"];
29-
var newArray = ["B", "C", "E"];
30-
var compareResult = ko.utils.compareArrays(oldArray, newArray);
31-
expect(compareResult).to.deep.equal([
32-
{ status: "deleted", value: "A", index: 0 },
33-
{ status: "retained", value: "B" },
34-
{ status: "retained", value: "C" },
35-
{ status: "deleted", value: "D", index: 3 },
36-
{ status: "retained", value: "E" }
37-
]);
38-
});
39+
it('Should recognize mixed edits', function () {
40+
var oldArray = ['A', 'B', 'C', 'D', 'E']
41+
var newArray = [123, 'A', 'E', 'C', 'D']
42+
var compareResult = ko.utils.compareArrays(oldArray, newArray)
43+
expect(compareResult).to.deep.equal([
44+
{ status: 'added', value: 123, index: 0 },
45+
{ status: 'retained', value: 'A' },
46+
{ status: 'deleted', value: 'B', index: 1 },
47+
{ status: 'added', value: 'E', index: 2, moved: 4 },
48+
{ status: 'retained', value: 'C' },
49+
{ status: 'retained', value: 'D' },
50+
{ status: 'deleted', value: 'E', index: 4, moved: 2 }
51+
])
52+
})
3953

40-
it('Should recognize mixed edits', function () {
41-
var oldArray = ["A", "B", "C", "D", "E"];
42-
var newArray = [123, "A", "E", "C", "D"];
43-
var compareResult = ko.utils.compareArrays(oldArray, newArray);
44-
expect(compareResult).to.deep.equal([
45-
{ status: "added", value: 123, index: 0 },
46-
{ status: "retained", value: "A" },
47-
{ status: "deleted", value: "B", index: 1 },
48-
{ status: "added", value: "E", index: 2, moved: 4 },
49-
{ status: "retained", value: "C" },
50-
{ status: "retained", value: "D" },
51-
{ status: "deleted", value: "E", index: 4, moved: 2 }
52-
]);
53-
});
54+
it('Should recognize replaced array', function () {
55+
var oldArray = ['A', 'B', 'C', 'D', 'E']
56+
var newArray = ['F', 'G', 'H', 'I', 'J']
57+
var compareResult = ko.utils.compareArrays(oldArray, newArray)
58+
// The ordering of added/deleted items for replaced entries isn't defined, so
59+
// we'll sort the results first to ensure the results are in a known order for verification.
60+
compareResult.sort(function (a, b) {
61+
return a.index - b.index || a.status.localeCompare(b.status)
62+
})
63+
expect(compareResult).to.deep.equal([
64+
{ status: 'added', value: 'F', index: 0 },
65+
{ status: 'deleted', value: 'A', index: 0 },
66+
{ status: 'added', value: 'G', index: 1 },
67+
{ status: 'deleted', value: 'B', index: 1 },
68+
{ status: 'added', value: 'H', index: 2 },
69+
{ status: 'deleted', value: 'C', index: 2 },
70+
{ status: 'added', value: 'I', index: 3 },
71+
{ status: 'deleted', value: 'D', index: 3 },
72+
{ status: 'added', value: 'J', index: 4 },
73+
{ status: 'deleted', value: 'E', index: 4 }
74+
])
75+
})
5476

55-
it('Should recognize replaced array', function () {
56-
var oldArray = ["A", "B", "C", "D", "E"];
57-
var newArray = ["F", "G", "H", "I", "J"];
58-
var compareResult = ko.utils.compareArrays(oldArray, newArray);
59-
// The ordering of added/deleted items for replaced entries isn't defined, so
60-
// we'll sort the results first to ensure the results are in a known order for verification.
61-
compareResult.sort(function(a, b) { return (a.index - b.index) || a.status.localeCompare(b.status); });
62-
expect(compareResult).to.deep.equal([
63-
{ status : 'added', value : 'F', index : 0 },
64-
{ status : 'deleted', value : 'A', index : 0 },
65-
{ status : 'added', value : 'G', index : 1 },
66-
{ status : 'deleted', value : 'B', index : 1 },
67-
{ status : 'added', value : 'H', index : 2 },
68-
{ status : 'deleted', value : 'C', index : 2 },
69-
{ status : 'added', value : 'I', index : 3 },
70-
{ status : 'deleted', value : 'D', index : 3 },
71-
{ status : 'added', value : 'J', index : 4 },
72-
{ status : 'deleted', value : 'E', index : 4 }
73-
]);
74-
});
77+
it('Should support sparse diffs', function () {
78+
// A sparse diff is exactly like a regular diff, except it doesn't contain any
79+
// 'retained' items. This still preserves enough information for most things
80+
// you'd want to do with the changeset.
7581

76-
it('Should support sparse diffs', function() {
77-
// A sparse diff is exactly like a regular diff, except it doesn't contain any
78-
// 'retained' items. This still preserves enough information for most things
79-
// you'd want to do with the changeset.
82+
var oldArray = ['A', 'B', 'C', 'D', 'E']
83+
var newArray = [123, 'A', 'E', 'C', 'D']
84+
var compareResult = ko.utils.compareArrays(oldArray, newArray, { sparse: true })
85+
expect(compareResult).to.deep.equal([
86+
{ status: 'added', value: 123, index: 0 },
87+
{ status: 'deleted', value: 'B', index: 1 },
88+
{ status: 'added', value: 'E', index: 2, moved: 4 },
89+
{ status: 'deleted', value: 'E', index: 4, moved: 2 }
90+
])
91+
})
8092

81-
var oldArray = ["A", "B", "C", "D", "E"];
82-
var newArray = [123, "A", "E", "C", "D"];
83-
var compareResult = ko.utils.compareArrays(oldArray, newArray, { sparse: true });
84-
expect(compareResult).to.deep.equal([
85-
{ status: "added", value: 123, index: 0 },
86-
{ status: "deleted", value: "B", index: 1 },
87-
{ status: "added", value: "E", index: 2, moved: 4 },
88-
{ status: "deleted", value: "E", index: 4, moved: 2 }
89-
]);
90-
});
93+
it('Should honor "dontLimitMoves" option', function () {
94+
// In order to test this, we must have a scenario in which a move is not recognized as such without the option.
95+
// This scenario doesn't represent the definition of the spec itself and may need to be modified if the move
96+
// detection algorithm in Knockout is changed.
97+
var oldArray = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T']
98+
var newArray = [1, 2, 3, 4, 'T', 6, 7, 8, 9, 10]
9199

92-
it('Should honor "dontLimitMoves" option', function() {
93-
// In order to test this, we must have a scenario in which a move is not recognized as such without the option.
94-
// This scenario doesn't represent the definition of the spec itself and may need to be modified if the move
95-
// detection algorithm in Knockout is changed.
96-
var oldArray = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T"];
97-
var newArray = [1, 2, 3, 4, "T", 6, 7, 8, 9, 10];
100+
var compareResult = ko.utils.compareArrays(oldArray, newArray)
101+
expect(compareResult[compareResult.length - 1]).to.deep.equal({ status: 'deleted', value: 'T', index: 19 })
98102

99-
var compareResult = ko.utils.compareArrays(oldArray, newArray);
100-
expect(compareResult[compareResult.length-1]).to.deep.equal({ status: 'deleted', value: 'T', index: 19 });
101-
102-
compareResult = ko.utils.compareArrays(oldArray, newArray, { dontLimitMoves: true });
103-
expect(compareResult[compareResult.length-1]).to.deep.equal({ status: 'deleted', value: 'T', index: 19, moved: 4 });
104-
});
105-
});
103+
compareResult = ko.utils.compareArrays(oldArray, newArray, { dontLimitMoves: true })
104+
expect(compareResult[compareResult.length - 1]).to.deep.equal({
105+
status: 'deleted',
106+
value: 'T',
107+
index: 19,
108+
moved: 4
109+
})
110+
})
111+
})

0 commit comments

Comments
 (0)