Commit 1f34fdb9 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Add a linter to the chromium-side of chrome://media-app

Linters are cool.

PRESUBMIT.py is the one that was in ui/file_manager, but with the path
adjusted so it can find `web_dev_style`.

.eslintrc.js is the one from ui/webui but with

  'parserOptions': {
    'ecmaVersion': 2018,
    'sourceType': 'module',
  },

added. This is needed to support `await` and spread syntax, and matches
our closure typechecking flags.

Note we also inherit the .eslintrc.js configuration in src/.eslintrc.js.


Fixes were mostly achieved by
  ./third_party/node/linux/node-linux-x64/bin/node \
      third_party/node/node_modules/eslint/bin/eslint.js \
      chromeos/components/media_app_ui/{test,resources/{js,mock}} --fix


The remaining bits were:
 -  document.getElementById is a restricted keyword. Recommendation is
to use resources/js/util.js, but I'm not sure we need/want that
dependency. Found a workaround (querySelector), but we might add that
dependency in a follow-up. (Where we use getElementById is placeholder/
experimental code currently).
 -  linter didn't like declaring a "namespace" like media_app. Changed
to declare pageHandler directly.
 -  linter also couldn't automatically fix the `==` -> `===`.

Bug: b/152284689
Change-Id: Ib12765ade3cc5f3a9f46448ad8741eb3b8434737
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119336Reviewed-by: default avatarPatti <patricialor@chromium.org>
Commit-Queue: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753523}
parent 7350e47a
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module.exports = {
'env': {
'browser': true,
'es6': true,
},
'parserOptions': {
'ecmaVersion': 2018,
'sourceType': 'module',
},
'rules': {
'eqeqeq': ['error', 'always', {'null': 'ignore'}],
},
};
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
def CheckChangeOnUpload(input_api, output_api):
return _CommonChecks(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
return _CommonChecks(input_api, output_api)
def _CommonChecks(input_api, output_api):
results = input_api.canned_checks.CheckPatchFormatted(input_api, output_api,
check_js=True)
try:
import sys
old_sys_path = sys.path[:]
cwd = input_api.PresubmitLocalPath()
sys.path += [input_api.os_path.join(cwd, '..', '..', '..', 'tools')]
from web_dev_style import presubmit_support
results += presubmit_support.CheckStyle(input_api, output_api)
finally:
sys.path = old_sys_path
return results
...@@ -43,7 +43,7 @@ let currentDirectoryHandle = null; ...@@ -43,7 +43,7 @@ let currentDirectoryHandle = null;
const guestMessagePipe = new MessagePipe('chrome://media-app-guest'); const guestMessagePipe = new MessagePipe('chrome://media-app-guest');
guestMessagePipe.registerHandler(Message.OPEN_FEEDBACK_DIALOG, () => { guestMessagePipe.registerHandler(Message.OPEN_FEEDBACK_DIALOG, () => {
let response = media_app.handler.openFeedbackDialog(); let response = mediaAppPageHandler.openFeedbackDialog();
if (response === null) { if (response === null) {
response = {errorMessage: 'Null response received'}; response = {errorMessage: 'Null response received'};
} }
...@@ -148,7 +148,7 @@ async function setCurrentDirectory(directory, focusFile) { ...@@ -148,7 +148,7 @@ async function setCurrentDirectory(directory, focusFile) {
currentFiles.push({token: -1, file: asFile.file, handle: asFile.handle}); currentFiles.push({token: -1, file: asFile.file, handle: asFile.handle});
} }
} }
entryIndex = currentFiles.findIndex(i => i.file.name == focusFile.name); entryIndex = currentFiles.findIndex(i => i.file.name === focusFile.name);
currentDirectoryHandle = directory; currentDirectoryHandle = directory;
sendFilesToGuest(); sendFilesToGuest();
} }
...@@ -183,9 +183,9 @@ async function advance(direction) { ...@@ -183,9 +183,9 @@ async function advance(direction) {
sendFilesToGuest(); sendFilesToGuest();
} }
document.getElementById('prev-container') document.querySelector('#prev-container')
.addEventListener('click', () => advance(-1)); .addEventListener('click', () => advance(-1));
document.getElementById('next-container') document.querySelector('#next-container')
.addEventListener('click', () => advance(1)); .addEventListener('click', () => advance(1));
// Wait for 'load' (and not DOMContentLoaded) to ensure the subframe has been // Wait for 'load' (and not DOMContentLoaded) to ensure the subframe has been
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
*/ */
/** @const */ /** @const */
var mediaApp = {}; const mediaApp = {};
/** /**
* Wraps an HTML File object (or a mock, or media loaded through another means). * Wraps an HTML File object (or a mock, or media loaded through another means).
......
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
const media_app = { const mediaAppPageHandler = new mediaAppUi.mojom.PageHandlerRemote();
handler: new mediaAppUi.mojom.PageHandlerRemote()
};
// Set up a page handler to talk to the browser process. // Set up a page handler to talk to the browser process.
mediaAppUi.mojom.PageHandlerFactory.getRemote().createPageHandler( mediaAppUi.mojom.PageHandlerFactory.getRemote().createPageHandler(
media_app.handler.$.bindNewPipeAndPassReceiver()); mediaAppPageHandler.$.bindNewPipeAndPassReceiver());
...@@ -72,7 +72,8 @@ class ReceivedFileList { ...@@ -72,7 +72,8 @@ class ReceivedFileList {
// don't break older versions of the media app which uses item(0) instead // don't break older versions of the media app which uses item(0) instead
// of getCurrentlyWritable() // of getCurrentlyWritable()
// TODO(b/151880563): remove this. // TODO(b/151880563): remove this.
let {files, writableFileIndex} = filesMessage; let writableFileIndex = filesMessage.writableFileIndex;
const files = filesMessage.files;
while (writableFileIndex > 0) { while (writableFileIndex > 0) {
files.push(files.shift()); files.push(files.shift());
writableFileIndex--; writableFileIndex--;
...@@ -102,7 +103,7 @@ class ReceivedFileList { ...@@ -102,7 +103,7 @@ class ReceivedFileList {
parentMessagePipe.registerHandler(Message.LOAD_FILES, (message) => { parentMessagePipe.registerHandler(Message.LOAD_FILES, (message) => {
const filesMessage = /** @type{!LoadFilesMessage} */ (message); const filesMessage = /** @type{!LoadFilesMessage} */ (message);
loadFiles(new ReceivedFileList(filesMessage)); loadFiles(new ReceivedFileList(filesMessage));
}) });
/** /**
* A delegate which exposes privileged WebUI functionality to the media * A delegate which exposes privileged WebUI functionality to the media
......
...@@ -37,7 +37,7 @@ class FileSystemWriter { ...@@ -37,7 +37,7 @@ class FileSystemWriter {
* data: (BufferSource|Blob|string|undefined) * data: (BufferSource|Blob|string|undefined)
* }} * }}
*/ */
var WriteParams; let WriteParams;
/** @interface */ /** @interface */
class FileSystemWritableFileStream { class FileSystemWritableFileStream {
...@@ -66,7 +66,7 @@ class FileSystemWritableFileStream { ...@@ -66,7 +66,7 @@ class FileSystemWritableFileStream {
} }
/** @typedef {{writable: boolean}} */ /** @typedef {{writable: boolean}} */
var FileSystemHandlePermissionDescriptor; let FileSystemHandlePermissionDescriptor;
/** @interface */ /** @interface */
class FileSystemHandle { class FileSystemHandle {
...@@ -101,7 +101,7 @@ class FileSystemHandle { ...@@ -101,7 +101,7 @@ class FileSystemHandle {
} }
/** @typedef {{keepExistingData: boolean}} */ /** @typedef {{keepExistingData: boolean}} */
var FileSystemCreateWriterOptions; let FileSystemCreateWriterOptions;
/** @interface */ /** @interface */
class FileSystemFileHandle extends FileSystemHandle { class FileSystemFileHandle extends FileSystemHandle {
...@@ -123,16 +123,16 @@ class FileSystemFileHandle extends FileSystemHandle { ...@@ -123,16 +123,16 @@ class FileSystemFileHandle extends FileSystemHandle {
} }
/** @typedef {{create: boolean}} */ /** @typedef {{create: boolean}} */
var FileSystemGetFileOptions; let FileSystemGetFileOptions;
/** @typedef {{create: boolean}} */ /** @typedef {{create: boolean}} */
var FileSystemGetDirectoryOptions; let FileSystemGetDirectoryOptions;
/** @typedef {{recursive: boolean}} */ /** @typedef {{recursive: boolean}} */
var FileSystemRemoveOptions; let FileSystemRemoveOptions;
/** @typedef {{type: string}} */ /** @typedef {{type: string}} */
var GetSystemDirectoryOptions; let GetSystemDirectoryOptions;
/** @interface */ /** @interface */
class FileSystemDirectoryHandle extends FileSystemHandle { class FileSystemDirectoryHandle extends FileSystemHandle {
...@@ -165,7 +165,7 @@ class FileSystemDirectoryHandle extends FileSystemHandle { ...@@ -165,7 +165,7 @@ class FileSystemDirectoryHandle extends FileSystemHandle {
* @return {Promise<!FileSystemDirectoryHandle>} * @return {Promise<!FileSystemDirectoryHandle>}
*/ */
static getSystemDirectory(options) {} static getSystemDirectory(options) {}
}; }
/** @interface */ /** @interface */
class LaunchParams { class LaunchParams {
...@@ -179,7 +179,7 @@ class LaunchParams { ...@@ -179,7 +179,7 @@ class LaunchParams {
} }
/** @typedef {function(LaunchParams)} */ /** @typedef {function(LaunchParams)} */
var LaunchConsumer; let LaunchConsumer;
/** @interface */ /** @interface */
class LaunchQueue { class LaunchQueue {
...@@ -194,7 +194,7 @@ class LaunchQueue { ...@@ -194,7 +194,7 @@ class LaunchQueue {
* extensions: (!Array<string>|undefined) * extensions: (!Array<string>|undefined)
* }} * }}
*/ */
var ChooseFileSystemEntriesOptionsAccepts; let ChooseFileSystemEntriesOptionsAccepts;
/** /**
* @typedef {{ * @typedef {{
...@@ -204,7 +204,7 @@ var ChooseFileSystemEntriesOptionsAccepts; ...@@ -204,7 +204,7 @@ var ChooseFileSystemEntriesOptionsAccepts;
* excludeAcceptAllOption: (boolean|undefined) * excludeAcceptAllOption: (boolean|undefined)
* }} * }}
*/ */
var chooseFileSystemEntriesOptions; let chooseFileSystemEntriesOptions;
/** /**
* @param {(!chooseFileSystemEntriesOptions|undefined)} options * @param {(!chooseFileSystemEntriesOptions|undefined)} options
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* @typedef{function(string): Promise<!HTMLElement>}} * @typedef{function(string): Promise<!HTMLElement>}}
*/ */
var ModuleHandler; let ModuleHandler;
/** @type{ModuleHandler} */ /** @type{ModuleHandler} */
const createVideoChild = async (blobSrc) => { const createVideoChild = async (blobSrc) => {
......
...@@ -56,7 +56,7 @@ class FakeWritableFileStream { ...@@ -56,7 +56,7 @@ class FakeWritableFileStream {
} }
/** @override */ /** @override */
async seek(offset) { async seek(offset) {
throw new Error('seek() not implemented.') throw new Error('seek() not implemented.');
} }
} }
...@@ -86,7 +86,7 @@ class FakeFileSystemFileHandle extends FakeFileSystemHandle { ...@@ -86,7 +86,7 @@ class FakeFileSystemFileHandle extends FakeFileSystemHandle {
} }
/** @override */ /** @override */
createWriter(options) { createWriter(options) {
throw new Error('createWriter() deprecated.') throw new Error('createWriter() deprecated.');
} }
/** @override */ /** @override */
async createWritable(options) { async createWritable(options) {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
/** @typedef {{testQueryResult: string}} */ /** @typedef {{testQueryResult: string}} */
var TestMessageResponseData; let TestMessageResponseData;
/** /**
* @typedef {{ * @typedef {{
...@@ -15,4 +15,4 @@ var TestMessageResponseData; ...@@ -15,4 +15,4 @@ var TestMessageResponseData;
* deleteLastFile: (boolean|undefined) * deleteLastFile: (boolean|undefined)
* }} * }}
*/ */
var TestMessageQueryData; let TestMessageQueryData;
...@@ -73,7 +73,7 @@ function installTestHandlers() { ...@@ -73,7 +73,7 @@ function installTestHandlers() {
loadFiles = async (/** !ReceivedFileList */ fileList) => { loadFiles = async (/** !ReceivedFileList */ fileList) => {
lastReceivedFileList = fileList; lastReceivedFileList = fileList;
realLoadFiles(fileList); realLoadFiles(fileList);
} };
} }
// Ensure content and all scripts have loaded before installing test handlers. // Ensure content and all scripts have loaded before installing test handlers.
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
GEN('#include "chromeos/constants/chromeos_features.h"'); GEN('#include "chromeos/constants/chromeos_features.h"');
// js2gtest fixtures require var here (https://crbug.com/1033337).
// eslint-disable-next-line no-var
var MediaAppGuestUIBrowserTest = class extends testing.Test { var MediaAppGuestUIBrowserTest = class extends testing.Test {
/** @override */ /** @override */
get browsePreload() { get browsePreload() {
......
...@@ -15,6 +15,8 @@ const GUEST_ORIGIN = 'chrome://media-app-guest'; ...@@ -15,6 +15,8 @@ const GUEST_ORIGIN = 'chrome://media-app-guest';
let driver = null; let driver = null;
// js2gtest fixtures require var here (https://crbug.com/1033337).
// eslint-disable-next-line no-var
var MediaAppUIBrowserTest = class extends testing.Test { var MediaAppUIBrowserTest = class extends testing.Test {
/** @override */ /** @override */
get browsePreload() { get browsePreload() {
...@@ -108,7 +110,7 @@ TEST_F('MediaAppUIBrowserTest', 'LoadFile', async () => { ...@@ -108,7 +110,7 @@ TEST_F('MediaAppUIBrowserTest', 'LoadFile', async () => {
// Tests that chrome://media-app can successfully send a request to open the // Tests that chrome://media-app can successfully send a request to open the
// feedback dialog and recieve a response. // feedback dialog and recieve a response.
TEST_F('MediaAppUIBrowserTest', 'CanOpenFeedbackDialog', async () => { TEST_F('MediaAppUIBrowserTest', 'CanOpenFeedbackDialog', async () => {
const result = await media_app.handler.openFeedbackDialog(); const result = await mediaAppPageHandler.openFeedbackDialog();
assertEquals(result.errorMessage, ''); assertEquals(result.errorMessage, '');
testDone(); testDone();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment