Skip to content

Commit a2ced3f

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[Eslint] Enable no-empty-object-type
The {} type in TypeScript does not represent a empty object as one may expect this makes it confusing to work with and use properly. https://typescript-eslint.io/rules/no-empty-object-type/ Bug: 397260638 Change-Id: Ic2cc515ac729a76d652fca829082bb76c8b1f913 Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6327458 Auto-Submit: Nikolay Vitkov <[email protected]> Reviewed-by: Mathias Bynens <[email protected]> Commit-Queue: Jack Franklin <[email protected]> Reviewed-by: Jack Franklin <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent af32496 commit a2ced3f

File tree

17 files changed

+66
-65
lines changed

17 files changed

+66
-65
lines changed

eslint.config.mjs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import jsdocPlugin from 'eslint-plugin-jsdoc';
1313
import mochaPlugin from 'eslint-plugin-mocha';
1414
import rulesdirPlugin from 'eslint-plugin-rulesdir';
1515
import globals from 'globals';
16-
import {join} from 'path';
16+
import { join } from 'path';
1717

1818
rulesdirPlugin.RULES_DIR = join(
19-
import.meta.dirname,
20-
'scripts',
21-
'eslint_rules',
22-
'lib',
19+
import.meta.dirname,
20+
'scripts',
21+
'eslint_rules',
22+
'lib',
2323
);
2424

2525
/**
@@ -316,11 +316,11 @@ export default [
316316
parserOptions: {
317317
allowAutomaticSingleRunInference: true,
318318
project: join(
319-
import.meta.dirname,
320-
'config',
321-
'typescript',
322-
'tsconfig.eslint.json',
323-
),
319+
import.meta.dirname,
320+
'config',
321+
'typescript',
322+
'tsconfig.eslint.json',
323+
),
324324
},
325325
},
326326

@@ -542,6 +542,13 @@ export default [
542542

543543
'@typescript-eslint/no-unsafe-function-type': 'error',
544544

545+
'@typescript-eslint/no-empty-object-type': [
546+
'error',
547+
{
548+
allowInterfaces: 'with-single-extends',
549+
},
550+
],
551+
545552
'rulesdir/no-underscored-properties': 'error',
546553
'rulesdir/inline-type-imports': 'error',
547554

@@ -550,12 +557,12 @@ export default [
550557
{
551558
// Enforce that any import of models/trace/trace.js names the import Trace.
552559
modulePath: join(
553-
import.meta.dirname,
554-
'front_end',
555-
'models',
556-
'trace',
557-
'trace.js',
558-
),
560+
import.meta.dirname,
561+
'front_end',
562+
'models',
563+
'trace',
564+
'trace.js',
565+
),
559566
importName: 'Trace',
560567
},
561568
],
@@ -827,7 +834,7 @@ export default [
827834
rules: {
828835
// Not a useful rule for .d.ts files where we are
829836
// representing an existing module.
830-
'import/no-default-export': 'off'
831-
}
832-
}
837+
'import/no-default-export': 'off',
838+
},
839+
},
833840
];

front_end/core/common/Settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ export class VersionController {
756756
const newName = settingNames[oldName];
757757
const oldNameH = oldName + 'H';
758758

759-
let newValue: {}|null = null;
759+
let newValue: object|null = null;
760760
const oldSetting = Settings.instance().createSetting(oldName, empty);
761761
if (oldSetting.get() !== empty) {
762762
newValue = newValue || {};

front_end/core/platform/MapUtilities.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export class Multimap<K, V> {
8282
/**
8383
* Gets value for key, assigning a default if value is falsy.
8484
*/
85+
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
8586
export function getWithDefault<K extends {}, V>(
8687
map: WeakMap<K, V>|Map<K, V>, key: K, defaultValueFactory: (key?: K) => V): V {
8788
let value = map.get(key);

front_end/core/sdk/FrameManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('FrameManager', () => {
8080
function setupEventSink(
8181
// eslint-disable-next-line @typescript-eslint/no-explicit-any
8282
frameManager: FrameManager, events: SDK.FrameManager.Events[]): Array<{type: string, data: any}> {
83-
const dispatchedEvents: Array<{type: string, data: {}}> = [];
83+
const dispatchedEvents: Array<{type: string, data: object}> = [];
8484
for (const event of events) {
8585
frameManager.addEventListener(event, e => dispatchedEvents.push({type: event || '', data: e.data}));
8686
}

front_end/models/trace/handlers/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type * as ModelHandlers from './ModelHandlers.js';
77

88
export interface Handler {
99
reset(): void;
10-
handleEvent(data: {}): void;
10+
handleEvent(data: object): void;
1111
finalize(options?: Types.Configuration.ParseOptions): Promise<void>;
1212
data(): unknown;
1313
deps?(): HandlerName[];

front_end/models/trace/types/TraceEvents.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface CallFrame {
109109
url: string;
110110
}
111111

112-
export function objectIsCallFrame(object: {}): object is CallFrame {
112+
export function objectIsCallFrame(object: object): object is CallFrame {
113113
return ('functionName' in object && typeof object.functionName === 'string') &&
114114
('scriptId' in object && (typeof object.scriptId === 'string' || typeof object.scriptId === 'number')) &&
115115
('columnNumber' in object && typeof object.columnNumber === 'number') &&

front_end/panels/application/KeyValueStorageItemsView.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ export interface ViewInput {
8585
onDelete: (event: CustomEvent<HTMLElement>) => void;
8686
}
8787

88-
export interface ViewOutput {}
89-
90-
export type View = (input: ViewInput, output: ViewOutput, target: HTMLElement) => void;
88+
export type View = (input: ViewInput, output: object, target: HTMLElement) => void;
9189
/**
9290
* A helper typically used in the Application panel. Renders a split view
9391
* between a DataGrid displaying key-value pairs and a preview Widget.
@@ -106,7 +104,7 @@ export abstract class KeyValueStorageItemsView extends StorageItemsView {
106104
title: string, id: string, editable: boolean, view?: View,
107105
metadataView?: ApplicationComponents.StorageMetadataView.StorageMetadataView) {
108106
if (!view) {
109-
view = (input: ViewInput, output: ViewOutput, target: HTMLElement) => {
107+
view = (input: ViewInput, _, target: HTMLElement) => {
110108
// clang-format off
111109
render(html `
112110
<devtools-split-view direction="column" sidebar-position="second" name="${id}-split-view-state">

front_end/panels/developer_resources/DeveloperResourcesListView.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,16 @@ export interface ViewInput {
8383
onInitiatorMouseLeave: () => void;
8484
}
8585

86-
export interface ViewOutput {}
87-
88-
export type View = (input: ViewInput, output: ViewOutput, target: HTMLElement) => void;
86+
export type View = (input: ViewInput, output: object, target: HTMLElement) => void;
8987

9088
export class DeveloperResourcesListView extends UI.Widget.VBox {
9189
#items: SDK.PageResourceLoader.PageResource[] = [];
9290
#selectedItem: SDK.PageResourceLoader.PageResource|null = null;
9391
readonly #view: View;
9492
#filters: TextUtils.TextUtils.ParsedFilter[] = [];
95-
constructor(view: View = (input, output, target) => {
96-
// clang-format off
93+
constructor(
94+
view: View = (input, _, target) => {
95+
// clang-format off
9796
render(html`
9897
<devtools-data-grid
9998
name=${i18nString(UIStrings.developerResources)}
@@ -158,21 +157,21 @@ export class DeveloperResourcesListView extends UI.Widget.VBox {
158157
</table>
159158
</devtools-data-grid>`,
160159
target, {host: input});
161-
// clang-format on
162-
function renderUrl(url: string): HTMLElement {
163-
const outer = document.createElement('div');
164-
UI.ARIAUtils.setHidden(outer, true);
165-
outer.setAttribute('part', 'url-outer');
166-
const domain = outer.createChild('div');
167-
domain.setAttribute('part', 'url-prefix');
168-
const path = outer.createChild('div');
169-
path.setAttribute('part', 'url-suffix');
170-
const splitURL = /^(.*)(\/[^/]*)$/.exec(url);
171-
domain.textContent = splitURL ? splitURL[1] : url;
172-
path.textContent = splitURL ? splitURL[2] : '';
173-
return outer;
174-
}
175-
}) {
160+
// clang-format on
161+
function renderUrl(url: string): HTMLElement {
162+
const outer = document.createElement('div');
163+
UI.ARIAUtils.setHidden(outer, true);
164+
outer.setAttribute('part', 'url-outer');
165+
const domain = outer.createChild('div');
166+
domain.setAttribute('part', 'url-prefix');
167+
const path = outer.createChild('div');
168+
path.setAttribute('part', 'url-suffix');
169+
const splitURL = /^(.*)(\/[^/]*)$/.exec(url);
170+
domain.textContent = splitURL ? splitURL[1] : url;
171+
path.textContent = splitURL ? splitURL[2] : '';
172+
return outer;
173+
}
174+
}) {
176175
super(true);
177176
this.#view = view;
178177
this.registerRequiredCSS(developerResourcesListViewStyles);

front_end/panels/elements/CSSValueTraceView.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ export interface ViewInput {
2323
finalResult: Node[]|undefined;
2424
onToggle: () => void;
2525
}
26-
export interface ViewOutput {}
2726

2827
export type View = (
2928
input: ViewInput,
30-
output: ViewOutput,
29+
output: object,
3130
target: HTMLElement,
3231
) => void;
3332

@@ -38,7 +37,7 @@ export class CSSValueTraceView extends UI.Widget.VBox {
3837
#substitutions: Node[][] = [];
3938

4039
constructor(
41-
view: View = (input, output, target):
40+
view: View = (input, _, target):
4241
void => {
4342
const substitutionIcon = html`<span class=trace-line-icon aria-label="resolved to">\u21B3</span>`;
4443
const evalIcon = html`<span class=trace-line-icon aria-label="is equal to">\u003D</span>`;

front_end/panels/recorder/components/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export function assert<T>(
1818
export type Keys<T> = T extends T ? keyof T : never;
1919

2020
export type RequiredKeys<T> = {
21-
[K in keyof T] -?: {} extends Pick<T, K>? never : K;
21+
[K in keyof T] -?: Record<string|number|symbol, unknown> extends Pick<T, K>? never : K;
2222
}[keyof T];
2323

2424
export type OptionalKeys<T> = {
25-
[K in keyof T] -?: {} extends Pick<T, K>? K : never;
25+
[K in keyof T] -?: Record<string|number|symbol, unknown> extends Pick<T, K>? K : never;
2626
}[keyof T];
2727

2828
export type DeepImmutable<T> = {

0 commit comments

Comments
 (0)