Skip to content

Commit f16b9ca

Browse files
committed
Add eslint
Long overdue.
1 parent e811157 commit f16b9ca

24 files changed

+127
-74
lines changed

browserify.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function transform(
2323
let buffer = Buffer.alloc(0);
2424

2525
return new Transform({
26-
transform(chunk: any, encoding: string, done: TransformCallback) {
26+
transform(chunk, encoding, done) {
2727
buffer = Buffer.concat([buffer, chunk]);
2828
done();
2929
},

declarations.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
declare module "@cypress/browserify-preprocessor";
2-
3-
declare module "pngjs";

esbuild.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function createEsbuildPlugin(
1212
return {
1313
name: "feature",
1414
setup(build) {
15+
// eslint-disable-next-line @typescript-eslint/no-var-requires
1516
const fs = require("fs") as typeof import("fs");
1617

1718
build.onLoad({ filter: /\.feature$/ }, async (args) => {

features/step_definitions/cli_steps.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import util from "util";
2-
import { Given, When, Then } from "@cucumber/cucumber";
2+
import { When, Then } from "@cucumber/cucumber";
33
import assert from "assert";
44
import childProcess from "child_process";
55
import stripAnsi from "strip-ansi";
6-
import { isPost10, isPre10 } from "../support/helpers";
76

87
function execAsync(
98
command: string

features/step_definitions/file_steps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Given } from "@cucumber/cucumber";
22
import stripIndent from "strip-indent";
33
import path from "path";
4-
import { isPost10, isPre10, writeFile } from "../support/helpers";
4+
import { isPre10, writeFile } from "../support/helpers";
55

66
Given("a file named {string} with:", async function (filePath, fileContent) {
77
const absoluteFilePath = path.join(this.tmpDir, filePath);

features/step_definitions/json_steps.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ function isObject(object: any): object is object {
1111
return typeof object === "object" && object != null;
1212
}
1313

14+
// eslint-disable-next-line @typescript-eslint/ban-types
1415
function hasOwnProperty<X extends {}, Y extends PropertyKey>(
1516
obj: X,
1617
prop: Y
1718
): obj is X & Record<Y, unknown> {
18-
return obj.hasOwnProperty(prop);
19+
return Object.prototype.hasOwnProperty.call(obj, prop);
1920
}
2021

2122
function* traverseTree(object: any): Generator<object, void, any> {
@@ -133,10 +134,10 @@ Then(
133134

134135
assert.strictEqual(embedding.mime_type, "image/png");
135136

136-
const png = await new Promise<any>((resolve, reject) => {
137+
const png = await new Promise<PNG>((resolve, reject) => {
137138
new PNG().parse(
138-
toByteArray(embedding.data).buffer,
139-
function (error: any, data: any) {
139+
Buffer.from(toByteArray(embedding.data)),
140+
function (error, data) {
140141
if (error) {
141142
reject(error);
142143
} else {
@@ -146,7 +147,7 @@ Then(
146147
);
147148
});
148149

149-
let expectedDimensions;
150+
let expectedDimensions: { width: number; height: number };
150151

151152
/**
152153
* See https://github.com/cypress-io/cypress/pull/15686 and https://github.com/cypress-io/cypress/pull/17309.

features/support/configFileUpdater.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable */
2+
13
import { parse } from "@babel/parser";
24
import type { File } from "@babel/types";
35
import type { NodePath } from "ast-types/lib/node-path";

features/support/hooks.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { version as cypressVersion } from "cypress/package.json";
21
import { After, Before, formatterHelpers } from "@cucumber/cucumber";
32
import path from "path";
43
import assert from "assert";
@@ -138,15 +137,3 @@ After(function () {
138137
);
139138
}
140139
});
141-
142-
function addCucumberPreprocessorPlugin(on: any, config: any) {
143-
throw new Error("Function not implemented.");
144-
}
145-
146-
function createBundler(arg0: { plugins: any[] }): any {
147-
throw new Error("Function not implemented.");
148-
}
149-
150-
function createEsbuildPlugin(config: any) {
151-
throw new Error("Function not implemented.");
152-
}

lib/add-cucumber-preprocessor-plugin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import { createTimestamp } from "./messages-helpers";
4848
* Work-around for the fact that some Cypress versions pre v10 were missing this property in their types.
4949
*/
5050
declare global {
51+
// eslint-disable-next-line @typescript-eslint/no-namespace
5152
namespace Cypress {
5253
interface PluginConfigOptions {
5354
testFiles: string[];
@@ -214,7 +215,7 @@ export async function afterRunHandler(config: Cypress.PluginConfigOptions) {
214215
}
215216
}
216217

217-
export async function beforeSpecHandler(config: Cypress.PluginConfigOptions) {
218+
export async function beforeSpecHandler(_config: Cypress.PluginConfigOptions) {
218219
currentSpecMessages = [];
219220
}
220221

lib/assertions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function fail(message: string) {
88
);
99
}
1010

11-
export function assert(value: any, message: string): asserts value {
11+
export function assert(value: unknown, message: string): asserts value {
1212
if (value) {
1313
return;
1414
}
@@ -25,7 +25,7 @@ export function assertAndReturn<T>(
2525
}
2626

2727
export function assertIsString(
28-
value: any,
28+
value: unknown,
2929
message: string
3030
): asserts value is string {
3131
assert(isString(value), message);

lib/create-tests.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ import { indent, stripIndent } from "./helpers/strings";
5151
import { generateSnippet } from "./snippets";
5252

5353
declare global {
54+
// eslint-disable-next-line @typescript-eslint/no-namespace
5455
namespace globalThis {
56+
// eslint-disable-next-line no-var
5557
var __cypress_cucumber_preprocessor_dont_use_this: true | undefined;
5658
}
5759
}
@@ -459,13 +461,13 @@ function createPickle(
459461
return cy.wrap(start, { log: false });
460462
})
461463
.then((start) => {
462-
const ensureChain = (value: any): Cypress.Chainable<any> =>
464+
const ensureChain = (value: unknown): Cypress.Chainable<unknown> =>
463465
Cypress.isCy(value) ? value : cy.wrap(value, { log: false });
464466

465467
try {
466468
return ensureChain(
467469
registry.runStepDefininition(this, text, argument)
468-
).then((result: any) => {
470+
).then((result: unknown) => {
469471
return {
470472
start,
471473
result,
@@ -680,7 +682,7 @@ export default function createTests(
680682

681683
if (
682684
remainingSteps.length > 0 &&
683-
(this.currentTest?.state as any) !== "pending"
685+
(this.currentTest?.state as unknown) !== "pending"
684686
) {
685687
const error = assertAndReturn(
686688
this.currentTest?.err?.message,

lib/data_table.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class DataTable {
3232
}
3333
}
3434

35-
hashes(): any[] {
35+
hashes(): Record<string, string>[] {
3636
const copy = this.raw();
3737
const keys = copy[0];
3838
const valuesArray = copy.slice(1);
@@ -49,7 +49,7 @@ export default class DataTable {
4949
return copy;
5050
}
5151

52-
rowsHash() {
52+
rowsHash(): Record<string, string> {
5353
return Object.fromEntries(
5454
this.raw().map<[string, string]>((values) => {
5555
const [first, second, ...rest] = values;
@@ -65,7 +65,7 @@ export default class DataTable {
6565
);
6666
}
6767

68-
transpose() {
68+
transpose(): DataTable {
6969
const transposed = this.rawTable[0].map((x, i) =>
7070
this.rawTable.map((y) => y[i])
7171
);

lib/diagnostics/diagnose.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import "source-map-support/register";
22
import fs from "fs/promises";
3-
import os from "os";
43
import path from "path";
54
import util from "util";
65
import {
@@ -14,7 +13,6 @@ import {
1413
} from "@cucumber/cucumber-expressions";
1514
import { generateMessages } from "@cucumber/gherkin";
1615
import { IdGenerator, SourceMediaType } from "@cucumber/messages";
17-
import hook from "node-hook";
1816
import * as esbuild from "esbuild";
1917
import { assert, assertAndReturn } from "../assertions";
2018
import { createAstIdMap } from "../ast-helpers";
@@ -79,10 +77,14 @@ export function compareStepDefinition(
7977
) {
8078
return (
8179
expressionToString(a.expression) === expressionToString(b.expression) &&
82-
comparePosition(a.position!, b.position!)
80+
comparePosition(position(a), position(b))
8381
);
8482
}
8583

84+
export function position(definition: IStepDefinition<unknown[]>): Position {
85+
return assertAndReturn(definition.position, "Expected to find a position");
86+
}
87+
8688
export async function diagnose(configuration: {
8789
cypress: ICypressConfiguration;
8890
preprocessor: IPreprocessorConfiguration;
@@ -155,7 +157,7 @@ export async function diagnose(configuration: {
155157

156158
try {
157159
require(outputFileName);
158-
} catch (e: any) {
160+
} catch (e: unknown) {
159161
console.log(util.inspect(e));
160162

161163
throw new Error(
@@ -169,8 +171,8 @@ export async function diagnose(configuration: {
169171
/**
170172
* Delete without regard for errors.
171173
*/
172-
await fs.rm(inputFileName).catch(() => {});
173-
await fs.rm(outputFileName).catch(() => {});
174+
await fs.rm(inputFileName).catch(() => true);
175+
await fs.rm(outputFileName).catch(() => true);
174176
}
175177

176178
const options = {
@@ -253,7 +255,8 @@ export async function diagnose(configuration: {
253255
result.unmatchedSteps.push({
254256
step: {
255257
source: testFile,
256-
line: astNode.location?.line!,
258+
line: astNode.location.line,
259+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
257260
text: step.text!,
258261
},
259262
argument,
@@ -279,7 +282,8 @@ export async function diagnose(configuration: {
279282

280283
usage.steps.push({
281284
source: testFile,
282-
line: astNode.location?.line!,
285+
line: astNode.location?.line,
286+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
283287
text: step.text!,
284288
});
285289
} else {
@@ -296,15 +300,17 @@ export async function diagnose(configuration: {
296300

297301
usage.steps.push({
298302
source: testFile,
299-
line: astNode.location?.line!,
303+
line: astNode.location.line,
304+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
300305
text: step.text!,
301306
});
302307
}
303308

304309
result.ambiguousSteps.push({
305310
step: {
306311
source: testFile,
307-
line: astNode.location?.line!,
312+
line: astNode.location.line,
313+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
308314
text: step.text!,
309315
},
310316
definitions: matchingStepDefinitions,

lib/diagnostics/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ import {
2828
import { assertAndReturn } from "../assertions";
2929
import { generateSnippet } from "../snippets";
3030

31-
const TEMPLATE = `
32-
Given("[expression]", function ([arguments]) {
33-
return "pending";
34-
});
35-
`.trim();
36-
3731
export function log(...lines: string[]) {
3832
console.log(lines.join("\n"));
3933
}
@@ -66,10 +60,14 @@ export function compareStepDefinition(
6660
) {
6761
return (
6862
expressionToString(a.expression) === expressionToString(b.expression) &&
69-
comparePosition(a.position!, b.position!)
63+
comparePosition(position(a), position(b))
7064
);
7165
}
7266

67+
export function position(definition: IStepDefinition<unknown[]>): Position {
68+
return assertAndReturn(definition.position, "Expected to find a position");
69+
}
70+
7371
export function groupToMap<T, K>(
7472
collection: T[],
7573
getKeyFn: (el: T) => K,
@@ -82,6 +80,7 @@ export function groupToMap<T, K>(
8280

8381
for (const existingKey of map.keys()) {
8482
if (compareKeyFn(key, existingKey)) {
83+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
8584
map.get(existingKey)!.push(el);
8685
continue el;
8786
}
@@ -122,6 +121,7 @@ export function createDefinitionsUsage(
122121
const groups = mapValues(
123122
groupToMap(
124123
result.definitionsUsage,
124+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125125
(definitionsUsage) => definitionsUsage.definition.position!.source,
126126
strictCompare
127127
),
@@ -143,9 +143,9 @@ export function createDefinitionsUsage(
143143
.sort((a, b) => a[0].localeCompare(b[0]))
144144
.flatMap(([, matches]) => {
145145
return Array.from(matches.entries())
146-
.sort((a, b) => a[0].position?.line! - b[0].position?.line!)
146+
.sort((a, b) => position(a[0]).line - position(b[0]).line)
147147
.map<[string, string]>(([stepDefinition, steps]) => {
148-
const { expression, position } = stepDefinition;
148+
const { expression } = stepDefinition;
149149

150150
const right = [
151151
inspect(
@@ -159,9 +159,9 @@ export function createDefinitionsUsage(
159159
].join("\n");
160160

161161
const left = [
162-
ensureIsRelative(projectRoot, position!.source) +
162+
ensureIsRelative(projectRoot, position(stepDefinition).source) +
163163
":" +
164-
position!.line,
164+
position(stepDefinition).line,
165165
...steps.map((step) => {
166166
return (
167167
ensureIsRelative(projectRoot, step.source) + ":" + step.line
@@ -214,8 +214,8 @@ export function createAmbiguousStep(
214214
definition.expression instanceof RegularExpression
215215
? definition.expression.regexp
216216
: definition.expression.source
217-
)} (${relativeToProjectRoot(definition.position!.source)}:${
218-
definition.position!.line
217+
)} (${relativeToProjectRoot(position(definition).source)}:${
218+
position(definition).line
219219
})`
220220
)
221221
.forEach(append);

lib/environment-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function getTags(env: Record<string, any>): string | null {
1+
export function getTags(env: Record<string, unknown>): string | null {
22
const tags = env.TAGS ?? env.tags;
33

44
return tags == null ? null : String(tags);

0 commit comments

Comments
 (0)