Skip to content

Commit 4e5877c

Browse files
committed
migrate to eslint & update dependencies & apply suggestions by --fix
1 parent eee3742 commit 4e5877c

File tree

34 files changed

+4001
-3128
lines changed

34 files changed

+4001
-3128
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ secret.yaml
3030

3131
# Binaries
3232
logexporter/cmd/logexporter
33+
34+
# artifacts
35+
package-lock.json

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ verify-go-deps:
6363
verify:
6464
hack/make-rules/verify/all.sh
6565
# typescript linting
66-
.PHONY: verify-tslint
67-
verify-tslint:
68-
hack/make-rules/verify/tslint.sh
66+
.PHONY: verify-eslint
67+
verify-eslint:
68+
hack/make-rules/verify/eslint.sh
6969
# go linters
7070
.PHONY: go-lint
7171
go-lint:

eslintrc.js

+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
/*
2+
👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3+
https://github.com/typescript-eslint/tslint-to-eslint-config
4+
5+
It represents the closest reasonable ESLint configuration to this
6+
project's original TSLint configuration.
7+
8+
We recommend eventually switching this configuration to extend from
9+
the recommended rulesets in typescript-eslint.
10+
https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11+
12+
Happy linting! 💖
13+
*/
14+
module.exports = {
15+
"env": {
16+
"browser": true,
17+
"es6": true
18+
},
19+
"extends": [
20+
"plugin:@typescript-eslint/recommended",
21+
"plugin:@typescript-eslint/recommended-requiring-type-checking"
22+
],
23+
"parser": "@typescript-eslint/parser",
24+
"parserOptions": {
25+
"project": "tsconfig.json",
26+
"sourceType": "module"
27+
},
28+
"plugins": [
29+
"eslint-plugin-jsdoc",
30+
"eslint-plugin-prefer-arrow",
31+
"@typescript-eslint"
32+
],
33+
"root": true,
34+
"rules": {
35+
"@typescript-eslint/adjacent-overload-signatures": "error",
36+
"@typescript-eslint/array-type": [
37+
"error",
38+
{
39+
"default": "array"
40+
}
41+
],
42+
"@typescript-eslint/ban-types": [
43+
"error",
44+
{
45+
"types": {
46+
"Object": {
47+
"message": "Avoid using the `Object` type. Did you mean `object`?"
48+
},
49+
"Function": {
50+
"message": "Avoid using the `Function` type. Prefer a specific function type, like `() => void`."
51+
},
52+
"Boolean": {
53+
"message": "Avoid using the `Boolean` type. Did you mean `boolean`?"
54+
},
55+
"Number": {
56+
"message": "Avoid using the `Number` type. Did you mean `number`?"
57+
},
58+
"String": {
59+
"message": "Avoid using the `String` type. Did you mean `string`?"
60+
},
61+
"Symbol": {
62+
"message": "Avoid using the `Symbol` type. Did you mean `symbol`?"
63+
}
64+
}
65+
}
66+
],
67+
"@typescript-eslint/restrict-template-expressions": "warn",
68+
"@typescript-eslint/no-unsafe-assignment": "warn",
69+
"@typescript-eslint/no-unsafe-member-access": "off",
70+
"@typescript-eslint/consistent-type-assertions": "error",
71+
"@typescript-eslint/dot-notation": "error",
72+
"@typescript-eslint/explicit-function-return-type": "off",
73+
"@typescript-eslint/explicit-module-boundary-types": "off",
74+
"@typescript-eslint/indent": [
75+
"error",
76+
2
77+
],
78+
"@typescript-eslint/naming-convention": "off",
79+
"@typescript-eslint/no-empty-function": "error",
80+
"@typescript-eslint/no-empty-interface": "error",
81+
"@typescript-eslint/no-explicit-any": "off",
82+
"@typescript-eslint/no-misused-new": "error",
83+
"@typescript-eslint/no-namespace": "error",
84+
"@typescript-eslint/no-parameter-properties": "off",
85+
"@typescript-eslint/no-shadow": [
86+
"error",
87+
{
88+
"hoist": "all"
89+
}
90+
],
91+
"@typescript-eslint/no-unused-expressions": "error",
92+
"@typescript-eslint/no-use-before-define": "off",
93+
"@typescript-eslint/no-var-requires": "error",
94+
"@typescript-eslint/prefer-for-of": "error",
95+
"@typescript-eslint/prefer-function-type": "error",
96+
"@typescript-eslint/prefer-namespace-keyword": "error",
97+
"@typescript-eslint/quotes": "off",
98+
"@typescript-eslint/triple-slash-reference": [
99+
"error",
100+
{
101+
"path": "always",
102+
"types": "prefer-import",
103+
"lib": "always"
104+
}
105+
],
106+
"@typescript-eslint/typedef": "off",
107+
"@typescript-eslint/unified-signatures": "error",
108+
"complexity": "off",
109+
"constructor-super": "error",
110+
"dot-notation": "off",
111+
"eqeqeq": [
112+
"error",
113+
"smart"
114+
],
115+
"guard-for-in": "error",
116+
"id-denylist": [
117+
"error",
118+
"any",
119+
"String",
120+
"string",
121+
"Boolean",
122+
"boolean",
123+
"Undefined",
124+
"undefined"
125+
],
126+
"id-match": "error",
127+
"indent": "off",
128+
"jsdoc/check-alignment": "error",
129+
"jsdoc/check-indentation": "error",
130+
"jsdoc/newline-after-description": "error",
131+
"max-classes-per-file": "off",
132+
"max-len": "off",
133+
"new-parens": "error",
134+
"no-bitwise": "error",
135+
"no-caller": "error",
136+
"no-cond-assign": "error",
137+
"no-console": "off",
138+
"no-debugger": "error",
139+
"no-empty": "error",
140+
"no-empty-function": "off",
141+
"no-eval": "error",
142+
"no-fallthrough": "off",
143+
"no-invalid-this": "off",
144+
"no-new-wrappers": "error",
145+
"no-shadow": "off",
146+
"no-throw-literal": "error",
147+
"no-trailing-spaces": "error",
148+
"no-undef-init": "error",
149+
"no-underscore-dangle": "off",
150+
"no-unsafe-finally": "error",
151+
"no-unused-expressions": "off",
152+
"no-unused-labels": "error",
153+
"no-use-before-define": "off",
154+
"no-var": "error",
155+
"object-shorthand": "error",
156+
"one-var": [
157+
"error",
158+
"never"
159+
],
160+
"prefer-arrow/prefer-arrow-functions": "warn",
161+
"prefer-const": "error",
162+
"prefer-template": "error",
163+
"quotes": "off",
164+
"radix": "error",
165+
"spaced-comment": [
166+
"error",
167+
"always",
168+
{
169+
"markers": [
170+
"/"
171+
]
172+
}
173+
],
174+
"use-isnan": "error",
175+
"valid-typeof": "off"
176+
}
177+
};

gopherage/cmd/html/static/browser.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ limitations under the License.
1717
import {Coverage, parseCoverage} from './parser';
1818
import {enumerate, map} from './utils';
1919

20-
declare const embeddedProfiles: Array<{path: string, content: string}>;
20+
declare const embeddedProfiles: {path: string, content: string}[];
2121

22-
let coverageFiles: Array<{name: string, coverage: Coverage}> = [];
22+
let coverageFiles: {name: string, coverage: Coverage}[] = [];
2323
let gPrefix = '';
2424

2525
function filenameForDisplay(path: string): string {
@@ -28,7 +28,7 @@ function filenameForDisplay(path: string): string {
2828
return withoutSuffix;
2929
}
3030

31-
function loadEmbeddedProfiles(): Array<{name: string, coverage: Coverage}> {
31+
function loadEmbeddedProfiles(): {name: string, coverage: Coverage}[] {
3232
return embeddedProfiles.map(({path, content}) => ({
3333
coverage: parseCoverage(content),
3434
name: filenameForDisplay(path),
@@ -60,7 +60,7 @@ function updateBreadcrumb(): void {
6060
if (!part) {
6161
continue;
6262
}
63-
prefixSoFar += part + '/';
63+
prefixSoFar += `${part }/`;
6464
const node = document.createElement('a');
6565
node.href = `#${prefixSoFar}`;
6666
node.innerText = part;
@@ -70,39 +70,39 @@ function updateBreadcrumb(): void {
7070
}
7171

7272
function coveragesForPrefix(coverages: Coverage[], prefix: string):
73-
Iterable<{c: Array<{v: number | string, f?: string}>}> {
73+
Iterable<{c: {v: number | string, f?: string}[]}> {
7474
const m =
7575
mergeMaps(map(coverages, (c) => c.getCoverageForPrefix(prefix).children));
7676
const keys = Array.from(m.keys());
7777
keys.sort();
7878
console.log(m);
7979
return map(
80-
keys,
81-
(k) => ({
82-
c: [({v: k} as {v: number | string, f?: string})].concat(
83-
m.get(k)!.map((x, i) => {
84-
if (!x) {
85-
return {v: ''};
86-
}
87-
const next = m.get(k)![i + 1];
88-
const coverage = x.coveredStatements / x.totalStatements;
89-
let arrow = '';
90-
if (next) {
91-
const nextCoverage =
80+
keys,
81+
(k) => ({
82+
c: [({v: k} as {v: number | string, f?: string})].concat(
83+
m.get(k)!.map((x, i) => {
84+
if (!x) {
85+
return {v: ''};
86+
}
87+
const next = m.get(k)![i + 1];
88+
const coverage = x.coveredStatements / x.totalStatements;
89+
let arrow = '';
90+
if (next) {
91+
const nextCoverage =
9292
next.coveredStatements / next.totalStatements;
93-
if (coverage > nextCoverage) {
94-
arrow = '▲';
95-
} else if (coverage < nextCoverage) {
96-
arrow = '▼';
97-
}
98-
}
99-
const percentage = `${(coverage * 100).toFixed(1)}%`;
100-
return {
101-
f: `<span class="arrow">${arrow}</span> ${percentage}`,
102-
v: coverage,
103-
};
104-
})),
105-
}));
93+
if (coverage > nextCoverage) {
94+
arrow = '▲';
95+
} else if (coverage < nextCoverage) {
96+
arrow = '▼';
97+
}
98+
}
99+
const percentage = `${(coverage * 100).toFixed(1)}%`;
100+
return {
101+
f: `<span class="arrow">${arrow}</span> ${percentage}`,
102+
v: coverage,
103+
};
104+
})),
105+
}));
106106
}
107107

108108
function mergeMaps<T, U>(maps: Iterable<Map<T, U>>): Map<T, U[]> {
@@ -125,9 +125,9 @@ function mergeMaps<T, U>(maps: Iterable<Map<T, U>>): Map<T, U[]> {
125125

126126
function drawTable(): void {
127127
const rows = Array.from(
128-
coveragesForPrefix(coverageFiles.map((x) => x.coverage), gPrefix));
128+
coveragesForPrefix(coverageFiles.map((x) => x.coverage), gPrefix));
129129
const cols = coverageFiles.map(
130-
(x, i) => ({id: `file-${i}`, label: x.name, type: 'number'}));
130+
(x, i) => ({id: `file-${i}`, label: x.name, type: 'number'}));
131131
const dataTable = new google.visualization.DataTable({
132132
cols: [
133133
{id: 'child', label: 'File', type: 'string'},

gopherage/cmd/html/static/parser.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class FileCoverage {
4949

5050
get coveredStatements(): number {
5151
return reduce(this.blocks.values(),
52-
(acc, b) => acc + (b.hits > 0 ? b.statements : 0), 0);
52+
(acc, b) => acc + (b.hits > 0 ? b.statements : 0), 0);
5353
}
5454

5555
private keyForBlock(block: Block): string {
@@ -72,7 +72,7 @@ export class Coverage {
7272

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

7878
public getCoverageForPrefix(prefix: string): Coverage {
@@ -88,7 +88,7 @@ export class Coverage {
8888
get children(): Map<string, Coverage> {
8989
const children = new Map();
9090
for (const path of this.files.keys()) {
91-
// tslint:disable-next-line:prefer-const
91+
// eslint-disable-next-line prefer-const
9292
let [dir, rest] = path.substr(this.prefix.length).split('/', 2);
9393
if (!children.has(dir)) {
9494
if (rest) {
@@ -102,8 +102,8 @@ export class Coverage {
102102

103103
get basename(): string {
104104
if (this.prefix.endsWith('/')) {
105-
return this.prefix.substring(0, this.prefix.length - 1).split('/').pop() +
106-
'/';
105+
return `${this.prefix.substring(0, this.prefix.length - 1).split('/').pop()
106+
}/`;
107107
}
108108
return this.prefix.split('/').pop()!;
109109
}
@@ -114,7 +114,7 @@ export class Coverage {
114114

115115
get coveredStatements(): number {
116116
return reduce(
117-
this.files.values(), (acc, f) => acc + f.coveredStatements, 0);
117+
this.files.values(), (acc, f) => acc + f.coveredStatements, 0);
118118
}
119119

120120
get totalFiles(): number {
@@ -123,8 +123,8 @@ export class Coverage {
123123

124124
get coveredFiles(): number {
125125
return reduce(
126-
this.files.values(),
127-
(acc, f) => acc + (f.coveredStatements > 0 ? 1 : 0), 0);
126+
this.files.values(),
127+
(acc, f) => acc + (f.coveredStatements > 0 ? 1 : 0), 0);
128128
}
129129
}
130130

gopherage/cmd/html/static/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ limitations under the License.
1818
// Provide our own tools.
1919

2020
export function*
21-
map<T, U>(iterable: Iterable<T>, fn: (value: T) => U): Iterable<U> {
21+
map<T, U>(iterable: Iterable<T>, fn: (value: T) => U): Iterable<U> {
2222
for (const entry of iterable) {
2323
yield fn(entry);
2424
}
2525
}
2626

2727
export function reduce<T, U>(
28-
iterable: Iterable<T>, fn: (acc: U, value: T) => U, initialValue: U): U {
28+
iterable: Iterable<T>, fn: (acc: U, value: T) => U, initialValue: U): U {
2929
let accumulator = initialValue;
3030
for (const entry of iterable) {
3131
accumulator = fn(accumulator, entry);
@@ -34,7 +34,7 @@ export function reduce<T, U>(
3434
}
3535

3636
export function*
37-
filter<T>(iterable: Iterable<T>, fn: (value: T) => boolean): Iterable<T> {
37+
filter<T>(iterable: Iterable<T>, fn: (value: T) => boolean): Iterable<T> {
3838
for (const entry of iterable) {
3939
if (fn(entry)) {
4040
yield entry;

0 commit comments

Comments
 (0)