Skip to content

Commit

Permalink
WebUI: Enforce naming style with more ESLint checks in TS files.
Browse files Browse the repository at this point in the history
Specifically enforcing naming for class, interface, typeAlias, enum,
typeParameter, classMethod and parameter cases to match the
styleguide at [1].

[1] https://google.github.io/styleguide/jsguide.html#naming

Bug: 720034
Change-Id: I80a1000d500e5770aaff1fea5f944fd43f9ac877
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3632596
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1001357}
  • Loading branch information
freshp86 authored and Chromium LUCI CQ committed May 10, 2022
1 parent da26adb commit 684f427
Show file tree
Hide file tree
Showing 20 changed files with 75 additions and 67 deletions.
16 changes: 13 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,28 @@ module.exports = {
'semi': 'off',
'@typescript-eslint/semi': ['error'],

// https://google.github.io/styleguide/jsguide.html#naming
'@typescript-eslint/naming-convention': [
'error',
{
// https://google.github.io/styleguide/jsguide.html#naming-enum-names
selector: 'enum',
selector: ['class', 'interface', 'typeAlias', 'enum', 'typeParameter'],
format: ['PascalCase'],
},
{
// https://google.github.io/styleguide/jsguide.html#naming-enum-names
selector: 'enumMember',
format: ['UPPER_CASE'],
},
{
selector: 'classMethod',
format: ['camelCase'],
leadingUnderscore: 'allow',
trailingUnderscore: 'allow',
},
{
selector: 'parameter',
format: ['camelCase'],
leadingUnderscore: 'allow',
},
],

'@typescript-eslint/member-delimiter-style': ['error', {
Expand Down
6 changes: 3 additions & 3 deletions chrome/browser/resources/chromeos/audio/feedback_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {InputPage} from './input_page.js';
import {OutputPage} from './output_page.js';
import {Page} from './page.js';

interface feedbackObject {
interface FeedbackObject {
[key: string]: any;
}

Expand Down Expand Up @@ -55,7 +55,7 @@ export class FeedbackPage extends Page {
}

updateAudioInfo() {
var audioInfoJson: feedbackObject = {};
var audioInfoJson: FeedbackObject = {};

const inputFeedbackObject = this.mapToObject(this.inputFeedbackMap);
const outputFeedbackObject = this.mapToObject(this.outputFeedbackMap);
Expand All @@ -74,7 +74,7 @@ export class FeedbackPage extends Page {
}

mapToObject(map: Map<string, any>) {
const tempObject: feedbackObject = {};
const tempObject: FeedbackObject = {};
map.forEach((value: any, key: string) => {
tempObject[key] = value;
});
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/resources/chromeos/audio/input_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ export class InputPage extends Page {
}
}

initAudio(audio_constraint: boolean|Object) {
initAudio(audioConstraint: boolean|Object) {
this.audioContext = new window.AudioContext();
navigator.mediaDevices.getUserMedia({'audio': audio_constraint})
.then((stream_got) => {
navigator.mediaDevices.getUserMedia({'audio': audioConstraint})
.then((streamGot) => {
if (this.audioContext) {
const stream = stream_got;
const stream = streamGot;
const source = this.audioContext.createMediaStreamSource(stream);
this.record(stream);
this.buildAudioGraph(source);
Expand Down
10 changes: 5 additions & 5 deletions chrome/browser/resources/discards/discards_tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {getTemplate} from './discards_tab.html.js';
import {LifecycleUnitDiscardReason, LifecycleUnitLoadingState, LifecycleUnitState} from './lifecycle_unit_state.mojom-webui.js';
import {SortedTableMixin} from './sorted_table_mixin.js';

type dictType = {
type DictType = {
[key: string]: (boolean|number|string),
};

Expand All @@ -30,7 +30,7 @@ type dictType = {
* number if a > b.
*/
export function compareTabDiscardsInfos(
sortKey: string, a: dictType, b: dictType): number {
sortKey: string, a: DictType, b: DictType): number {
let val1 = a[sortKey];
let val2 = b[sortKey];

Expand Down Expand Up @@ -123,14 +123,14 @@ class DiscardsTabElement extends DiscardsTabElementBase {
* @private
*/
private computeSortFunction_(sortKey: string, sortReverse: boolean):
(a: dictType, b: dictType) => number {
(a: DictType, b: DictType) => number {
// Polymer 2.0 may invoke multi-property observers before all properties
// are defined.
if (!sortKey) {
return (_a: dictType, _b: dictType) => 0;
return (_a: DictType, _b: DictType) => 0;
}

return function(a: dictType, b: dictType) {
return function(a: DictType, b: DictType) {
const comp = compareTabDiscardsInfos(sortKey, a, b);
return sortReverse ? -comp : comp;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {afterNextRender, PolymerElement} from 'chrome://resources/polymer/v3_0/p
import {navigateToNextStep, NavigationMixin} from '../navigation_mixin.js';
import {BookmarkBarManager, BookmarkProxy, BookmarkProxyImpl} from '../shared/bookmark_proxy.js';
import {ModuleMetricsManager} from '../shared/module_metrics_proxy.js';
import {stepIndicatorModel} from '../shared/nux_types.js';
import {StepIndicatorModel} from '../shared/nux_types.js';

import {GoogleAppProxy, GoogleAppProxyImpl} from './google_app_proxy.js';
import {GoogleAppsMetricsProxyImpl} from './google_apps_metrics_proxy.js';
Expand Down Expand Up @@ -88,7 +88,7 @@ export class NuxGoogleAppsElement extends NuxGoogleAppsElementBase {
private wasBookmarkBarShownOnInit_: boolean = false;
private appList_: AppItem[]|null = null;
private hasAppsSelected_: boolean = true;
indicatorModel?: stepIndicatorModel;
indicatorModel?: StepIndicatorModel;

constructor() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bu

import {navigateToNextStep, NavigationMixin} from '../navigation_mixin.js';
import {ModuleMetricsManager} from '../shared/module_metrics_proxy.js';
import {stepIndicatorModel} from '../shared/nux_types.js';
import {StepIndicatorModel} from '../shared/nux_types.js';

import {NtpBackgroundMetricsProxyImpl} from './ntp_background_metrics_proxy.js';
import {NtpBackgroundData, NtpBackgroundProxy, NtpBackgroundProxyImpl} from './ntp_background_proxy.js';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class NuxNtpBackgroundElement extends NuxNtpBackgroundElementBase {
private metricsManager_: ModuleMetricsManager;
private ntpBackgroundProxy_: NtpBackgroundProxy;
private selectedBackground_: NtpBackgroundData|undefined;
indicatorModel?: stepIndicatorModel;
indicatorModel?: StepIndicatorModel;

constructor() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {WebUIListenerMixin} from 'chrome://resources/js/web_ui_listener_mixin.js
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {navigateToNextStep, NavigationMixin} from '../navigation_mixin.js';
import {DefaultBrowserInfo, stepIndicatorModel} from '../shared/nux_types.js';
import {DefaultBrowserInfo, StepIndicatorModel} from '../shared/nux_types.js';

import {getTemplate} from './nux_set_as_default.html.js';
import {NuxSetAsDefaultProxy, NuxSetAsDefaultProxyImpl} from './nux_set_as_default_proxy.js';
Expand Down Expand Up @@ -62,7 +62,7 @@ export class NuxSetAsDefaultElement extends NuxSetAsDefaultElementBase {
private browserProxy_: NuxSetAsDefaultProxy;
private finalized_: boolean = false;
navigateToNextStep: Function;
indicatorModel?: stepIndicatorModel;
indicatorModel?: StepIndicatorModel;

constructor() {
super();
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/resources/welcome/shared/nux_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type BookmarkListItem = {
url: string,
};

export type stepIndicatorModel = {
export type StepIndicatorModel = {
total: number,
active: number,
};
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/welcome/shared/step_indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import './navi_colors.css.js';
import {I18nMixin} from 'chrome://resources/js/i18n_mixin.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';

import {stepIndicatorModel} from './nux_types.js';
import {StepIndicatorModel} from './nux_types.js';
import {getTemplate} from './step_indicator.html.js';

const StepIndicatorElementBase = I18nMixin(PolymerElement);
Expand All @@ -38,7 +38,7 @@ export class StepIndicatorElement extends StepIndicatorElementBase {
};
}

model?: stepIndicatorModel;
model?: StepIndicatorModel;
private dots_?: undefined[];

private computeLabel_(active: number, total: number): string {
Expand Down
2 changes: 1 addition & 1 deletion chrome/test/data/webui/chai_assert.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ export function assertNotEquals(
expected: any, actual: any, message?: string): void;
export function assertNotReached(message?: string): void;
export function assertThrows(
testFunction: () => any, expected_or_constructor?: (Function|string|RegExp),
testFunction: () => any, expectedOrConstructor?: (Function|string|RegExp),
message?: string): void;
export function assertArrayEquals(expected: any[], actual: any[]): void;
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,16 @@ export class TestAmbientProvider extends TestBrowserProxy implements
this.methodCalled('setAnimationTheme', animationTheme);
}

setTopicSource(topic_source: TopicSource) {
this.methodCalled('setTopicSource', topic_source);
setTopicSource(topicSource: TopicSource) {
this.methodCalled('setTopicSource', topicSource);
}

setTemperatureUnit(temperature_unit: TemperatureUnit) {
this.methodCalled('setTemperatureUnit', temperature_unit);
setTemperatureUnit(temperatureUnit: TemperatureUnit) {
this.methodCalled('setTemperatureUnit', temperatureUnit);
}

setAlbumSelected(id: string, topic_source: TopicSource, selected: boolean) {
this.methodCalled('setAlbumSelected', id, topic_source, selected);
setAlbumSelected(id: string, topicSource: TopicSource, selected: boolean) {
this.methodCalled('setAlbumSelected', id, topicSource, selected);
}

setPageViewed() {
Expand Down
26 changes: 13 additions & 13 deletions chrome/test/data/webui/extensions/test_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ export class ClickMock {
* Tests clicking on an element and expecting a call.
* @param element The element to click on.
* @param callName The function expected to be called.
* @param opt_expectedArgs The arguments the function is
* @param expectedArgs The arguments the function is
* expected to be called with.
* @param opt_returnValue The value to return from the function call.
* @param returnValue The value to return from the function call.
*/
testClickingCalls(
element: HTMLElement, callName: string, opt_expectedArgs: any[],
opt_returnValue?: any) {
element: HTMLElement, callName: string, expectedArgs: any[],
returnValue?: any) {
const mock = new MockController();
const mockMethod = mock.createFunctionMock(this, callName);
mockMethod.returnValue = opt_returnValue;
MockMethod.prototype.addExpectation.apply(mockMethod, opt_expectedArgs);
mockMethod.returnValue = returnValue;
MockMethod.prototype.addExpectation.apply(mockMethod, expectedArgs);
element.click();
mock.verifyMocks();
}
Expand Down Expand Up @@ -57,12 +57,12 @@ export class ListenerMock {

/**
* Adds an expected event.
* @param opt_eventArgs If omitted, will check that the details
* @param eventArgs If omitted, will check that the details
* are empty (i.e., {}).
*/
addListener(target: EventTarget, eventName: string, opt_eventArgs: any) {
addListener(target: EventTarget, eventName: string, eventArgs: any) {
assertTrue(!this.listeners_.hasOwnProperty(eventName));
this.listeners_[eventName] = {args: opt_eventArgs || {}, satisfied: false};
this.listeners_[eventName] = {args: eventArgs || {}, satisfied: false};
target.addEventListener(eventName, this.onEvent_.bind(this, eventName));
}

Expand Down Expand Up @@ -143,16 +143,16 @@ export function isElementVisible(element: HTMLElement): boolean {
* @param parentEl The parent element to query for the element.
* @param selector The selector to find the element.
* @param expectedVisible Whether the element should be visible.
* @param opt_expectedText The expected textContent value.
* @param expectedText The expected textContent value.
*/
export function testVisible(
parentEl: HTMLElement, selector: string, expectedVisible: boolean,
opt_expectedText?: string) {
expectedText?: string) {
const visible = isChildVisible(parentEl, selector);
assertEquals(expectedVisible, visible, selector);
if (expectedVisible && visible && opt_expectedText) {
if (expectedVisible && visible && expectedText) {
const element = parentEl.shadowRoot!.querySelector(selector)!;
assertEquals(opt_expectedText, element.textContent!.trim(), selector);
assertEquals(expectedText, element.textContent!.trim(), selector);
}
}

Expand Down
7 changes: 3 additions & 4 deletions chrome/test/data/webui/js/load_time_data_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ suite('LoadTimeDataModuleTest', function() {
test('getStringPieces', function() {
function assertSubstitutedPieces(
expected: {value: string, arg: (null|string)}[], label: string,
...var_args: (string|number)[]) {
const pieces =
loadTimeData.getSubstitutedStringPieces(label, ...var_args);
...args: (string|number)[]) {
const pieces = loadTimeData.getSubstitutedStringPieces(label, ...args);
assertDeepEquals(expected, pieces);

// Ensure output matches getStringF.
assertEquals(
loadTimeData.substituteString(label, ...var_args),
loadTimeData.substituteString(label, ...args),
pieces.map(p => p.value).join(''));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function createResults(n: number): SpeechRecognitionEvent {
} as unknown as SpeechRecognitionEvent;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
type webkitSpeechRecognitionError = SpeechRecognitionErrorEvent;
declare const webkitSpeechRecognitionError: typeof SpeechRecognitionErrorEvent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ suite(destination_store_test.suiteName, function() {

/*
* Sets the initial settings to the stored value and creates the page.
* @param opt_expectPrinterFailure Whether printer fetch is
* @param expectPrinterFailure Whether printer fetch is
* expected to fail
* @return Promise that resolves when initial settings and,
* if printer failure is not expected, printer capabilities have
* been returned.
*/
function setInitialSettings(opt_expectPrinterFailure?: boolean):
function setInitialSettings(expectPrinterFailure?: boolean):
Promise<{destinationId: string, printerType: PrinterType}> {
// Set local print list.
nativeLayer.setLocalDestinations(localDestinations);
Expand All @@ -109,7 +109,7 @@ suite(destination_store_test.suiteName, function() {
initialSettings.printerName,
initialSettings.serializedDefaultDestinationSelectionRulesStr,
recentDestinations);
return opt_expectPrinterFailure ? Promise.resolve() : Promise.race([
return expectPrinterFailure ? Promise.resolve() : Promise.race([
nativeLayer.whenCalled('getPrinterCapabilities'), whenCapabilitiesReady
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ export class NativeLayerCrosStub extends TestBrowserProxy implements

/**
* @param response The response to send when |setupPrinter| is called.
* @param opt_reject Whether printSetup requests should be
* @param reject Whether printSetup requests should be
* rejected. Defaults to false (will resolve callback) if not provided.
*/
setSetupPrinterResponse(
response: PrinterSetupResponse, opt_reject?: boolean) {
this.shouldRejectPrinterSetup_ = opt_reject || false;
setSetupPrinterResponse(response: PrinterSetupResponse, reject?: boolean) {
this.shouldRejectPrinterSetup_ = reject || false;
this.setupPrinterResponse_ = response;
}

Expand Down
6 changes: 3 additions & 3 deletions chrome/test/data/webui/print_preview/native_layer_stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,14 @@ export class NativeLayerStub extends TestBrowserProxy implements NativeLayer {
/**
* @param response The response to send for the destination whose ID is in the
* response.
* @param opt_reject Whether to reject the callback for this destination.
* @param reject Whether to reject the callback for this destination.
* Defaults to false (will resolve callback) if not provided.
*/
setLocalDestinationCapabilities(
response: CapabilitiesResponse, opt_reject?: boolean) {
response: CapabilitiesResponse, reject?: boolean) {
this.localDestinationCapabilities_.set(
response.printer!.deviceName,
opt_reject ? Promise.reject() : Promise.resolve(response));
reject ? Promise.reject() : Promise.resolve(response));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions chrome/test/data/webui/print_preview/print_preview_test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export function getDefaultInitialSettings(isPdf: boolean = false):
}

export function getCddTemplate(
printerId: string, opt_printerName?: string): CapabilitiesResponse {
printerId: string, printerName?: string): CapabilitiesResponse {
const template: CapabilitiesResponse = {
printer: {
deviceName: printerId,
printerName: opt_printerName || '',
printerName: printerName || '',
},
capabilities: {
version: '1.0',
Expand Down Expand Up @@ -100,12 +100,12 @@ export function getCddTemplate(
* capabilities, the values of these options are arbitrary. These values are
* provided and read by the destination, so there are no fixed options like
* there are for margins or color.
* @param opt_printerName Defaults to an empty string.
* @param printerName Defaults to an empty string.
*/
export function getCddTemplateWithAdvancedSettings(
numSettings: number, printerId: string,
opt_printerName?: string): CapabilitiesResponse {
const template = getCddTemplate(printerId, opt_printerName);
printerName?: string): CapabilitiesResponse {
const template = getCddTemplate(printerId, printerName);
if (numSettings < 1) {
return template;
}
Expand Down

0 comments on commit 684f427

Please sign in to comment.