Skip to content

Commit 82f7757

Browse files
committed
improve eslint's happiness
1 parent d43d0ca commit 82f7757

12 files changed

+53
-85
lines changed

eslint.config.js

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -45,62 +45,30 @@ export default [
4545
globals: { ...globals.node },
4646
},
4747
rules: {
48-
"unicorn/no-console-spaces": "error",
49-
// "unicorn/filename-case": "error",
50-
// "unicorn/better-regex": "error",
51-
// "unicorn/catch-error-name": "error",
52-
// "unicorn/consistent-destructuring": "error",
53-
// "unicorn/consistent-function-scoping": "error",
54-
// "unicorn/custom-error-definition": "off",
55-
// "unicorn/empty-brace-spaces": "error",
56-
// "unicorn/error-message": "error",
57-
// "unicorn/escape-case": "error",
58-
// "unicorn/expiring-todo-comments": "error",
59-
// "unicorn/explicit-length-check": "error",
60-
// "unicorn/import-style": "error",
61-
// "unicorn/new-for-builtins": "error",
62-
// "unicorn/no-abusive-eslint-disable": "error",
63-
// "unicorn/no-array-callback-reference": "error",
64-
// "unicorn/no-array-for-each": "error",
65-
// "unicorn/no-array-method-this-argument": "error",
66-
// "unicorn/no-array-push-push": "error",
67-
// "unicorn/no-array-reduce": "error",
68-
// "unicorn/no-await-expression-member": "error",
69-
// "unicorn/no-console-spaces": "error",
70-
// "unicorn/no-document-cookie": "error",
71-
// "unicorn/no-empty-file": "error",
72-
// "unicorn/no-for-loop": "error",
73-
// "unicorn/no-hex-escape": "error",
74-
// "unicorn/no-instanceof-array": "error",
75-
// "unicorn/no-invalid-remove-event-listener": "error",
76-
// "unicorn/no-keyword-prefix": "off",
77-
// "unicorn/no-lonely-if": "error",
78-
// "no-negated-condition": "off",
79-
// "unicorn/no-negated-condition": "error",
80-
// "no-nested-ternary": "off",
81-
// "unicorn/no-nested-ternary": "error",
82-
// "unicorn/no-new-array": "error",
83-
// "unicorn/no-new-buffer": "error",
84-
// "unicorn/no-null": "error",
85-
// "unicorn/no-object-as-default-parameter": "error",
86-
// "unicorn/no-process-exit": "error",
87-
// "unicorn/no-static-only-class": "error",
88-
// "unicorn/no-thenable": "error",
89-
// "unicorn/no-this-assignment": "error",
90-
// "unicorn/no-typeof-undefined": "error",
91-
// "unicorn/no-unnecessary-await": "error",
92-
// "unicorn/no-unreadable-array-destructuring": "error",
93-
// "unicorn/no-unreadable-iife": "error",
94-
// "unicorn/no-unused-properties": "off",
95-
// "unicorn/no-useless-fallback-in-spread": "error",
96-
// "unicorn/no-useless-length-check": "error",
97-
// "unicorn/no-useless-promise-resolve-reject": "error",
98-
// "unicorn/no-useless-spread": "error",
99-
// "unicorn/no-useless-switch-case": "error",
100-
// "unicorn/no-useless-undefined": "error",
101-
// "unicorn/no-zero-fractions": "error",
102-
// "unicorn/number-literal-case": "error",
103-
// "unicorn/numeric-separators-style": "error",
48+
...unicorn.configs.recommended.rules,
49+
// no:
50+
"unicorn/filename-case": "off",
51+
"unicorn/no-for-loop": "off",
52+
"unicorn/no-process-exit": "off",
53+
"unicorn/numeric-separators-style": "off",
54+
"unicorn/prevent-abbreviations": "off",
55+
"unicorn/prefer-spread": "off",
56+
"unicorn/prefer-ternary": "off",
57+
"unicorn/require-number-to-fixed-digits-argument": "off",
58+
"unicorn/prefer-set-has": "off",
59+
// maybe not:
60+
"unicorn/consistent-function-scoping": "off",
61+
"unicorn/no-array-for-each": "off",
62+
"unicorn/no-await-expression-member": "off",
63+
"unicorn/no-zero-fractions": "off",
64+
"unicorn/prefer-top-level-await": "off",
65+
"unicorn/prefer-module": "off",
66+
// maybe add later:
67+
"unicorn/no-null": "off",
68+
"unicorn/switch-case-braces": "off",
69+
"unicorn/prefer-dom-node-text-content": "off",
70+
"unicorn/prefer-optional-catch-binding": "off",
71+
"unicorn/prefer-logical-operator-over-ternary": "off",
10472

10573
"no-unused-vars": "off",
10674
"@typescript-eslint/no-explicit-any": "off",

webdriver-ts/src/benchmarkRunner.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
FrameworkData,
88
initializeFrameworks,
99
} from "./common.js";
10-
import { fork } from "child_process";
11-
import * as fs from "fs";
10+
import { fork } from "node:child_process";
11+
import * as fs from "node:fs";
1212
import {
1313
BenchmarkInfo,
1414
benchmarkInfos,
@@ -94,7 +94,7 @@ async function runBenchmakLoopStartup(
9494
} else results.push(res.result);
9595
warnings = warnings.concat(res.warnings);
9696
if (res.error) {
97-
if (res.error.indexOf("Server terminated early with status 1") > -1) {
97+
if (res.error.includes("Server terminated early with status 1")) {
9898
console.log("******* STRANGE selenium error found - retry #", retries + 1);
9999
retries++;
100100
if (retries == 3) break;
@@ -155,7 +155,7 @@ async function runBenchmakLoop(
155155
}
156156
warnings = warnings.concat(res.warnings);
157157
if (res.error) {
158-
if (res.error.indexOf("Server terminated early with status 1") > -1) {
158+
if (res.error.includes("Server terminated early with status 1")) {
159159
console.log("******* STRANGE selenium error found - retry #", retries + 1);
160160
retries++;
161161
if (retries == 3) break;
@@ -205,7 +205,7 @@ async function runBench(
205205
let errors: string[] = [];
206206
let warnings: string[] = [];
207207

208-
let restart: string = undefined;
208+
let restart: string;
209209
let index = runFrameworks.findIndex((f) => f.fullNameWithKeyedAndVersion === restart);
210210
if (index > -1) {
211211
runFrameworks = runFrameworks.slice(index);
@@ -372,7 +372,7 @@ async function main() {
372372
(b) =>
373373
// afterframe currently only targets CPU benchmarks
374374
(config.BENCHMARK_RUNNER !== BenchmarkRunner.WEBDRIVER_AFTERFRAME || b.type == BenchmarkType.CPU) &&
375-
runBenchmarksArgs.some((name) => b.id.toLowerCase().indexOf(name) > -1)
375+
runBenchmarksArgs.some((name) => b.id.toLowerCase().includes(name))
376376
);
377377

378378
let runFrameworks: FrameworkData[];

webdriver-ts/src/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export async function initializeFrameworks(
159159
useRowShadowRoot: !!frameworkVersionInformation.useRowShadowRoot,
160160
shadowRootName: frameworkVersionInformation.shadowRootName,
161161
buttonsInShadowRoot: !!frameworkVersionInformation.buttonsInShadowRoot,
162-
issues: (frameworkVersionInformation.issues ?? []).map((i) => Number(i)),
162+
issues: (frameworkVersionInformation.issues ?? []).map(Number),
163163
frameworkHomeURL: frameworkVersionInformation.frameworkHomeURL ?? "",
164164
});
165165
}

webdriver-ts/src/createResultJS.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from "fs";
1+
import * as fs from "node:fs";
22
import yargs from "yargs";
33
import {
44
BenchmarkInfo,
@@ -73,7 +73,7 @@ async function main() {
7373
if (fs.existsSync(file)) {
7474
let data: JsonResult = JSON.parse(
7575
fs.readFileSync(file, {
76-
encoding: "utf-8",
76+
encoding: "utf8",
7777
})
7878
);
7979

@@ -148,10 +148,10 @@ async function main() {
148148
resultJS += "export const benchmarks = " + JSON.stringify(formattedBenchmarks) + ";\n";
149149

150150
fs.writeFileSync("../webdriver-ts-results/src/results.ts", resultJS, {
151-
encoding: "utf-8",
151+
encoding: "utf8",
152152
});
153153
fs.writeFileSync("./results.json", JSON.stringify(jsonResult), {
154-
encoding: "utf-8",
154+
encoding: "utf8",
155155
});
156156
}
157157

webdriver-ts/src/forkedBenchmarkRunnerLighthouse.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ function extractRawValue(results: any, id: string) {
1111
let audits = results.audits;
1212
if (!audits) return null;
1313
let audit_with_id = audits[id];
14-
if (typeof audit_with_id === "undefined") return null;
15-
if (typeof audit_with_id.numericValue === "undefined") return null;
14+
if (audit_with_id === undefined) return null;
15+
if (audit_with_id.numericValue === undefined) return null;
1616
return audit_with_id.numericValue;
1717
}
1818

webdriver-ts/src/forkedBenchmarkRunnerWebdriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ async function computeResultsCPU(
190190
});
191191
}
192192

193-
let duration = (paintsP[paintsP.length - 1].end - clicks[0].ts) / 1000.0;
193+
let duration = (paintsP.at(-1).end - clicks[0].ts) / 1000.0;
194194
let upperBoundForSoundnessCheck = (R.last(eventsDuringBenchmark).end - eventsDuringBenchmark[0].ts) / 1000.0;
195195

196196
if (duration < 0) {

webdriver-ts/src/forkedBenchmarkRunnerWebdriverCDP.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as fs from "fs/promises";
1+
import * as fs from "node:fs/promises";
22
import { WebDriver } from "selenium-webdriver";
33
import { BenchmarkType, CPUBenchmarkResult, slowDownFactor } from "./benchmarksCommon.js";
44
import { benchmarks, CPUBenchmarkWebdriverCDP } from "./benchmarksWebdriverCDP.js";

webdriver-ts/src/stats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export function stats(values: number[]) {
55
let h = sorted.length / 2;
66
median = 0.5 * (sorted[h - 1] + sorted[h]);
77
} else {
8-
median = sorted[(sorted.length / 2) | 0];
8+
median = sorted[Math.trunc(sorted.length / 2)];
99
}
1010

1111
let mean = sorted.reduce((p, c) => p + c, 0) / sorted.length;
@@ -15,7 +15,7 @@ export function stats(values: number[]) {
1515

1616
return {
1717
min: sorted[0],
18-
max: sorted[sorted.length - 1],
18+
max: sorted.at(-1),
1919
median,
2020
mean,
2121
stddev,

webdriver-ts/src/timeline.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { readFile } from "fs/promises";
2-
import * as fs from "fs";
1+
import { readFile } from "node:fs/promises";
2+
import * as fs from "node:fs";
33
import * as R from "ramda";
44
import { BenchmarkType, CPUBenchmarkInfo, CPUBenchmarkResult } from "./benchmarksCommon.js";
55
import { BenchmarkOptions, FrameworkData, Config, config } from "./common.js";
@@ -208,7 +208,7 @@ export async function computeResultsCPU(
208208

209209
let startFrom = R.filter(type_eq("click", "fireAnimationFrame", "timerFire", "layout", "functioncall"))(eventsOnMainThreadDuringBenchmark);
210210
// we're looking for the commit after this event
211-
let startFromEvent = startFrom[startFrom.length - 1];
211+
let startFromEvent = startFrom.at(-1);
212212
if (config.LOG_DETAILS) console.log("DEBUG: searching for commit event after", startFromEvent, "for", fileName);
213213
let commit = R.find((e: TimingResult) => e.ts > startFromEvent.end)(R.filter(type_eq("commit"))(eventsOnMainThreadDuringBenchmark));
214214
let allCommitsAfterClick = R.filter(type_eq("commit"))(eventsOnMainThreadDuringBenchmark);
@@ -220,10 +220,10 @@ export async function computeResultsCPU(
220220
console.log("ERROR: No commit event found for", fileName);
221221
throw "No commit event found for " + fileName;
222222
} else {
223-
commit = allCommitsAfterClick[allCommitsAfterClick.length - 1];
223+
commit = allCommitsAfterClick.at(-1);
224224
}
225225
}
226-
let maxDeltaBetweenCommits = (allCommitsAfterClick[allCommitsAfterClick.length-1].ts - allCommitsAfterClick[0].ts)/1000.0;
226+
let maxDeltaBetweenCommits = (allCommitsAfterClick.at(-1).ts - allCommitsAfterClick[0].ts)/1000.0;
227227

228228
let duration = (commit.end - clicks[0].ts) / 1000.0;
229229
if (config.LOG_DEBUG) console.log("duration", duration);

webdriver-ts/src/webdriverAccess.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export async function testTextContains(
8787
let elem = await findByXPath(driver, xpath, isInButtonArea);
8888
if (elem == null) return false;
8989
let v = await elem.getText();
90-
return v && v.indexOf(text) > -1;
90+
return v && v.includes(text);
9191
} catch (error) {
9292
console.log(
9393
"ignoring error in testTextContains for xpath = " + xpath + " text = " + text,
@@ -113,7 +113,7 @@ export async function testTextNotContained(
113113
let elem = await findByXPath(driver, xpath, isInButtonArea);
114114
if (elem == null) return false;
115115
let v = await elem.getText();
116-
return v && v.indexOf(text) == -1;
116+
return v && !v.includes(text);
117117
} catch (error) {
118118
console.log("ignoring error in testTextNotContained for xpath = " + xpath + " text = " + text, error.toString().split("\n")[0]);
119119
}
@@ -136,7 +136,7 @@ export async function testClassContains(
136136
let elem = await findByXPath(driver, xpath, isInButtonArea);
137137
if (elem == null) return false;
138138
let v = await elem.getAttribute("class");
139-
return v && v.indexOf(text) > -1;
139+
return v && v.includes(text);
140140
} catch (error) {
141141
console.log("ignoring error in testClassContains for xpath = " + xpath + " text = " + text, error.toString().split("\n")[0]);
142142
}

0 commit comments

Comments
 (0)