Skip to content

Commit d2ea0b8

Browse files
crisbetojelbourn
authored andcommitted
build: Object.assign linting not working (#17733)
A long time ago we decided to ban uses of `Object.assign` because of some issues in g3, but the way we wrote it for the `ban` lint rule meant that it wouldn't be caught. These changes tweak the syntax and fix the cases that are being caught now.
1 parent 37015ac commit d2ea0b8

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

src/material-experimental/mdc-chips/chip-grid.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,8 @@ describe('MDC-based MatChipGrid', () => {
565565
dispatchMouseEvent(chipRemoveDebugElements[2].nativeElement, 'click');
566566
fixture.detectChanges();
567567

568-
const fakeEvent = Object.assign(createFakeEvent('transitionend'), {propertyName: 'width'});
568+
const fakeEvent = createFakeEvent('transitionend');
569+
(fakeEvent as any).propertyName = 'width';
569570
chipElements[2].nativeElement.dispatchEvent(fakeEvent);
570571

571572
fixture.detectChanges();
@@ -729,7 +730,8 @@ describe('MDC-based MatChipGrid', () => {
729730
chip.focus();
730731
dispatchKeyboardEvent(chip, 'keydown', BACKSPACE);
731732
fixture.detectChanges();
732-
const fakeEvent = Object.assign(createFakeEvent('transitionend'), {propertyName: 'width'});
733+
const fakeEvent = createFakeEvent('transitionend');
734+
(fakeEvent as any).propertyName = 'width';
733735
chip.dispatchEvent(fakeEvent);
734736
fixture.detectChanges();
735737
tick();

src/material-experimental/mdc-chips/chip-remove.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ describe('MDC-based Chip Remove', () => {
5959
buttonElement.click();
6060
fixture.detectChanges();
6161

62-
const fakeEvent = Object.assign(createFakeEvent('transitionend'), {propertyName: 'width'});
62+
const fakeEvent = createFakeEvent('transitionend');
63+
(fakeEvent as any).propertyName = 'width';
6364
chipNativeElement.dispatchEvent(fakeEvent);
6465

6566
expect(testChip.didRemove).toHaveBeenCalled();

src/material-experimental/mdc-chips/chip-row.spec.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ describe('MDC-based Row Chips', () => {
9494
chipInstance.remove();
9595
fixture.detectChanges();
9696

97-
const fakeEvent = Object.assign(createFakeEvent('transitionend'), {propertyName: 'width'});
97+
const fakeEvent = createFakeEvent('transitionend');
98+
(fakeEvent as any).propertyName = 'width';
9899
chipNativeElement.dispatchEvent(fakeEvent);
99100

100101
expect(testComponent.chipRemove).toHaveBeenCalledWith({chip: chipInstance});
@@ -123,8 +124,8 @@ describe('MDC-based Row Chips', () => {
123124
chipInstance._keydown(DELETE_EVENT);
124125
fixture.detectChanges();
125126

126-
const fakeEvent = Object.assign(createFakeEvent('transitionend'),
127-
{propertyName: 'width'});
127+
const fakeEvent = createFakeEvent('transitionend');
128+
(fakeEvent as any).propertyName = 'width';
128129
chipNativeElement.dispatchEvent(fakeEvent);
129130

130131
expect(testComponent.chipRemove).toHaveBeenCalled();
@@ -138,8 +139,8 @@ describe('MDC-based Row Chips', () => {
138139
chipInstance._keydown(BACKSPACE_EVENT);
139140
fixture.detectChanges();
140141

141-
const fakeEvent = Object.assign(createFakeEvent('transitionend'),
142-
{propertyName: 'width'});
142+
const fakeEvent = createFakeEvent('transitionend');
143+
(fakeEvent as any).propertyName = 'width';
143144
chipNativeElement.dispatchEvent(fakeEvent);
144145

145146
expect(testComponent.chipRemove).toHaveBeenCalled();
@@ -160,8 +161,8 @@ describe('MDC-based Row Chips', () => {
160161
chipInstance._keydown(DELETE_EVENT);
161162
fixture.detectChanges();
162163

163-
const fakeEvent = Object.assign(createFakeEvent('transitionend'),
164-
{propertyName: 'width'});
164+
const fakeEvent = createFakeEvent('transitionend');
165+
(fakeEvent as any).propertyName = 'width';
165166
chipNativeElement.dispatchEvent(fakeEvent);
166167

167168
expect(testComponent.chipRemove).not.toHaveBeenCalled();
@@ -176,8 +177,8 @@ describe('MDC-based Row Chips', () => {
176177
chipInstance._keydown(BACKSPACE_EVENT);
177178
fixture.detectChanges();
178179

179-
const fakeEvent = Object.assign(createFakeEvent('transitionend'),
180-
{propertyName: 'width'});
180+
const fakeEvent = createFakeEvent('transitionend');
181+
(fakeEvent as any).propertyName = 'width';
181182
chipNativeElement.dispatchEvent(fakeEvent);
182183

183184
expect(testComponent.chipRemove).not.toHaveBeenCalled();

src/material-experimental/mdc-chips/chip.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ describe('MDC-based MatChip', () => {
109109
chipInstance.remove();
110110
fixture.detectChanges();
111111

112-
const fakeEvent = Object.assign(createFakeEvent('transitionend'), {propertyName: 'width'});
112+
const fakeEvent = createFakeEvent('transitionend');
113+
(fakeEvent as any).propertyName = 'width';
113114
chipNativeElement.dispatchEvent(fakeEvent);
114115

115116
expect(testComponent.chipRemove).toHaveBeenCalledWith({chip: chipInstance});

src/material/input/input.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ describe('MatInput without forms', () => {
829829
expect(inputContainer._shouldAlwaysFloat).toBe(false);
830830
expect(inputContainer.floatLabel).toBe('always');
831831

832-
const fakeEvent = Object.assign(createFakeEvent('transitionend'), {propertyName: 'transform'});
833-
832+
const fakeEvent = createFakeEvent('transitionend');
833+
(fakeEvent as any).propertyName = 'transform';
834834
label.dispatchEvent(fakeEvent);
835835
fixture.detectChanges();
836836

tools/dgeni/processors/merge-inherited-properties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class MergeInheritedProperties implements Processor {
3535
// member doc for the destination class, we clone the member doc. It's important to keep
3636
// the prototype and reference because later, Dgeni identifies members and properties
3737
// by using an instance comparison.
38-
const newMemberDoc = Object.assign(Object.create(memberDoc), memberDoc);
38+
const newMemberDoc = {...Object.create(memberDoc), ...memberDoc};
3939
newMemberDoc.containerDoc = destination;
4040

4141
destination.members.push(newMemberDoc);

tslint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
["fdescribe"],
8787
["xit"],
8888
["xdescribe"],
89-
{"name": "Object.assign", "message": "Use the spread operator instead."}
89+
{"name": ["Object", "assign"], "message": "Use the spread operator instead."}
9090
],
9191
// Avoids inconsistent linebreak styles in source files. Forces developers to use LF linebreaks.
9292
"linebreak-style": [true, "LF"],

0 commit comments

Comments
 (0)