Skip to content

Commit

Permalink
WebUI: Enforce one variable declaration per line with ESLint.
Browse files Browse the repository at this point in the history
Per the styleguide at [1]

"Every local variable declaration declares only one variable:
declarations such as let a = 1, b = 2; are not used."

Fixing all violations (using ESLint's --fix flag), and turning on the
one-var ESLint rule to catch such violations at PRESUBMIT time in the
future.

[1] https://google.github.io/styleguide/jsguide.html#features-one-variable-per-declaration

Bug: 720034
Change-Id: I369c12ef7d456722e03fbc8f178245fa82e638c6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3774879
Reviewed-by: John Lee <johntlee@chromium.org>
Reviewed-by: Luciano Pacheco <lucmult@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1026316}
  • Loading branch information
freshp86 authored and Chromium LUCI CQ committed Jul 20, 2022
1 parent b37cc21 commit d631d17
Show file tree
Hide file tree
Showing 28 changed files with 106 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ module.exports = {
'quotes': ['error', 'single', {allowTemplateLiterals: true}],
'semi': ['error', 'always'],

// https://google.github.io/styleguide/jsguide.html#features-one-variable-per-declaration
'one-var': ['error', {
let: 'never',
const: 'never',
}],

// TODO(dpapad): Add more checks according to our styleguide.
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export class PanStrategy {
const buf =
this.panStrategyWrapped_ ? this.wrappedBuffer_ : this.fixedBuffer_;

let startIndex, endIndex;
let startIndex;
let endIndex;
if (this.panStrategyWrapped_) {
startIndex = this.wrappedCursor_.start;
endIndex = this.wrappedCursor_.end;
Expand Down Expand Up @@ -353,7 +354,8 @@ export class PanStrategy {
const contentLength =
this.panStrategyWrapped_ ? this.wrappedLineCount : this.fixedLineCount;
if (this.viewPort_.firstRow > 0) {
let newStart, newEnd;
let newStart;
let newEnd;
if (this.viewPort_.firstRow < this.displaySize_.rows) {
newStart = 0;
newEnd = Math.min(this.displaySize_.rows, contentLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,8 @@ export class CommandHandler extends CommandHandlerInterface {
}

// Get word start and end indices.
let wordStarts, wordEnds;
let wordStarts;
let wordEnds;
if (node.role === RoleType.INLINE_TEXT_BOX) {
wordStarts = node.wordStarts;
wordEnds = node.wordEnds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ export class Output {
if (this.brailleBuffer_.length) {
const buff = this.mergeBraille_(this.brailleBuffer_);
const selSpan = buff.getSpanInstanceOf(OutputSelectionSpan);
let startIndex = -1, endIndex = -1;
let startIndex = -1;
let endIndex = -1;
if (selSpan) {
const valueStart = buff.getSpanStart(selSpan);
const valueEnd = buff.getSpanEnd(selSpan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ TEST_F('ChromeVoxTtsBackgroundTest', 'UpdateVoice', function() {
TEST_F(
'ChromeVoxTtsBackgroundTest', 'DISABLED_EmptyStringCallsCallbacks',
function() {
let startCalls = 0, endCalls = 0;
let startCalls = 0;
let endCalls = 0;
assertCallsCallbacks = (text, speakCalls) => {
tts.speak(text, QueueMode.QUEUE, {
startCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,8 @@ export class Panel extends PanelInterface {
Panel.brailleTableElement2_.deleteRow(0);
}

let row1, row2;
let row1;
let row2;
// Number of rows already written.
rowCount = 0;
// Number of cells already written in this row.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ MockFeedback = class {
* @private
*/
static matchAndConsume_(text, props, pending) {
let i, candidate;
let i;
let candidate;
for (i = 0; candidate = pending[i]; ++i) {
let candidateText = candidate.text;
if (typeof (candidateText) !== 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ AutomationPredicate = class {
const dir = opts.dir || Dir.FORWARD;

// Compute the row/col index defaulting to 0.
let rowIndex = 0, colIndex = 0;
let rowIndex = 0;
let colIndex = 0;
let tableNode = start;
while (tableNode) {
if (AutomationPredicate.table(tableNode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'GetUniqueAncestors',
async function() {
const root = await this.runWithLoadedTree(this.basicDoc());
let leftmost = root, rightmost = root;
let leftmost = root;
let rightmost = root;
while (leftmost.firstChild) {
leftmost = leftmost.firstChild;
}
Expand Down Expand Up @@ -142,7 +143,8 @@ AX_TEST_F(
'AccessibilityExtensionAutomationUtilE2ETest', 'GetDirection',
async function() {
const root = await this.runWithLoadedTree(this.basicDoc());
let left = root, right = root;
let left = root;
let right = root;

// Same node.
assertEquals(Dir.FORWARD, AutomationUtil.getDirection(left, right));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,17 @@ export class Cursor {

switch (movement) {
case CursorMovement.BOUND: {
let wordStarts, wordEnds;
let wordStarts;
let wordEnds;
if (newNode.role === RoleType.INLINE_TEXT_BOX) {
wordStarts = newNode.wordStarts;
wordEnds = newNode.wordEnds;
} else {
wordStarts = newNode.nonInlineTextWordStarts;
wordEnds = newNode.nonInlineTextWordEnds;
}
let start, end;
let start;
let end;
for (let i = 0; i < wordStarts.length; i++) {
if (newIndex >= wordStarts[i] && newIndex < wordEnds[i]) {
start = wordStarts[i];
Expand All @@ -351,7 +353,8 @@ export class Cursor {
}
// fallthrough
case CursorMovement.DIRECTIONAL: {
let wordStarts, wordEnds;
let wordStarts;
let wordEnds;
let start;
if (newNode.role === RoleType.INLINE_TEXT_BOX) {
wordStarts = newNode.wordStarts;
Expand Down Expand Up @@ -520,7 +523,8 @@ export class Cursor {
break;
}

let targetLine, targetIndex = 0;
let targetLine;
let targetIndex = 0;
for (let i = 0, line, cur = 0; line = lines[i]; i++) {
const lineLength = line.name ? line.name.length : 1;
cur += lineLength;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ export class CursorRange {
* Select the text contained within this range.
*/
select() {
let start = this.start_, end = this.end_;
let start = this.start_;
let end = this.end_;
if (this.start.compare(this.end) === constants.Dir.BACKWARD) {
start = this.end;
end = this.start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ export const RectUtil = {
return RectUtil.ZERO_RECT;
}

let above, below, toTheLeft, toTheRight;
let above;
let below;
let toTheLeft;
let toTheRight;

if (outer.top < subtrahend.top) {
above = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ export class NodeNavigationUtils {
*/
static getNodesForNextSentence(
currentNodeGroup, currentCharIndex, direction, pred) {
let nodes = [], offset;
let nodes = [];
let offset;
if (!currentNodeGroup) {
return {nodes, offset};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,8 @@ AX_TEST_F(
// Second paragraph has another two sentences.
assertEquals(nodeGroupForParagraph2.text, 'Line 3. Line 4. ');

let nodes, offset;
let nodes;
let offset;
// Navigating forward from the first sentence returns the second sentence.
({nodes, offset} = NodeNavigationUtils.getNodesForNextSentence(
nodeGroupForParagraph1, 0 /* currentCharIndex */,
Expand Down Expand Up @@ -793,7 +794,9 @@ AX_TEST_F(
nodeGroup.text,
'Line 1. This sentence is chopped. Another chopped sentence. ');

let nodes, offset, result;
let nodes;
let offset;
let result;
// Navigating forward from the first word returns the content starting
// from the second sentence.
({nodes, offset} = NodeNavigationUtils.getNodesForNextSentence(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,8 @@ export class NodeUtils {
* @return {!NodeUtils.Position}
*/
static getPositionFromNodeGroup(nodeGroup, charIndex, fallbackToEnd) {
let node, offset;
let node;
let offset;
if (charIndex !== undefined) {
({node, offset} = ParagraphUtils.findNodeFromNodeGroupByCharIndex(
nodeGroup, charIndex));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@ AX_TEST_F(
const thirdStatic = 'No child sentence.';
const thirdSentence = thirdStatic + ' ';

let nodeGroup, startIndexInGroup, endIndexInGroup;
let nodeGroup;
let startIndexInGroup;
let endIndexInGroup;
({nodeGroup, startIndexInGroup, endIndexInGroup} =
ParagraphUtils.buildSingleNodeGroupWithOffset(nodes));
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3536,7 +3536,9 @@ var parser = (function() {
}();
parser.lexer = lexer;

let page, point, objectToMatch;
let page;
let point;
let objectToMatch;

let indent = '';
const increaseIndent = () => indent = indent + ' ';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ Polymer({
attached() {
this.browserProxy_ = InternetDetailDialogBrowserProxyImpl.getInstance();
const dialogArgs = this.browserProxy_.getDialogArguments();
let type, name;
let type;
let name;
if (dialogArgs) {
const args = JSON.parse(dialogArgs);
this.guid = args.guid || '';
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/resources/hangout_services/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ function onProcessCpu(port) {
return;
}

let browserProcessCpu, gpuProcessCpu;
let browserProcessCpu;
let gpuProcessCpu;
for (const pid in processes) {
const process = processes[pid];
if (process.type === 'browser') {
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/resources/new_tab_page/modules/cart/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ export class ChromeCartModuleElement extends I18nMixin
*/
private onLeftScrollClick_() {
const carts = this.$.cartCarousel.querySelectorAll('.cart-container');
let visibleRange = 0, firstVisibleIndex = 0;
let visibleRange = 0;
let firstVisibleIndex = 0;
for (let i = carts.length - 1; i >= 0; i--) {
if (this.getVisibilityForIndex_(i)) {
visibleRange += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ export const LayoutBehavior = {
* @private
*/
calculateBounds_(id, width, height) {
let left, top;
let left;
let top;
const layout = this.displayLayoutMap_.get(id);
if (this.mirroring || !layout || !layout.parentId) {
left = -width / 2;
Expand Down Expand Up @@ -394,7 +395,8 @@ export const LayoutBehavior = {
if (x >= left && x < left + width && y >= top && y < top + height) {
return otherId;
} // point is inside rect
let dx, dy;
let dx;
let dy;
if (x < left) {
dx = left - x;
} else if (x > left + width) {
Expand Down Expand Up @@ -654,7 +656,9 @@ export const LayoutBehavior = {

// Offset is calculated from top or left edge.
const parentBounds = this.getCalculatedDisplayBounds(layout.parentId);
let offset, minOffset, maxOffset;
let offset;
let minOffset;
let maxOffset;
if (position === chrome.system.display.LayoutPosition.LEFT ||
position === chrome.system.display.LayoutPosition.RIGHT) {
offset = bounds.top - parentBounds.top;
Expand Down
17 changes: 14 additions & 3 deletions chrome/test/data/webui/bookmarks/extension_api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ test('bookmarkManagerPrivate', async () => {
const bookmarkManager = chrome.bookmarkManagerPrivate;
const {pass, fail, runTests} = simulateChromeExtensionAPITest();

let fooNode, fooNode2, barNode, gooNode, count, emptyFolder, emptyFolder2;
let folder, nodeA, nodeB;
let childFolder, grandChildFolder, childNodeA, childNodeB;
let fooNode;
let fooNode2;
let barNode;
let gooNode;
let count;
let emptyFolder;
let emptyFolder2;
let folder;
let nodeA;
let nodeB;
let childFolder;
let grandChildFolder;
let childNodeA;
let childNodeB;

function doCopy() {
bookmarkManager.copy.apply(null, arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ suite('SidePanelBookmarkDragManagerTest', () => {
});

test('DragStartCallsAPI', () => {
let calledIds, calledIndex, calledX, calledY;
let calledIds;
let calledIndex;
let calledX;
let calledY;
let calledTouch = false;
chrome.bookmarkManagerPrivate.startDrag =
(ids: string[], index: number, touch: boolean, x: number,
Expand Down Expand Up @@ -189,7 +192,8 @@ suite('SidePanelBookmarkDragManagerTest', () => {
});

test('DropsIntoFolder', () => {
let calledId, calledIndex;
let calledId;
let calledIndex;
chrome.bookmarkManagerPrivate.startDrag = () => {};
chrome.bookmarkManagerPrivate.drop = (id, index) => {
calledId = id;
Expand Down Expand Up @@ -217,7 +221,8 @@ suite('SidePanelBookmarkDragManagerTest', () => {
});

test('DropsBookmarksToReorder', () => {
let calledId, calledIndex;
let calledId;
let calledIndex;
chrome.bookmarkManagerPrivate.startDrag = () => {};
chrome.bookmarkManagerPrivate.drop = (id, index) => {
calledId = id;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ export class NavigationListModel extends EventTarget {
this.navigationItems_.push(shortcut);
}

let myFilesEntry, myFilesModel;
let myFilesEntry;
let myFilesModel;
if (!this.myFilesModel_) {
// When MyFilesVolume is enabled we use the Downloads volume to be the
// MyFiles volume.
Expand Down
12 changes: 8 additions & 4 deletions ui/file_manager/image_loader/piex_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,14 @@ class ImageBuffer {
bitmap.setUint32(62, /* BlueMask */ 0, true);
bitmap.setUint32(66, /* AlphaMask */ 0, true);

let rx = 0, ry = 0;
let gx = 0, gy = 0;
let bx = 0, by = 0;
let zz = 0, gg = 0;
let rx = 0;
let ry = 0;
let gx = 0;
let gy = 0;
let bx = 0;
let by = 0;
let zz = 0;
let gg = 0;

if (thumbnail.colorSpace !== 'adobeRgb') {
bitmap.setUint8(70, 's'.charCodeAt(0));
Expand Down
Loading

0 comments on commit d631d17

Please sign in to comment.