Skip to content

Commit 6814017

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored andcommitted
[eslint] Enforce optional chaining
This simplify the code that we write Bug: 397260638 Change-Id: I9757acd0d700af2675264c7f4d2c22fa89b7dc8f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6287365 Commit-Queue: Mathias Bynens <[email protected]> Reviewed-by: Mathias Bynens <[email protected]> Auto-Submit: Nikolay Vitkov <[email protected]>
1 parent 1d0b26b commit 6814017

File tree

225 files changed

+533
-564
lines changed

Some content is hidden

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

225 files changed

+533
-564
lines changed

eslint.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ export default [
531531
},
532532
],
533533

534+
'@typescript-eslint/prefer-optional-chain': 'error',
535+
534536
'rulesdir/no-underscored-properties': 'error',
535537
'rulesdir/inline-type-imports': 'error',
536538

extensions/cxx_debugging/e2e/TestDriver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ describe('CXX Debugging Extension Test Suite', function() {
115115

116116
if (variableName.startsWith('$')) {
117117
if (variableType) {
118-
assert.isTrue(scopeVariable && scopeVariable.endsWith(`: ${variableType}`));
118+
assert.isTrue(scopeVariable?.endsWith(`: ${variableType}`));
119119
} else if (value) {
120-
assert.isTrue(scopeVariable && scopeVariable.endsWith(`: ${value}`));
120+
assert.isTrue(scopeVariable?.endsWith(`: ${value}`));
121121
}
122122
} else {
123123
if (variableType) {

extensions/cxx_debugging/src/DevToolsPluginHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export interface Storage {
109109

110110
export declare const chrome: Chrome.DevTools.Chrome&{storage?: Storage};
111111

112-
if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') {
112+
if (typeof chrome?.storage !== 'undefined') {
113113
const {storage} = chrome;
114114
const {languageServices} = chrome.devtools;
115115

extensions/cxx_debugging/src/MEMFSResourceLoader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class ResourceLoader implements DWARFSymbols.ResourceLoader {
2626
// get a 404 response.
2727
console.error(symbolsDwpError);
2828
}
29-
if (!(symbolsDwpResponse && symbolsDwpResponse.ok)) {
29+
if (!(symbolsDwpResponse?.ok)) {
3030
// Often this won't exist, but remember the missing file because if
3131
// we can't find symbol information later it is likely because this
3232
// file was missing.
@@ -37,7 +37,7 @@ export class ResourceLoader implements DWARFSymbols.ResourceLoader {
3737
}
3838
const [symbolsData, symbolsDwpData] = await Promise.all([
3939
symbolsResponse.arrayBuffer(),
40-
symbolsDwpResponse && symbolsDwpResponse.ok ? symbolsDwpResponse.arrayBuffer() : undefined,
40+
symbolsDwpResponse?.ok ? symbolsDwpResponse.arrayBuffer() : undefined,
4141
]);
4242
void hostInterface.reportResourceLoad(url.href, {success: true, size: symbolsData.byteLength});
4343
if (symbolsDwpData) {

front_end/core/common/Object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class ObjectWrapper<Events> implements EventTarget<Events> {
8585
}
8686

8787
hasEventListeners(eventType: keyof Events): boolean {
88-
return Boolean(this.listeners && this.listeners.has(eventType));
88+
return Boolean(this.listeners?.has(eventType));
8989
}
9090

9191
dispatchEventToListeners<T extends keyof Events>(

front_end/core/common/ParsedURL.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export class ParsedURL {
372372

373373
// Return absolute URLs with normalized path and other components as-is.
374374
const parsedHref = this.fromString(trimmedHref);
375-
if (parsedHref && parsedHref.scheme) {
375+
if (parsedHref?.scheme) {
376376
const securityOrigin = parsedHref.securityOrigin();
377377
const pathText = normalizePath(parsedHref.path);
378378
const queryText = parsedHref.queryParams && `?${parsedHref.queryParams}`;

front_end/core/common/Settings.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,10 @@ export class VersionController {
838838
continue;
839839
}
840840
// Zero out saved percentage sizes, and they will be restored to defaults.
841-
if (value.vertical && value.vertical.size && value.vertical.size < 1) {
841+
if (value.vertical?.size && value.vertical.size < 1) {
842842
value.vertical.size = 0;
843843
}
844-
if (value.horizontal && value.horizontal.size && value.horizontal.size < 1) {
844+
if (value.horizontal?.size && value.horizontal.size < 1) {
845845
value.horizontal.size = 0;
846846
}
847847
setting.set(value);

front_end/core/dom_extension/DOMExtension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Node.prototype.traversePreviousNode = function(stayWithin?: Node): Node|null {
341341
return null;
342342
}
343343
let node: ChildNode|(ChildNode | null) = this.previousSibling;
344-
while (node && node.lastChild) {
344+
while (node?.lastChild) {
345345
node = node.lastChild;
346346
}
347347
if (node) {

front_end/core/i18n/i18nImpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export function getAllSupportedDevToolsLocales(): string[] {
4848
*/
4949
function getLocaleFetchUrl(locale: Intl.UnicodeBCP47LocaleIdentifier, location: string): string {
5050
const remoteBase = Root.Runtime.getRemoteBase(location);
51-
if (remoteBase && remoteBase.version && !BUNDLED_LOCALES.has(locale)) {
51+
if (remoteBase?.version && !BUNDLED_LOCALES.has(locale)) {
5252
return REMOTE_FETCH_PATTERN.replace('@HOST@', 'devtools://devtools')
5353
.replace('@VERSION@', remoteBase.version)
5454
.replace('@LOCALE@', locale);

front_end/core/platform/DOMUtilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
export function deepActiveElement(doc: Document): Element|null {
1111
let activeElement: Element|null = doc.activeElement;
12-
while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement) {
12+
while (activeElement?.shadowRoot?.activeElement) {
1313
activeElement = activeElement.shadowRoot.activeElement;
1414
}
1515
return activeElement;

0 commit comments

Comments
 (0)