Skip to content

Commit 51bbdcb

Browse files
authored
Lint: Fix all ESLint errors (#664)
1 parent d50f71b commit 51bbdcb

File tree

26 files changed

+218
-131
lines changed

26 files changed

+218
-131
lines changed

.github/workflows/test.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,14 @@ jobs:
6363

6464
- run: yarn install --frozen-lockfile
6565
- run: yarn run prettier:check
66+
67+
docker:
68+
name: Build Docker image
69+
runs-on: ubuntu-latest
70+
permissions:
71+
contents: read # clone the repository
72+
steps:
73+
- uses: actions/checkout@v4
74+
with:
75+
persist-credentials: false
76+
- run: docker build .

devenv/loadtest/modules/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export const upsertTestdataDatasource = (client, name) => {
3333
if (res.status === 404) {
3434
res = client.datasources.create(payload);
3535

36-
if (res.status == 200) {
36+
if (res.status === 200) {
3737
id = res.json().id;
3838
}
39-
} else if (res.status == 200) {
39+
} else if (res.status === 200) {
4040
id = res.json().id;
4141
res = client.datasources.update(res.json().id, payload);
4242
}

eslint.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@ const grafanaConfig = require('@grafana/eslint-config/flat');
44

55
module.exports = tseslint.config(
66
{
7-
ignores: [".github", ".yarn", "**/build/", "**/compiled/", "**/dist/", "node_modules/"],
7+
ignores: [
8+
".github",
9+
".yarn",
10+
"**/build/",
11+
"**/compiled/",
12+
"**/dist/",
13+
"node_modules/",
14+
"scripts/",
15+
"devenv/",
16+
".prettierrc.js",
17+
"*.config.js",
18+
],
819
},
920

1021
eslint.configs.recommended,
1122
tseslint.configs.recommended,
1223
grafanaConfig,
24+
25+
{
26+
rules: {
27+
'@typescript-eslint/no-explicit-any': 'off', // Express litters them everywhere.
28+
},
29+
},
1330
);

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ module.exports = {
44
testEnvironment: 'node',
55
reporters: ['<rootDir>/tests/reporter.js'],
66
testTimeout: 20000,
7-
};
7+
};

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@
6060
"@eslint/js": "^9.31.0",
6161
"@grafana/eslint-config": "^8.1.0",
6262
"@stylistic/eslint-plugin-ts": "^4.4.1",
63+
"@types/content-disposition": "^0.5.9",
6364
"@types/express": "^4.17.14",
6465
"@types/jest": "^29.5.12",
6566
"@types/jsdom": "20.0.0",
67+
"@types/lodash": "^4.17.20",
68+
"@types/minimist": "^1.2.5",
69+
"@types/morgan": "^1.9.10",
6670
"@types/multer": "^1.4.7",
6771
"@types/node": "^20.17.27",
6872
"@types/pixelmatch": "^5.2.6",

src/app.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { startTracing } from './tracing';
2-
import * as path from 'path';
3-
import * as _ from 'lodash';
4-
import * as fs from 'fs';
2+
import path from 'path';
3+
import _ from 'lodash';
4+
import fs from 'fs';
55
import { Browser, computeExecutablePath } from '@puppeteer/browsers';
66
import { RenderGRPCPluginV2 } from './plugin/v2/grpc_plugin';
77
import { HttpServer } from './service/http-server';
8-
import { populateServiceConfigFromEnv, ServiceConfig, defaultServiceConfig } from './service/config';
9-
import { populatePluginConfigFromEnv, PluginConfig, defaultPluginConfig } from './plugin/v2/config';
8+
import { ServiceConfig } from './service/config';
9+
import { PluginConfig } from './plugin/v2/config';
1010
import { ConsoleLogger, PluginLogger } from './logger';
11-
import * as minimist from 'minimist';
11+
import minimist from 'minimist';
1212
import { serve } from './node-plugin';
1313
import { createSanitizer } from './sanitizer/Sanitizer';
1414
import { getConfig } from './config/config';
1515

1616
async function main() {
1717
const argv = minimist(process.argv.slice(2));
18-
const env = Object.assign({}, process.env);
1918
const command = argv._[0];
2019

2120
if (command === undefined) {

src/browser/browser.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ConsoleLogger } from '../logger';
22
import { RenderOptions } from '../types';
33
import { Browser } from './browser';
4-
import * as promClient from 'prom-client';
4+
import promClient from 'prom-client';
55

66
jest.mock('../logger');
77

@@ -58,7 +58,7 @@ describe('Test validateRenderOptions', () => {
5858
});
5959

6060
it('should use accept-language header if it exists', () => {
61-
let options: RenderOptions = {
61+
const options: RenderOptions = {
6262
url: 'http://localhost',
6363
filePath: '',
6464
timeout: 0,
@@ -75,7 +75,7 @@ describe('Test validateRenderOptions', () => {
7575
});
7676

7777
it('should use acceptLanguage configuration if no header is given', () => {
78-
let options: RenderOptions = {
78+
const options: RenderOptions = {
7979
url: 'http://localhost',
8080
filePath: '',
8181
timeout: 0,
@@ -89,7 +89,7 @@ describe('Test validateRenderOptions', () => {
8989
});
9090

9191
it('should use timeout option if given', () => {
92-
let options: RenderOptions = {
92+
const options: RenderOptions = {
9393
url: 'http://localhost',
9494
filePath: '',
9595
timeout: 5,
@@ -103,7 +103,7 @@ describe('Test validateRenderOptions', () => {
103103
});
104104

105105
it('should use default timeout if none is given', () => {
106-
let options: RenderOptions = {
106+
const options: RenderOptions = {
107107
url: 'http://localhost',
108108
filePath: '',
109109
timeout: 0,

src/browser/browser.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as os from 'os';
2-
import * as uniqueFilename from 'unique-filename';
1+
import os from 'os';
2+
import uniqueFilename from 'unique-filename';
33
import * as puppeteer from 'puppeteer';
4-
import * as chokidar from 'chokidar';
5-
import * as path from 'path';
6-
import * as fs from 'fs';
7-
import * as promClient from 'prom-client';
8-
import * as Jimp from 'jimp';
4+
import chokidar from 'chokidar';
5+
import path from 'path';
6+
import fs from 'fs';
7+
import promClient from 'prom-client';
8+
import Jimp from 'jimp';
99
import { Logger } from '../logger';
1010
import { RenderingConfig } from '../config/rendering';
1111
import { HTTPHeaders, ImageRenderOptions, RenderOptions } from '../types';
@@ -574,7 +574,7 @@ export class Browser {
574574
page.on('requestfailed', this.logRequestFailed);
575575
page.on('console', this.logConsoleMessage);
576576

577-
if (this.config.tracing.url.trim() != '') {
577+
if (this.config.tracing.url.trim() !== '') {
578578
await page.setRequestInterception(true);
579579

580580
page.on('request', this.addTracingHeaders(headers));

src/config/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import * as fs from 'fs';
2-
import * as _ from 'lodash';
3-
import * as minimist from 'minimist';
1+
import fs from 'fs';
2+
import _ from 'lodash';
3+
import minimist from 'minimist';
44
import { defaultServiceConfig, populateServiceConfigFromEnv, ServiceConfig } from '../service/config';
55
import { defaultPluginConfig, populatePluginConfigFromEnv, PluginConfig } from '../plugin/v2/config';
66

src/config/rendering.ts

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export enum Mode {
7979
}
8080

8181
type Keys<T> = {
82-
[K in keyof T]?: T[K] extends object ? (T[K] extends any[] ? string : Keys<T[K]>) : string;
82+
[K in keyof T]-?: T[K] extends object ? (T[K] extends any[] ? string : Keys<NonNullable<T[K]>>) : string;
8383
};
8484

8585
const envConfig: Record<Mode, Keys<RenderingConfig>> = {
@@ -101,13 +101,18 @@ const envConfig: Record<Mode, Keys<RenderingConfig>> = {
101101
mode: 'RENDERING_CLUSTERING_MODE',
102102
maxConcurrency: 'RENDERING_CLUSTERING_MAX_CONCURRENCY',
103103
timeout: 'RENDERING_CLUSTERING_TIMEOUT',
104+
monitor: 'RENDERING_CLUSTERING_MONITOR',
104105
},
105106
verboseLogging: 'RENDERING_VERBOSE_LOGGING',
106107
dumpio: 'RENDERING_DUMPIO',
107108
timingMetrics: 'RENDERING_TIMING_METRICS',
108109
tracing: {
109110
url: 'RENDERING_TRACING_URL',
111+
serviceName: 'RENDERING_TRACING_SERVICE_NAME',
110112
},
113+
headed: 'RENDERING_HEADED',
114+
emulateNetworkConditions: 'RENDERING_EMULATE_NETWORK_CONDITIONS',
115+
networkConditions: 'RENDERING_NETWORK_CONDITIONS',
111116
},
112117
plugin: {
113118
chromeBin: 'GF_PLUGIN_RENDERING_CHROME_BIN',
@@ -127,25 +132,30 @@ const envConfig: Record<Mode, Keys<RenderingConfig>> = {
127132
mode: 'GF_PLUGIN_RENDERING_CLUSTERING_MODE',
128133
maxConcurrency: 'GF_PLUGIN_RENDERING_CLUSTERING_MAX_CONCURRENCY',
129134
timeout: 'GF_PLUGIN_RENDERING_CLUSTERING_TIMEOUT',
135+
monitor: 'GF_PLUGIN_RENDERING_CLUSTERING_MONITOR',
130136
},
131137
verboseLogging: 'GF_PLUGIN_RENDERING_VERBOSE_LOGGING',
132138
dumpio: 'GF_PLUGIN_RENDERING_DUMPIO',
133139
timingMetrics: 'GF_PLUGIN_RENDERING_TIMING_METRICS',
134140
tracing: {
135141
url: 'GF_PLUGIN_RENDERING_TRACING_URL',
142+
serviceName: 'GF_PLUGIN_RENDERING_TRACING_SERVICE_NAME',
136143
},
144+
headed: 'GF_PLUGIN_RENDERING_HEADED',
145+
emulateNetworkConditions: 'GF_PLUGIN_RENDERING_EMULATE_NETWORK_CONDITIONS',
146+
networkConditions: 'GF_PLUGIN_RENDERING_NETWORK_CONDITIONS',
137147
},
138148
};
139149

140150
export function populateRenderingConfigFromEnv(config: RenderingConfig, env: NodeJS.ProcessEnv, mode: Mode) {
141151
const envKeys = envConfig[mode];
142152

143-
if (env[envKeys.chromeBin!]) {
144-
config.chromeBin = env[envKeys.chromeBin!];
153+
if (env[envKeys.chromeBin]) {
154+
config.chromeBin = env[envKeys.chromeBin];
145155
}
146156

147-
if (env[envKeys.args!]) {
148-
const args = env[envKeys.args!] as string;
157+
if (env[envKeys.args]) {
158+
const args = env[envKeys.args] as string;
149159
if (args.length > 0) {
150160
const argsList = args.split(',');
151161
if (argsList.length > 0) {
@@ -154,77 +164,95 @@ export function populateRenderingConfigFromEnv(config: RenderingConfig, env: Nod
154164
}
155165
}
156166

157-
if (env[envKeys.ignoresHttpsErrors!]) {
158-
config.ignoresHttpsErrors = env[envKeys.ignoresHttpsErrors!] === 'true';
167+
if (env[envKeys.ignoresHttpsErrors]) {
168+
config.ignoresHttpsErrors = env[envKeys.ignoresHttpsErrors] === 'true';
159169
}
160170

161-
if (env[envKeys.timezone!]) {
162-
config.timezone = env[envKeys.timezone!];
171+
if (env[envKeys.timezone]) {
172+
config.timezone = env[envKeys.timezone];
163173
} else if (env['TZ']) {
164174
config.timezone = env['TZ'];
165175
}
166176

167-
if (env[envKeys.acceptLanguage!]) {
168-
config.acceptLanguage = env[envKeys.acceptLanguage!];
177+
if (env[envKeys.acceptLanguage]) {
178+
config.acceptLanguage = env[envKeys.acceptLanguage];
169179
}
170180

171-
if (env[envKeys.width!]) {
172-
config.width = parseInt(env[envKeys.width!] as string, 10);
181+
if (env[envKeys.width]) {
182+
config.width = parseInt(env[envKeys.width] as string, 10);
173183
}
174184

175-
if (env[envKeys.height!]) {
176-
config.height = parseInt(env[envKeys.height!] as string, 10);
185+
if (env[envKeys.height]) {
186+
config.height = parseInt(env[envKeys.height] as string, 10);
177187
}
178188

179-
if (env[envKeys.deviceScaleFactor!]) {
180-
config.deviceScaleFactor = parseFloat(env[envKeys.deviceScaleFactor!] as string);
189+
if (env[envKeys.deviceScaleFactor]) {
190+
config.deviceScaleFactor = parseFloat(env[envKeys.deviceScaleFactor] as string);
181191
}
182192

183-
if (env[envKeys.maxWidth!]) {
184-
config.maxWidth = parseInt(env[envKeys.maxWidth!] as string, 10);
193+
if (env[envKeys.maxWidth]) {
194+
config.maxWidth = parseInt(env[envKeys.maxWidth] as string, 10);
185195
}
186196

187-
if (env[envKeys.maxHeight!]) {
188-
config.maxHeight = parseInt(env[envKeys.maxHeight!] as string, 10);
197+
if (env[envKeys.maxHeight]) {
198+
config.maxHeight = parseInt(env[envKeys.maxHeight] as string, 10);
189199
}
190200

191-
if (env[envKeys.maxDeviceScaleFactor!]) {
192-
config.maxDeviceScaleFactor = parseFloat(env[envKeys.maxDeviceScaleFactor!] as string);
201+
if (env[envKeys.maxDeviceScaleFactor]) {
202+
config.maxDeviceScaleFactor = parseFloat(env[envKeys.maxDeviceScaleFactor] as string);
193203
}
194204

195-
if (env[envKeys.pageZoomLevel!]) {
196-
config.pageZoomLevel = parseFloat(env[envKeys.pageZoomLevel!] as string);
205+
if (env[envKeys.pageZoomLevel]) {
206+
config.pageZoomLevel = parseFloat(env[envKeys.pageZoomLevel] as string);
197207
}
198208

199-
if (env[envKeys.mode!]) {
200-
config.mode = env[envKeys.mode!] as string;
209+
if (env[envKeys.mode]) {
210+
config.mode = env[envKeys.mode] as string;
201211
}
202212

203-
if (env[envKeys.clustering?.mode!]) {
204-
config.clustering.mode = env[envKeys.clustering?.mode!] as string;
213+
if (env[envKeys.clustering.mode]) {
214+
config.clustering.mode = env[envKeys.clustering.mode] as string;
205215
}
206-
207-
if (env[envKeys.clustering?.maxConcurrency!]) {
208-
config.clustering.maxConcurrency = parseInt(env[envKeys.clustering?.maxConcurrency!] as string, 10);
216+
if (env[envKeys.clustering.maxConcurrency]) {
217+
config.clustering.maxConcurrency = parseInt(env[envKeys.clustering.maxConcurrency] as string, 10);
218+
}
219+
if (env[envKeys.clustering.timeout]) {
220+
config.clustering.timeout = parseInt(env[envKeys.clustering.timeout] as string, 10);
221+
}
222+
if (env[envKeys.clustering.monitor]) {
223+
config.clustering.monitor = env[envKeys.clustering.monitor] === 'true';
209224
}
210225

211-
if (env[envKeys.clustering?.timeout!]) {
212-
config.clustering.timeout = parseInt(env[envKeys.clustering?.timeout!] as string, 10);
226+
if (env[envKeys.verboseLogging]) {
227+
config.verboseLogging = env[envKeys.verboseLogging] === 'true';
213228
}
214229

215-
if (env[envKeys.verboseLogging!]) {
216-
config.verboseLogging = env[envKeys.verboseLogging!] === 'true';
230+
if (env[envKeys.dumpio]) {
231+
config.dumpio = env[envKeys.dumpio] === 'true';
217232
}
218233

219-
if (env[envKeys.dumpio!]) {
220-
config.dumpio = env[envKeys.dumpio!] === 'true';
234+
if (env[envKeys.timingMetrics]) {
235+
config.timingMetrics = env[envKeys.timingMetrics] === 'true';
221236
}
222237

223-
if (env[envKeys.timingMetrics!]) {
224-
config.timingMetrics = env[envKeys.timingMetrics!] === 'true';
238+
if (env[envKeys.tracing.url]) {
239+
config.tracing.url = env[envKeys.tracing.url] as string;
240+
}
241+
if (env[envKeys.tracing.serviceName]) {
242+
config.tracing.serviceName = env[envKeys.tracing.serviceName] as string;
225243
}
226244

227-
if (env[envKeys.tracing?.url!]) {
228-
config.tracing.url = env[envKeys.tracing?.url!] as string;
245+
if (env[envKeys.headed]) {
246+
config.headed = env[envKeys.headed] === 'true';
247+
}
248+
if (env[envKeys.emulateNetworkConditions]) {
249+
config.emulateNetworkConditions = env[envKeys.emulateNetworkConditions] === 'true';
250+
}
251+
if (env[envKeys.networkConditions]) {
252+
try {
253+
config.networkConditions = JSON.parse(env[envKeys.networkConditions] as string);
254+
} catch (e) {
255+
throw new Error(`Invalid network conditions JSON: ${env[envKeys.networkConditions]}`);
256+
}
229257
}
230258
}

0 commit comments

Comments
 (0)