Remove usages of array constructor
TS Style Guide says not to use Array constructor.
https://google.github.io/styleguide/tsguide.html#array-constructor
Google-bug-id: b/260980834
Release-Notes: skip
Change-Id: I6775551aef5da011756a0e6dafbf5423c6484e93
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
index 6c7e661..117abd6 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.ts
@@ -229,7 +229,7 @@
}
private calculateStartIndices(sections: ChangeListSection[]): number[] {
- const startIndices: number[] = new Array(sections.length).fill(0);
+ const startIndices = Array.from<number>({length: sections.length}).fill(0);
for (let i = 1; i < sections.length; ++i) {
startIndices[i] = startIndices[i - 1] + sections[i - 1].results.length;
}
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts
index 7e9735f..e201ab4 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list_test.ts
@@ -141,7 +141,10 @@
});
test('computeRelativeIndex', () => {
- element.sections = [{results: new Array(1)}, {results: new Array(2)}];
+ element.sections = [
+ {results: Array.from({length: 1})},
+ {results: Array.from({length: 2})},
+ ];
let selectedChangeIndex = 0;
assert.equal(
@@ -228,7 +231,10 @@
test('keyboard shortcuts', async () => {
sinon.stub(element, 'computeLabelNames');
- element.sections = [{results: new Array(1)}, {results: new Array(2)}];
+ element.sections = [
+ {results: Array.from({length: 1})},
+ {results: Array.from({length: 2})},
+ ];
element.selectedIndex = 0;
element.preferences = createDefaultPreferences();
element.config = createServerInfo();
@@ -300,7 +306,10 @@
queryAndAssert<HTMLInputElement>(query(item, '.selection'), 'input');
sinon.stub(element, 'computeLabelNames');
- element.sections = [{results: new Array(1)}, {results: new Array(2)}];
+ element.sections = [
+ {results: Array.from({length: 1})},
+ {results: Array.from({length: 2})},
+ ];
element.selectedIndex = 0;
element.preferences = createDefaultPreferences();
element.config = createServerInfo();
diff --git a/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.ts b/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.ts
index c669209..13662982 100644
--- a/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.ts
+++ b/polygerrit-ui/app/elements/change/gr-label-score-row/gr-label-score-row.ts
@@ -168,7 +168,7 @@
// Render blank cells so that all same value votes are aligned
private renderBlankItems(position: string) {
const blankItemCount = this.computeBlankItemsCount(position);
- return new Array(blankItemCount)
+ return Array.from({length: blankItemCount})
.fill('')
.map(
() => html`
diff --git a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list_test.ts b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list_test.ts
index dcaa2d7..ec43aea 100644
--- a/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list_test.ts
+++ b/polygerrit-ui/app/elements/change/gr-messages-list/gr-messages-list_test.ts
@@ -71,7 +71,7 @@
};
function generateRandomMessages(count: number) {
- return new Array(count)
+ return Array.from({length: count})
.fill(undefined)
.map(() => randomMessage()) as ChangeMessageInfo[];
}
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.ts b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.ts
index dd0eecd..427563b 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-host/gr-diff-host_test.ts
@@ -46,7 +46,7 @@
import {GrDiffHost, LineInfo} from './gr-diff-host';
import {DiffInfo, DiffViewMode, IgnoreWhitespaceType} from '../../../api/diff';
import {ErrorCallback} from '../../../api/rest';
-import {SinonStub} from 'sinon';
+import {SinonStub, SinonStubbedMember} from 'sinon';
import {RunResult} from '../../../models/checks/checks-model';
import {GrCommentThread} from '../../shared/gr-comment-thread/gr-comment-thread';
import {assertIsDefined} from '../../../utils/common-util';
@@ -54,11 +54,12 @@
import {testResolver} from '../../../test/common-test-setup';
import {userModelToken, UserModel} from '../../../models/user/user-model';
import {pluginLoaderToken} from '../../shared/gr-js-api-interface/gr-plugin-loader';
+import {RestApiService} from '../../../services/gr-rest-api/gr-rest-api';
suite('gr-diff-host tests', () => {
let element: GrDiffHost;
let account = createAccountDetailWithId(1);
- let getDiffRestApiStub: SinonStub;
+ let getDiffRestApiStub: SinonStubbedMember<RestApiService['getDiff']>;
let userModel: UserModel;
setup(async () => {
@@ -1486,7 +1487,7 @@
...createDiff(),
content: [
{
- a: [new Array(501).join('*')],
+ a: ['*'.repeat(501)],
},
],
})
@@ -1542,7 +1543,7 @@
...createDiff(),
content: [
{
- a: [new Array(501).join('*')],
+ a: ['*'.repeat(501)],
},
],
})
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.ts b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.ts
index e7e1bc8..87ec05b 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.ts
+++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.ts
@@ -51,7 +51,7 @@
import {Side} from '../../../api/diff';
import {Files, GrDiffView} from './gr-diff-view';
import {DropdownItem} from '../../shared/gr-dropdown-list/gr-dropdown-list';
-import {SinonFakeTimers, SinonStub} from 'sinon';
+import {SinonFakeTimers, SinonStub, SinonStubbedMember} from 'sinon';
import {
changeModelToken,
ChangeModel,
@@ -76,6 +76,7 @@
changeViewModelToken,
} from '../../../models/views/change';
import {FileNameToNormalizedFileInfoMap} from '../../../models/change/files-model';
+import {RestApiService} from '../../../services/gr-rest-api/gr-rest-api';
function createComment(
id: string,
@@ -97,7 +98,7 @@
let element: GrDiffView;
let clock: SinonFakeTimers;
let diffCommentsStub;
- let getDiffRestApiStub: SinonStub;
+ let getDiffRestApiStub: SinonStubbedMember<RestApiService['getDiff']>;
let navToChangeStub: SinonStub;
let navToDiffStub: SinonStub;
let navToEditStub: SinonStub;
diff --git a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.ts b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.ts
index cce2840..38f4f17 100644
--- a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.ts
+++ b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view_test.ts
@@ -105,7 +105,7 @@
test('next button', async () => {
element.itemsPerPage = 25;
- element.items = new Array(26);
+ element.items = Array.from({length: 26});
element.loading = false;
await element.updateComplete;
@@ -116,7 +116,7 @@
assert.isFalse(element.hideNextArrow());
element.items = [];
assert.isTrue(element.hideNextArrow());
- element.items = new Array(4);
+ element.items = Array.from({length: 4});
assert.isTrue(element.hideNextArrow());
});
diff --git a/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts b/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts
index f6f7052..5b23ee7 100644
--- a/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts
+++ b/polygerrit-ui/app/embed/diff/gr-diff-processor/gr-diff-processor_test.ts
@@ -135,7 +135,7 @@
element.context = 10;
const content = [
{
- ab: new Array(100).fill(
+ ab: Array.from<string>({length: 100}).fill(
'all work and no play make jack a dull boy'
),
},
@@ -165,9 +165,13 @@
test('at the beginning with skip chunks', async () => {
element.context = 10;
const content = [
- {ab: new Array(20).fill('all work and no play make jack a dull boy')},
+ {
+ ab: Array.from<string>({length: 20}).fill(
+ 'all work and no play make jack a dull boy'
+ ),
+ },
{skip: 43900},
- {ab: new Array(30).fill('some other content')},
+ {ab: Array.from<string>({length: 30}).fill('some other content')},
{a: ['some other content']},
];
@@ -213,7 +217,11 @@
test('at the beginning, smaller than context', () => {
element.context = 10;
const content = [
- {ab: new Array(5).fill('all work and no play make jack a dull boy')},
+ {
+ ab: Array.from<string>({length: 5}).fill(
+ 'all work and no play make jack a dull boy'
+ ),
+ },
{a: ['all work and no play make andybons a dull boy']},
];
@@ -235,7 +243,7 @@
const content = [
{a: ['all work and no play make andybons a dull boy']},
{
- ab: new Array(100).fill(
+ ab: Array.from<string>({length: 100}).fill(
'all work and no play make jill a dull girl'
),
},
@@ -266,7 +274,11 @@
element.context = 10;
const content = [
{a: ['all work and no play make andybons a dull boy']},
- {ab: new Array(5).fill('all work and no play make jill a dull girl')},
+ {
+ ab: Array.from<string>({length: 5}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
];
return element.process(content, false).then(() => {
@@ -287,23 +299,39 @@
element.context = 10;
const content = [
{a: ['all work and no play make andybons a dull boy']},
- {ab: new Array(3).fill('all work and no play make jill a dull girl')},
{
- a: new Array(3).fill('all work and no play make jill a dull girl'),
- b: new Array(3).fill(
+ ab: Array.from<string>({length: 3}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
+ {
+ a: Array.from<string>({length: 3}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ b: Array.from<string>({length: 3}).fill(
' all work and no play make jill a dull girl'
),
common: true,
},
- {ab: new Array(3).fill('all work and no play make jill a dull girl')},
{
- a: new Array(3).fill('all work and no play make jill a dull girl'),
- b: new Array(3).fill(
+ ab: Array.from<string>({length: 3}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
+ {
+ a: Array.from<string>({length: 3}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ b: Array.from<string>({length: 3}).fill(
' all work and no play make jill a dull girl'
),
common: true,
},
- {ab: new Array(3).fill('all work and no play make jill a dull girl')},
+ {
+ ab: Array.from<string>({length: 3}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
];
return element.process(content, false).then(() => {
@@ -387,7 +415,7 @@
const content = [
{a: ['all work and no play make andybons a dull boy']},
{
- ab: new Array(100).fill(
+ ab: Array.from<string>({length: 100}).fill(
'all work and no play make jill a dull girl'
),
},
@@ -425,7 +453,11 @@
element.context = 10;
const content = [
{a: ['all work and no play make andybons a dull boy']},
- {ab: new Array(5).fill('all work and no play make jill a dull girl')},
+ {
+ ab: Array.from<string>({length: 5}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
{a: ['all work and no play make andybons a dull boy']},
];
@@ -448,9 +480,17 @@
element.context = 10;
const content = [
{a: ['all work and no play make andybons a dull boy']},
- {ab: new Array(20).fill('all work and no play make jill a dull girl')},
+ {
+ ab: Array.from<string>({length: 20}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
{skip: 60},
- {ab: new Array(20).fill('all work and no play make jill a dull girl')},
+ {
+ ab: Array.from<string>({length: 20}).fill(
+ 'all work and no play make jill a dull girl'
+ ),
+ },
{a: ['all work and no play make andybons a dull boy']},
];