Skip to content

Commit 65a5a91

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Run no-unnecessary-type-assertion
This type duplication can happen because of two reasons. 1) TypeScript was not smart enough to deduce the type correctly 2) During our TypeScript migration not very was typed, so we need to type cast in a lot of places. The rule is disabled as its too aggressive in some places, will file issues upstream. Bug: 397260638 Change-Id: Ic1100fee1e5a1d160d366f65d969442909f16eaf Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6276556 Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Benedikt Meurer <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent 011d249 commit 65a5a91

File tree

188 files changed

+461
-541
lines changed

Some content is hidden

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

188 files changed

+461
-541
lines changed

eslint.config.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,10 @@ export default [
498498
'no-throw-literal': 'off',
499499
'@typescript-eslint/only-throw-error': 'error',
500500

501+
// Disabled this rule while investigating why it creates
502+
// certain TypeScript compilation errors after fixes
503+
'@typescript-eslint/no-unnecessary-type-assertion': 'off',
504+
501505
'rulesdir/no-underscored-properties': 'error',
502506
'rulesdir/inline-type-imports': 'error',
503507

extensions/cxx_debugging/src/DWARFSymbols.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function createEmbindPool(): {
9999

100100
manage<T extends SymbolsBackend.EmbindObject|undefined>(object: T): T {
101101
if (typeof object !== 'undefined') {
102-
this.objectPool.push(object as SymbolsBackend.EmbindObject);
102+
this.objectPool.push(object);
103103
}
104104
return object;
105105
}

extensions/cxx_debugging/src/WasmTypes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ export function serializeWasmValue(value: WasmValue|ArrayBuffer, buffer: ArrayBu
3333
const view = new DataView(buffer);
3434
switch (value.type) {
3535
case 'i32': {
36-
view.setInt32(0, value.value as number, true);
36+
view.setInt32(0, value.value, true);
3737
return SerializedWasmType.i32;
3838
}
3939
case 'i64': {
40-
view.setBigInt64(0, value.value as bigint, true);
40+
view.setBigInt64(0, value.value, true);
4141
return SerializedWasmType.i64;
4242
}
4343
case 'f32': {
44-
view.setFloat32(0, value.value as number, true);
44+
view.setFloat32(0, value.value, true);
4545
return SerializedWasmType.f32;
4646
}
4747
case 'f64': {
48-
view.setFloat64(0, value.value as number, true);
48+
view.setFloat64(0, value.value, true);
4949
return SerializedWasmType.f64;
5050
}
5151
case 'v128': {
52-
const [, a, b, c, d] = (value.value as string).split(' ');
52+
const [, a, b, c, d] = (value.value).split(' ');
5353
view.setInt32(0, Number(a), true);
5454
view.setInt32(4, Number(b), true);
5555
view.setInt32(8, Number(c), true);

front_end/core/common/ParsedURL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export class ParsedURL {
168168
// Based on net::FilePathToFileURL. Ideally we would handle
169169
// '\\' as well on non-Windows file systems.
170170
for (const specialChar of ['%', ';', '#', '?', ' ']) {
171-
(path as string) = path.replaceAll(specialChar, encodeURIComponent(specialChar));
171+
(path) = path.replaceAll(specialChar, encodeURIComponent(specialChar));
172172
}
173173
return path;
174174
}

front_end/core/common/ResourceType.test.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ describeWithEnvironment('ResourceType class', () => {
121121
it('is able to return an wasm resource from the string "application/wasm"', () => {
122122
const result = ResourceType.fromMimeTypeOverride('application/wasm');
123123
assert.instanceOf(result, ResourceType, 'result type is incorrect');
124-
assert.strictEqual(result!.name(), 'wasm', 'name was not set correctly');
125-
assert.strictEqual(result!.title(), 'Wasm', 'title was not set correctly');
126-
assert.strictEqual(result!.category().title(), 'WebAssembly', 'category title was not set correctly');
127-
assert.strictEqual(result!.category().shortTitle(), 'Wasm', 'category short title was not set correctly');
128-
assert.isFalse(result!.isTextType(), 'resource type was not set correctly');
124+
assert.strictEqual(result.name(), 'wasm', 'name was not set correctly');
125+
assert.strictEqual(result.title(), 'Wasm', 'title was not set correctly');
126+
assert.strictEqual(result.category().title(), 'WebAssembly', 'category title was not set correctly');
127+
assert.strictEqual(result.category().shortTitle(), 'Wasm', 'category short title was not set correctly');
128+
assert.isFalse(result.isTextType(), 'resource type was not set correctly');
129129
});
130130

131131
it('is able to return an web bundle resource from the string "application/webbundle"', () => {
132132
const result = ResourceType.fromMimeTypeOverride('application/webbundle');
133133
assert.instanceOf(result, ResourceType, 'result type is incorrect');
134-
assert.strictEqual(result!.name(), 'webbundle', 'name was not set correctly');
135-
assert.strictEqual(result!.title(), 'WebBundle', 'title was not set correctly');
136-
assert.strictEqual(result!.category().title(), 'Other', 'category title was not set correctly');
137-
assert.strictEqual(result!.category().shortTitle(), 'Other', 'category short title was not set correctly');
138-
assert.isFalse(result!.isTextType(), 'resource type was not set correctly');
134+
assert.strictEqual(result.name(), 'webbundle', 'name was not set correctly');
135+
assert.strictEqual(result.title(), 'WebBundle', 'title was not set correctly');
136+
assert.strictEqual(result.category().title(), 'Other', 'category title was not set correctly');
137+
assert.strictEqual(result.category().shortTitle(), 'Other', 'category short title was not set correctly');
138+
assert.isFalse(result.isTextType(), 'resource type was not set correctly');
139139
});
140140

141141
it('is able to return a resource of type other from the string "test/resource"', () => {
@@ -151,41 +151,41 @@ describeWithEnvironment('ResourceType class', () => {
151151
it('is able to return a resource type from a URL that contains a mapped extension', () => {
152152
const result = ResourceType.fromURL('http://www.example.com/test/testFile.js');
153153
assert.instanceOf(result, ResourceType, 'result type is incorrect');
154-
assert.strictEqual(result!.name(), 'script', 'name was not set correctly');
155-
assert.strictEqual(result!.title(), 'Script', 'title was not set correctly');
156-
assert.strictEqual(result!.category().title(), 'JavaScript', 'category title was not set correctly');
157-
assert.strictEqual(result!.category().shortTitle(), 'JS', 'category short title was not set correctly');
158-
assert.isTrue(result!.isTextType(), 'resource type was not set correctly');
154+
assert.strictEqual(result.name(), 'script', 'name was not set correctly');
155+
assert.strictEqual(result.title(), 'Script', 'title was not set correctly');
156+
assert.strictEqual(result.category().title(), 'JavaScript', 'category title was not set correctly');
157+
assert.strictEqual(result.category().shortTitle(), 'JS', 'category short title was not set correctly');
158+
assert.isTrue(result.isTextType(), 'resource type was not set correctly');
159159
});
160160

161161
it('is able to return a resource type from a URL that ends in .avif', () => {
162162
const result = ResourceType.fromURL('https://host.example/image.avif');
163163
assert.instanceOf(result, ResourceType, 'result type is incorrect');
164-
assert.strictEqual(result!.name(), 'image', 'name was not set correctly');
165-
assert.strictEqual(result!.title(), 'Image', 'title was not set correctly');
166-
assert.strictEqual(result!.category().title(), 'Image', 'category title was not set correctly');
167-
assert.strictEqual(result!.category().shortTitle(), 'Img', 'category short title was not set correctly');
168-
assert.isTrue(result!.isImage(), 'resource type was not set correctly');
164+
assert.strictEqual(result.name(), 'image', 'name was not set correctly');
165+
assert.strictEqual(result.title(), 'Image', 'title was not set correctly');
166+
assert.strictEqual(result.category().title(), 'Image', 'category title was not set correctly');
167+
assert.strictEqual(result.category().shortTitle(), 'Img', 'category short title was not set correctly');
168+
assert.isTrue(result.isImage(), 'resource type was not set correctly');
169169
});
170170

171171
it('is able to return a resource type from a URL that ends in .jxl', () => {
172172
const result = ResourceType.fromURL('https://host.example/image.jxl');
173173
assert.instanceOf(result, ResourceType, 'result type is incorrect');
174-
assert.strictEqual(result!.name(), 'image', 'name was not set correctly');
175-
assert.strictEqual(result!.title(), 'Image', 'title was not set correctly');
176-
assert.strictEqual(result!.category().title(), 'Image', 'category title was not set correctly');
177-
assert.strictEqual(result!.category().shortTitle(), 'Img', 'category short title was not set correctly');
178-
assert.isTrue(result!.isImage(), 'resource type was not set correctly');
174+
assert.strictEqual(result.name(), 'image', 'name was not set correctly');
175+
assert.strictEqual(result.title(), 'Image', 'title was not set correctly');
176+
assert.strictEqual(result.category().title(), 'Image', 'category title was not set correctly');
177+
assert.strictEqual(result.category().shortTitle(), 'Img', 'category short title was not set correctly');
178+
assert.isTrue(result.isImage(), 'resource type was not set correctly');
179179
});
180180

181181
it('is able to return a resource type from a URL that ends in .woff2', () => {
182182
const result = ResourceType.fromURL('https://host.example/image.woff2');
183183
assert.instanceOf(result, ResourceType, 'result type is incorrect');
184-
assert.strictEqual(result!.name(), 'font', 'name was not set correctly');
185-
assert.strictEqual(result!.title(), 'Font', 'title was not set correctly');
186-
assert.strictEqual(result!.category().title(), 'Font', 'category title was not set correctly');
187-
assert.strictEqual(result!.category().shortTitle(), 'Font', 'category short title was not set correctly');
188-
assert.isFalse(result!.isTextType(), 'resource type was not set correctly');
184+
assert.strictEqual(result.name(), 'font', 'name was not set correctly');
185+
assert.strictEqual(result.title(), 'Font', 'title was not set correctly');
186+
assert.strictEqual(result.category().title(), 'Font', 'category title was not set correctly');
187+
assert.strictEqual(result.category().shortTitle(), 'Font', 'category short title was not set correctly');
188+
assert.isFalse(result.isTextType(), 'resource type was not set correctly');
189189
});
190190

191191
it('is able to return null from a URL that contains an unmapped extension', () => {
@@ -196,11 +196,11 @@ describeWithEnvironment('ResourceType class', () => {
196196
it('is able to return a resource type from a mapped name', () => {
197197
const result = ResourceType.fromName('script');
198198
assert.instanceOf(result, ResourceType, 'result type is incorrect');
199-
assert.strictEqual(result!.name(), 'script', 'name was not set correctly');
200-
assert.strictEqual(result!.title(), 'Script', 'title was not set correctly');
201-
assert.strictEqual(result!.category().title(), 'JavaScript', 'category title was not set correctly');
202-
assert.strictEqual(result!.category().shortTitle(), 'JS', 'category short title was not set correctly');
203-
assert.isTrue(result!.isTextType(), 'resource type was not set correctly');
199+
assert.strictEqual(result.name(), 'script', 'name was not set correctly');
200+
assert.strictEqual(result.title(), 'Script', 'title was not set correctly');
201+
assert.strictEqual(result.category().title(), 'JavaScript', 'category title was not set correctly');
202+
assert.strictEqual(result.category().shortTitle(), 'JS', 'category short title was not set correctly');
203+
assert.isTrue(result.isTextType(), 'resource type was not set correctly');
204204
});
205205

206206
it('is able to return null from an unmapped name', () => {

front_end/core/common/SettingRegistration.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ describe('SettingRegistration', () => {
5151

5252
it('retrieves a registered setting', () => {
5353
try {
54-
const preRegisteredSetting =
55-
Common.Settings.Settings.instance().moduleSetting(settingName) as Common.Settings.Setting<boolean>;
54+
const preRegisteredSetting = Common.Settings.Settings.instance().moduleSetting(settingName);
5655
assert.strictEqual(preRegisteredSetting.title(), settingTitle, 'Setting title is not returned correctly');
5756
assert.strictEqual(
5857
preRegisteredSetting.category(), settingCategory, 'Setting category is not returned correctly');

front_end/core/host/InspectorFrontendHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class InspectorFrontendHostStub implements InspectorFrontendHostAPI {
121121
}
122122

123123
document.addEventListener('keydown', event => {
124-
stopEventPropagation.call(this, (event as KeyboardEvent));
124+
stopEventPropagation.call(this, (event));
125125
}, true);
126126
}
127127

front_end/core/i18n/DevToolsLocale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class DevToolsLocale {
6262
forceFallbackLocale(): void {
6363
// Locale is 'readonly', this is the only case where we want to forceably
6464
// overwrite the locale.
65-
(this.locale as DevToolsLocale['locale']) = 'en-US';
65+
(this.locale as unknown) = 'en-US';
6666
}
6767

6868
/**

front_end/core/protocol_client/InspectorBackend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ export class TargetBase {
545545
router.registerSession(this, this.sessionId);
546546

547547
for (const [domain, agentPrototype] of inspectorBackend.agentPrototypes) {
548-
const agent = Object.create((agentPrototype as AgentPrototype));
548+
const agent = Object.create((agentPrototype));
549549
agent.target = this;
550550
this.#agents.set(domain, agent);
551551
}

front_end/core/sdk/CSSMatchedStyles.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ function cleanUserAgentPayload(payload: Protocol.CSS.RuleMatch[]): Protocol.CSS.
6969
return cleanMatchedPayload;
7070

7171
function mergeRule(from: Protocol.CSS.RuleMatch, to: Protocol.CSS.RuleMatch): void {
72-
const shorthands = (new Map() as Map<string, string>);
73-
const properties = (new Map() as Map<string, string>);
72+
const shorthands = new Map<string, string>();
73+
const properties = new Map<string, string>();
7474
for (const entry of to.rule.style.shorthandEntries) {
7575
shorthands.set(entry.name, entry.value);
7676
}
@@ -241,14 +241,14 @@ export class CSSRegisteredProperty {
241241
export class CSSMatchedStyles {
242242
#cssModelInternal: CSSModel;
243243
#nodeInternal: DOMNode;
244-
#addedStyles: Map<CSSStyleDeclaration, DOMNode>;
245-
#matchingSelectors: Map<number, Map<string, boolean>>;
246-
#keyframesInternal: CSSKeyframesRule[];
244+
#addedStyles = new Map<CSSStyleDeclaration, DOMNode>();
245+
#matchingSelectors = new Map<number, Map<string, boolean>>();
246+
#keyframesInternal: CSSKeyframesRule[] = [];
247247
#registeredProperties: CSSRegisteredProperty[];
248248
#registeredPropertyMap = new Map<string, CSSRegisteredProperty>();
249-
#nodeForStyleInternal: Map<CSSStyleDeclaration, DOMNode|null>;
250-
#inheritedStyles: Set<CSSStyleDeclaration>;
251-
#styleToDOMCascade: Map<CSSStyleDeclaration, DOMInheritanceCascade>;
249+
#nodeForStyleInternal = new Map<CSSStyleDeclaration, DOMNode|null>();
250+
#inheritedStyles = new Set<CSSStyleDeclaration>();
251+
#styleToDOMCascade = new Map<CSSStyleDeclaration, DOMInheritanceCascade>();
252252
#parentLayoutNodeId: Protocol.DOM.NodeId|undefined;
253253
#positionTryRules: CSSPositionTryRule[];
254254
#activePositionFallbackIndex: number;
@@ -276,13 +276,10 @@ export class CSSMatchedStyles {
276276
}: CSSMatchedStylesPayload) {
277277
this.#cssModelInternal = cssModel;
278278
this.#nodeInternal = node;
279-
this.#addedStyles = new Map();
280-
this.#matchingSelectors = new Map();
281279
this.#registeredProperties = [
282280
...propertyRules.map(rule => new CSSPropertyRule(cssModel, rule)),
283281
...cssPropertyRegistrations,
284282
].map(r => new CSSRegisteredProperty(cssModel, r));
285-
this.#keyframesInternal = [];
286283
if (animationsPayload) {
287284
this.#keyframesInternal = animationsPayload.map(rule => new CSSKeyframesRule(cssModel, rule));
288285
}
@@ -291,10 +288,6 @@ export class CSSMatchedStyles {
291288
this.#fontPaletteValuesRule =
292289
fontPaletteValuesRule ? new CSSFontPaletteValuesRule(cssModel, fontPaletteValuesRule) : undefined;
293290

294-
this.#nodeForStyleInternal = new Map();
295-
this.#inheritedStyles = new Set();
296-
this.#styleToDOMCascade = new Map();
297-
this.#registeredPropertyMap = new Map();
298291
this.#activePositionFallbackIndex = activePositionFallbackIndex;
299292
}
300293

@@ -818,17 +811,15 @@ class NodeCascade {
818811
readonly styles: CSSStyleDeclaration[];
819812
readonly #isInherited: boolean;
820813
readonly #isHighlightPseudoCascade: boolean;
821-
readonly propertiesState: Map<CSSProperty, PropertyState>;
822-
readonly activeProperties: Map<string, CSSProperty>;
814+
readonly propertiesState = new Map<CSSProperty, PropertyState>();
815+
readonly activeProperties = new Map<string, CSSProperty>();
823816
constructor(
824817
matchedStyles: CSSMatchedStyles, styles: CSSStyleDeclaration[], isInherited: boolean,
825818
isHighlightPseudoCascade: boolean = false) {
826819
this.#matchedStyles = matchedStyles;
827820
this.styles = styles;
828821
this.#isInherited = isInherited;
829822
this.#isHighlightPseudoCascade = isHighlightPseudoCascade;
830-
this.propertiesState = new Map();
831-
this.activeProperties = new Map();
832823
}
833824

834825
computeActiveProperties(): void {
@@ -1301,8 +1292,8 @@ class DOMInheritanceCascade {
13011292
const nodeCascade = this.#nodeCascades[i];
13021293
const variableNames = [];
13031294
for (const entry of nodeCascade.activeProperties.entries()) {
1304-
const propertyName = (entry[0] as string);
1305-
const property = (entry[1] as CSSProperty);
1295+
const propertyName = entry[0];
1296+
const property = entry[1];
13061297
if (propertyName.startsWith('--')) {
13071298
accumulatedCSSVariables.set(propertyName, {value: property.value, declaration: new CSSValueSource(property)});
13081299
variableNames.push(propertyName);

0 commit comments

Comments
 (0)