Skip to content

Commit

Permalink
Satisfy the TypeScript linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Katharine committed Feb 7, 2019
1 parent 7b35dc9 commit 4bef440
Show file tree
Hide file tree
Showing 20 changed files with 504 additions and 535 deletions.
32 changes: 16 additions & 16 deletions gopherage/cmd/html/static/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {enumerate, map} from './utils';
declare const embeddedProfiles: Array<{path: string, content: string}>;

let coverageFiles: Array<{name: string, coverage: Coverage}> = [];
let prefix = 'k8s.io/kubernetes/';
let gPrefix = 'k8s.io/kubernetes/';

function filenameForDisplay(path: string): string {
const basename = path.split('/').pop()!;
Expand All @@ -30,9 +30,9 @@ function filenameForDisplay(path: string): string {

function loadEmbeddedProfiles(): Array<{name: string, coverage: Coverage}> {
return embeddedProfiles.map(({path, content}) => ({
name: filenameForDisplay(path),
coverage: parseCoverage(content),
}));
coverage: parseCoverage(content),
name: filenameForDisplay(path),
}));
}

async function loadProfile(path: string): Promise<Coverage> {
Expand All @@ -43,16 +43,16 @@ async function loadProfile(path: string): Promise<Coverage> {

async function init(): Promise<void> {
if (location.hash.length > 1) {
prefix = location.hash.substring(1);
gPrefix = location.hash.substring(1);
}

coverageFiles = loadEmbeddedProfiles();
google.charts.load('current', {'packages': ['table']});
google.charts.load('current', {packages: ['table']});
google.charts.setOnLoadCallback(drawTable);
}

function updateBreadcrumb(): void {
const parts = prefix.split('/');
const parts = gPrefix.split('/');
const parent = document.getElementById('breadcrumbs')!;
parent.innerHTML = '';
let prefixSoFar = '';
Expand Down Expand Up @@ -98,17 +98,17 @@ function coveragesForPrefix(coverages: Coverage[], prefix: string):
}
const percentage = `${(coverage * 100).toFixed(1)}%`;
return {
f: `<span class="arrow">${arrow}</span> ${percentage}`,
v: coverage,
f: `<span class="arrow">${arrow}</span> ${percentage}`,
}
}))
};
})),
}));
}

function mergeMaps<T, U>(maps: Iterable<Map<T, U>>): Map<T, U[]> {
const result = new Map();
for (const [i, map] of enumerate(maps)) {
for (const [key, value] of map.entries()) {
for (const [i, m] of enumerate(maps)) {
for (const [key, value] of m.entries()) {
if (!result.has(key)) {
result.set(key, Array(i).fill(null));
}
Expand All @@ -125,14 +125,14 @@ function mergeMaps<T, U>(maps: Iterable<Map<T, U>>): Map<T, U[]> {

function drawTable(): void {
const rows = Array.from(
coveragesForPrefix(coverageFiles.map((x) => x.coverage), prefix));
coveragesForPrefix(coverageFiles.map((x) => x.coverage), gPrefix));
const cols = coverageFiles.map(
(x, i) => ({id: `file-${i}`, label: x.name, type: 'number'}));
const dataTable = new google.visualization.DataTable({
cols: [
{id: 'child', label: 'File', type: 'string'},
].concat(cols),
rows
rows,
});

const colourFormatter = new google.visualization.ColorFormat();
Expand All @@ -148,7 +148,7 @@ function drawTable(): void {
google.visualization.events.addListener(table, 'select', () => {
const child = rows[table.getSelection()[0].row!].c[0].v as string;
if (child.endsWith('/')) {
location.hash = prefix + child;
location.hash = gPrefix + child;
} else {
// TODO: this shouldn't be hardcoded.
// location.href = 'profiles/everything-diff.html#file' +
Expand All @@ -160,6 +160,6 @@ function drawTable(): void {

document.addEventListener('DOMContentLoaded', () => init());
window.addEventListener('hashchange', () => {
prefix = location.hash.substring(1);
gPrefix = location.hash.substring(1);
drawTable();
});
30 changes: 15 additions & 15 deletions gopherage/cmd/html/static/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ export interface Block {
end: Pos;
}


export class FileCoverage {
blocks: Block[] = [];
public blocks: Block[] = [];

constructor(readonly filename: string, readonly fileNumber: number) {}

addBlock(block: Block) {
public addBlock(block: Block) {
this.blocks.push(block);
}

Expand All @@ -49,24 +48,24 @@ export class FileCoverage {
}

export class Coverage {
files = new Map<string, FileCoverage>();
public files = new Map<string, FileCoverage>();

constructor(readonly mode: string, readonly prefix = '') {}

addFile(file: FileCoverage): void {
public addFile(file: FileCoverage): void {
this.files.set(file.filename, file);
}

getFile(name: string): FileCoverage|undefined {
public getFile(name: string): FileCoverage|undefined {
return this.files.get(name);
}

getFilesWithPrefix(prefix: string): Map<string, FileCoverage> {
public getFilesWithPrefix(prefix: string): Map<string, FileCoverage> {
return new Map(filter(
this.files.entries(), ([k]) => k.startsWith(this.prefix + prefix)));
}

getCoverageForPrefix(prefix: string): Coverage {
public getCoverageForPrefix(prefix: string): Coverage {
const subCoverage = new Coverage(this.mode, this.prefix + prefix);
for (const [filename, file] of this.files) {
if (filename.startsWith(this.prefix + prefix)) {
Expand All @@ -79,6 +78,7 @@ export class Coverage {
get children(): Map<string, Coverage> {
const children = new Map();
for (const path of this.files.keys()) {
// tslint:disable-next-line:prefer-const
let [dir, rest] = path.substr(this.prefix.length).split('/', 2);
if (!children.has(dir)) {
if (rest) {
Expand Down Expand Up @@ -121,7 +121,7 @@ export class Coverage {
export function parseCoverage(content: string): Coverage {
const lines = content.split('\n');
const modeLine = lines.shift()!;
const [modeLabel, mode] = modeLine.split(':').map(x => x.trim());
const [modeLabel, mode] = modeLine.split(':').map((x) => x.trim());
if (modeLabel !== 'mode') {
throw new Error('Expected to start with mode line.');
}
Expand Down Expand Up @@ -151,16 +151,16 @@ function parseLine(line: string): Block&{filename: string} {
const [startLine, startCol] = start.split('.').map(parseInt);
const [endLine, endCol] = end.split('.').map(parseInt);
return {
end: {
col: endCol,
line: endLine,
},
filename,
statements: Number(statements),
hits: Math.max(0, Number(hits)),
start: {
line: startLine,
col: startCol,
line: startLine,
},
end: {
line: endLine,
col: endCol,
},
statements: Number(statements),
};
}
6 changes: 3 additions & 3 deletions gopherage/cmd/html/static/utils_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('filter', () => {
describe('enumerate', () => {
it('should count up', () => {
expect(Array.from(enumerate(['hello', 'world']))).toEqual([
[0, 'hello'], [1, 'world']
[0, 'hello'], [1, 'world'],
]);
});

Expand Down Expand Up @@ -121,13 +121,13 @@ function iterableSpy<T>(output: T[]): [jasmine.Spy, Iterable<T>] {
// IteratorResult<T> is incorrect for finished iterators, apparently.
return {done: true} as IteratorResult<T>;
}
}
},
};

const iterable = {
[Symbol.iterator]() {
return iterator;
}
},
};

const spy = spyOn(iterator, 'next').and.callThrough();
Expand Down
5 changes: 2 additions & 3 deletions prow/cmd/deck/static/api/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export interface Context {
State: StatusState;
}


export interface Commit {
Status: {
Contexts: Context[];
}
};
OID: string;
}

Expand All @@ -43,4 +42,4 @@ export interface PullRequest {
HeadRefOID: string;
Mergeable: MergeableState;
Repository: Repository;
}
}
6 changes: 3 additions & 3 deletions prow/cmd/deck/static/api/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export interface PullRequest extends BasePullRequest {
Merged: boolean;
Title: string;
Labels: {
Nodes: {
Nodes: Array<{
Label: Label;
}[];
}>;
};
Milestone: {
Title: string;
}
};
}

export interface PullRequestWithContext {
Expand Down
10 changes: 5 additions & 5 deletions prow/cmd/deck/static/api/tide-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export interface HistoryData {
}

export interface Record {
time: string;
action: string;
baseSHA?: string;
target?: Pull[];
err?: string;
time: string;
action: string;
baseSHA?: string;
target?: Pull[];
err?: string;
}
8 changes: 4 additions & 4 deletions prow/cmd/deck/static/api/tide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export interface PullRequest extends BasePullRequest {
Title: string;
HeadRefName: string;
Commits: {
Nodes: {
Nodes: Array<{
Commit: Commit;
}[];
}>;
};
Labels: {
Nodes: {
Nodes: Array<{
Name: string;
}[];
}>;
};
Milestone?: {
Title: string;
Expand Down
34 changes: 16 additions & 18 deletions prow/cmd/deck/static/command-help/command-help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare const dialogPolyfill: {
};

function getParameterByName(name: string): string | null { // http://stackoverflow.com/a/5158301/3694
const match = new RegExp('[?&]' + name + '=([^&/]*)').exec(window.location.search);
const match = new RegExp(`[?&]${name}=([^&/]*)`).exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}

Expand All @@ -27,7 +27,7 @@ function redrawOptions(): void {
});
}

window.onload = function (): void {
window.onload = (): void => {
// set dropdown based on options from query string
const hash = window.location.hash;
redrawOptions();
Expand Down Expand Up @@ -132,11 +132,11 @@ function createCommandCell(data: string | string[], styles: string[] = [], noWra
* @param tooltip tooltip string
* @param isButton true if icon is a button
*/
function createIcon(no: number, iconString: string, styles: string[], tooltip: string, isButton?: false): HTMLDivElement
function createIcon(no: number, iconString: string, styles: string[], tooltip: string, isButton?: true): HTMLButtonElement
function createIcon(no: number, iconString: string, styles: string[], tooltip: string, isButton?: false): HTMLDivElement;
function createIcon(no: number, iconString: string, styles: string[], tooltip: string, isButton?: true): HTMLButtonElement;
function createIcon(no: number, iconString: string, styles: string[] = [], tooltip: string = "", isButton = false) {
const icon = document.createElement("i");
icon.id = "icon-" + iconString + "-" + no;
icon.id = `icon-${iconString}-${no}`;
icon.classList.add("material-icons");
icon.classList.add(...styles);
icon.innerHTML = iconString;
Expand Down Expand Up @@ -231,13 +231,13 @@ function createPluginCell(repo: string, pluginName: string, plugin: PluginHelp):
content.appendChild(addDialogSection("Description", plugin.Description));
}
if (plugin.Events) {
const sectionContent = "[" + plugin.Events.sort().join(", ") + "]";
const sectionContent = `[${plugin.Events.sort().join(", ")}]`;
content.appendChild(addDialogSection("Events handled", sectionContent));
}
if (plugin.Config) {
let sectionContent = plugin.Config ? plugin.Config[repo] : "";
let sectionTitle =
repo === "" ? "Configuration(global)" : "Configuration(" + repo + ")";
const sectionContent = plugin.Config ? plugin.Config[repo] : "";
const sectionTitle =
repo === "" ? "Configuration(global)" : `Configuration(${repo})`;
if (sectionContent && sectionContent !== "") {
content.appendChild(addDialogSection(sectionTitle, sectionContent));
}
Expand Down Expand Up @@ -284,7 +284,6 @@ function createCommandLink(name: string, no: number): HTMLTableDataCellElement {
return link;
}


/**
* Creates a row for the Command table.
* @param repo repo name.
Expand Down Expand Up @@ -329,12 +328,12 @@ function redrawHelpTable(repo: string, helpMap: Map<string, {isExternal: boolean
tableBody.removeChild(tableBody.firstChild!);
}
const names = Array.from(helpMap.keys());
const commandsWithPluginName: {pluginName: string, command: Command}[] = [];
for (let name of names) {
const commandsWithPluginName: Array<{pluginName: string, command: Command}> = [];
for (const name of names) {
helpMap.get(name)!.plugin.Commands.forEach((command) => {
commandsWithPluginName.push({
command,
pluginName: name,
command: command
});
});
}
Expand Down Expand Up @@ -366,7 +365,7 @@ function redraw(): void {
history.replaceState(null, "", "/command-help?repo="
+ encodeURIComponent(repoSel));
} else {
history.replaceState(null, "", "/command-help")
history.replaceState(null, "", "/command-help");
}
}
redrawOptions();
Expand All @@ -379,7 +378,7 @@ function redraw(): void {
name,
{
isExternal: false,
plugin: allHelp.PluginHelp[name]
plugin: allHelp.PluginHelp[name],
});
}
});
Expand All @@ -391,14 +390,13 @@ function redraw(): void {
name,
{
isExternal: true,
plugin: allHelp.ExternalPluginHelp[name]
plugin: allHelp.ExternalPluginHelp[name],
});
}
});
redrawHelpTable(repoSel, pluginsWithCommands);
}


/**
* Extracts a command name from a command example. It takes the first example,
* with out the slash, as the name for the command. Also, any '-' character is
Expand All @@ -413,4 +411,4 @@ function extractCommandName(commandExample: string): string {
}

// This is referenced by name in the HTML.
(window as any)['redraw'] = redraw;
(window as any).redraw = redraw;
Loading

0 comments on commit 4bef440

Please sign in to comment.