Skip to content

Commit 0445f2c

Browse files
Merge branch 'chore/bin/lint' into feat/bin/revamp
2 parents b747e4b + b7e4116 commit 0445f2c

File tree

9 files changed

+76
-67
lines changed

9 files changed

+76
-67
lines changed

src/GraphQLIntrospection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export async function introspectServer(
3232
headers[matches[1]] = matches[2];
3333
}
3434

35+
// biome-ignore lint/suspicious/noImplicitAnyLet: <explanation>
3536
let result;
3637
try {
3738
const response = await fetch(url, {

src/index.ts

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
23
import * as fs from "node:fs";
34
import * as path from "node:path";
45

@@ -67,7 +68,6 @@ import type {
6768
} from "./TypeSource";
6869
import { urlsFromURLGrammar } from "./URLGrammar";
6970

70-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
7171
const packageJSON = require("../package.json");
7272

7373
const wordWrap: (s: string) => string = _wordwrap(90);
@@ -389,13 +389,14 @@ function makeLangTypeLabel(targetLanguages: readonly TargetLanguage[]): string {
389389
.join("|");
390390
}
391391

392-
function negatedInferenceFlagName(name: string): string {
392+
function negatedInferenceFlagName(inputName: string): string {
393+
let name = inputName;
393394
const prefix = "infer";
394395
if (name.startsWith(prefix)) {
395396
name = name.slice(prefix.length);
396397
}
397398

398-
return "no" + capitalize(name);
399+
return `no${capitalize(name)}`;
399400
}
400401

401402
function dashedFromCamelCase(name: string): string {
@@ -469,6 +470,7 @@ function makeOptionDefinitions(
469470
return {
470471
name: dashedFromCamelCase(negatedInferenceFlagName(name)),
471472
optionType: "boolean" as const,
473+
// biome-ignore lint/style/useTemplate: <explanation>
472474
description: flag.negationDescription + ".",
473475
kind: "cli" as const,
474476
};
@@ -674,16 +676,15 @@ const sectionsAfterRenderers: UsageSection[] = [
674676

675677
export function parseCLIOptions(
676678
argv: string[],
677-
targetLanguage?: TargetLanguage,
679+
inputTargetLanguage?: TargetLanguage,
678680
): CLIOptions {
679681
if (argv.length === 0) {
680-
return inferCLIOptions({ help: true }, targetLanguage);
682+
return inferCLIOptions({ help: true }, inputTargetLanguage);
681683
}
682684

683-
const targetLanguages =
684-
targetLanguage === undefined
685-
? defaultTargetLanguages
686-
: [targetLanguage];
685+
const targetLanguages = inputTargetLanguage
686+
? [inputTargetLanguage]
687+
: defaultTargetLanguages;
687688
const optionDefinitions = makeOptionDefinitions(targetLanguages);
688689

689690
// We can only fully parse the options once we know which renderer is selected,
@@ -692,9 +693,11 @@ export function parseCLIOptions(
692693
// twice. This is the first parse to get the renderer:
693694
const incompleteOptions = inferCLIOptions(
694695
parseOptions(optionDefinitions, argv, true),
695-
targetLanguage,
696+
inputTargetLanguage,
696697
);
697-
if (targetLanguage === undefined) {
698+
699+
let targetLanguage = inputTargetLanguage as TargetLanguage;
700+
if (inputTargetLanguage === undefined) {
698701
const languageName = isLanguageName(incompleteOptions.lang)
699702
? incompleteOptions.lang
700703
: "typescript";
@@ -828,7 +831,11 @@ async function typeSourcesForURIs(
828831
case "schema":
829832
return uris.map(
830833
(uri) =>
831-
({ kind: "schema", name, uris: [uri] }) as SchemaTypeSource,
834+
({
835+
kind: "schema",
836+
name,
837+
uris: [uri],
838+
}) as SchemaTypeSource,
832839
);
833840
default:
834841
return panic(
@@ -879,15 +886,18 @@ function makeTypeScriptSource(fileNames: string[]): SchemaTypeSource {
879886
}
880887

881888
export function jsonInputForTargetLanguage(
882-
targetLanguage: string | TargetLanguage,
889+
_targetLanguage: string | TargetLanguage,
883890
languages?: TargetLanguage[],
884891
handleJSONRefs = false,
885892
): JSONInput<Readable> {
886-
if (typeof targetLanguage === "string") {
887-
const languageName = isLanguageName(targetLanguage)
888-
? targetLanguage
893+
let targetLanguage: TargetLanguage;
894+
if (typeof _targetLanguage === "string") {
895+
const languageName = isLanguageName(_targetLanguage)
896+
? _targetLanguage
889897
: "typescript";
890898
targetLanguage = defined(languageNamed(languageName, languages));
899+
} else {
900+
targetLanguage = _targetLanguage;
891901
}
892902

893903
const compressedJSON = new CompressedJSONFromStream(
@@ -983,7 +993,7 @@ export async function makeQuicktypeOptions(
983993
let leadingComments: string[] | undefined = undefined;
984994
let fixedTopLevels = false;
985995
switch (options.srcLang) {
986-
case "graphql":
996+
case "graphql": {
987997
let schemaString: string | undefined = undefined;
988998
let wroteSchemaToFile = false;
989999
if (options.graphqlIntrospect !== undefined) {
@@ -1040,6 +1050,7 @@ export async function makeQuicktypeOptions(
10401050

10411051
sources = gqlSources;
10421052
break;
1053+
}
10431054
case "json":
10441055
case "schema":
10451056
sources = await getSources(options);

test/buildkite.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ function getChangedFiles(base: string, commit: string): string[] {
1111
return diff.trim().split("\n");
1212
}
1313

14-
export function affectedFixtures(
15-
changedFiles: string[] | undefined = undefined,
16-
): Fixture[] {
17-
if (changedFiles === undefined) {
14+
export function affectedFixtures(_changedFiles?: string[]): Fixture[] {
15+
if (_changedFiles === undefined) {
1816
const { GITHUB_BASE_REF: base, GITHUB_SHA: commit } = process.env;
1917
return commit === undefined
2018
? allFixtures
2119
: affectedFixtures(getChangedFiles(base || "master", commit));
2220
}
2321

2422
// We can ignore changes in Markdown files
25-
changedFiles = _.reject(changedFiles, (file) => _.endsWith(file, ".md"));
23+
const changedFiles = _.reject(_changedFiles, (file) =>
24+
_.endsWith(file, ".md"),
25+
);
2626

2727
// All fixtures are dirty if any changed file is not included as a sourceFile of some fixture.
2828
const fileDependencies = _.flatMap(

test/fixtures.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function runEnvForLanguage(
103103
const newEnv = Object.assign({}, process.env);
104104

105105
for (const option of Object.keys(additionalRendererOptions)) {
106-
newEnv["QUICKTYPE_" + option.toUpperCase().replace("-", "_")] = (
106+
newEnv[`QUICKTYPE_${option.toUpperCase().replace("-", "_")}`] = (
107107
additionalRendererOptions[
108108
option as keyof typeof additionalRendererOptions
109109
] as Option<string, unknown>
@@ -216,10 +216,6 @@ export abstract class Fixture {
216216
}
217217

218218
abstract class LanguageFixture extends Fixture {
219-
constructor(language: languages.Language) {
220-
super(language);
221-
}
222-
223219
async setup() {
224220
const setupCommand = this.language.setupCommand;
225221
if (!setupCommand || ONLY_OUTPUT) {

test/languages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { LanguageName } from "quicktype-core";
22

3-
import * as process from "process";
3+
import * as process from "node:process";
44
// @ts-ignore
55
import type { RendererOptions } from "../dist/quicktype-core/Run";
66

@@ -672,7 +672,7 @@ export const ElmLanguage: Language = {
672672
export const SwiftLanguage: Language = {
673673
name: "swift",
674674
base: "test/fixtures/swift",
675-
compileCommand: `swiftc -o quicktype main.swift quicktype.swift`,
675+
compileCommand: "swiftc -o quicktype main.swift quicktype.swift",
676676
runCommand(sample: string) {
677677
return `./quicktype "${sample}"`;
678678
},
@@ -760,7 +760,7 @@ export const SwiftLanguage: Language = {
760760
export const ObjectiveCLanguage: Language = {
761761
name: "objective-c",
762762
base: "test/fixtures/objective-c",
763-
compileCommand: `clang -Werror -framework Foundation *.m -o test`,
763+
compileCommand: "clang -Werror -framework Foundation *.m -o test",
764764
runCommand(sample: string) {
765765
return `cp "${sample}" sample.json && ./test sample.json`;
766766
},

test/lib/deepEquals.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Moment } from "moment";
33
import type { ComparisonRelaxations } from "../utils";
44

55
function pathToString(path: string[]): string {
6+
// biome-ignore lint/style/useTemplate: <explanation>
67
return "." + path.join(".");
78
}
89

@@ -13,9 +14,13 @@ declare namespace Math {
1314

1415
function tryParseMoment(s: string): [Moment | undefined, boolean] {
1516
let m = moment(s);
16-
if (m.isValid()) return [m, false];
17+
if (m.isValid()) {
18+
return [m, false];
19+
}
1720
m = moment(s, "HH:mm:ss.SSZ");
18-
if (m.isValid()) return [m, true];
21+
if (m.isValid()) {
22+
return [m, true];
23+
}
1924
return [undefined, false];
2025
}
2126

test/lib/multicore.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import cluster from "cluster";
2-
import process from "process";
3-
import * as _ from "lodash";
1+
import cluster from "node:cluster";
2+
import process from "node:process";
43

54
const exit = require("exit");
65

@@ -18,8 +17,8 @@ function randomPick<T>(arr: T[]): T {
1817
}
1918

2019
function guys(n: number): string {
21-
return _.range(n)
22-
.map((_i) => randomPick(WORKERS))
20+
return Array.from({ length: n })
21+
.map(() => randomPick(WORKERS))
2322
.join(" ");
2423
}
2524

@@ -63,13 +62,13 @@ export async function inParallel<Item, Result, Acc>(
6362
await map(item, i);
6463
}
6564
} else {
66-
_.range(workers).forEach((i) =>
65+
for (let i = 0; i < workers; i++) {
6766
cluster.fork({
6867
worker: i,
6968
// https://github.com/TypeStrong/ts-node/issues/367
7069
TS_NODE_PROJECT: "test/tsconfig.json",
71-
}),
72-
);
70+
});
71+
}
7372
}
7473
} else {
7574
// Setup a worker

test/test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import * as os from "os";
2-
import * as _ from "lodash";
1+
import * as os from "node:os";
32

43
import { inParallel } from "./lib/multicore";
54
import { execAsync, type Sample } from "./utils";
6-
import { type Fixture, allFixtures } from "./fixtures";
5+
import { allFixtures } from "./fixtures";
76
import { affectedFixtures, divideParallelJobs } from "./buildkite";
87

98
const exit = require("exit");
@@ -20,8 +19,8 @@ async function main(sources: string[]) {
2019
const fixturesFromCmdline = process.env.FIXTURE;
2120
if (fixturesFromCmdline) {
2221
const fixtureNames = fixturesFromCmdline.split(",");
23-
fixtures = _.filter(fixtures, (fixture) =>
24-
_.some(fixtureNames, (name) => fixture.runForName(name)),
22+
fixtures = fixtures.filter((fixture) =>
23+
fixtureNames.some(fixture.runForName),
2524
);
2625
}
2726

@@ -34,24 +33,24 @@ async function main(sources: string[]) {
3433
// Get an array of all { sample, fixtureName } objects we'll run.
3534
// We can't just put the fixture in there because these WorkItems
3635
// will be sent in a message, removing all code.
37-
const samples = _.map(fixtures, (fixture) => ({
36+
const samples = fixtures.map((fixture) => ({
3837
fixtureName: fixture.name,
3938
samples: fixture.getSamples(sources),
4039
}));
41-
const priority = _.flatMap(samples, (x) =>
42-
_.map(x.samples.priority, (s) => ({
43-
fixtureName: x.fixtureName,
44-
sample: s,
40+
const priority = samples.flatMap((sample) =>
41+
sample.samples.priority.map((prioritySample) => ({
42+
fixtureName: sample.fixtureName,
43+
sample: prioritySample,
4544
})),
4645
);
47-
const others = _.flatMap(samples, (x) =>
48-
_.map(x.samples.others, (s) => ({
49-
fixtureName: x.fixtureName,
50-
sample: s,
46+
const others = samples.flatMap((sample) =>
47+
sample.samples.others.map((otherSample) => ({
48+
fixtureName: sample.fixtureName,
49+
sample: otherSample,
5150
})),
5251
);
5352

54-
const tests = divideParallelJobs(_.concat(priority, others));
53+
const tests = divideParallelJobs(priority.concat(others));
5554

5655
await inParallel({
5756
queue: tests,
@@ -63,17 +62,18 @@ async function main(sources: string[]) {
6362
);
6463

6564
for (const fixture of fixtures) {
66-
await execAsync(`rm -rf test/runs`);
67-
await execAsync(`mkdir -p test/runs`);
65+
await execAsync("rm -rf test/runs");
66+
await execAsync("mkdir -p test/runs");
6867

6968
await fixture.setup();
7069
}
7170
},
7271

7372
map: async ({ sample, fixtureName }: WorkItem, index) => {
74-
const fixture = _.find(fixtures, { name: fixtureName }) as Fixture;
73+
const fixture = fixtures.find(({ name }) => name === fixtureName);
74+
7575
try {
76-
await fixture.runWithSample(sample, index, tests.length);
76+
await fixture?.runWithSample(sample, index, tests.length);
7777
} catch (e) {
7878
console.trace(e);
7979
exit(1);

test/utils.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,16 @@ export function callAndExpectFailure<T>(message: string, f: () => T): void {
5252
}
5353

5454
export function exec(
55-
s: string,
56-
env: NodeJS.ProcessEnv | undefined,
55+
str: string,
56+
env: NodeJS.ProcessEnv = process.env,
5757
printFailure = true,
5858
): { stdout: string; code: number } {
59-
debug(s);
60-
if (env === undefined) {
61-
env = process.env;
62-
}
63-
const result = shell.exec(s, { silent: !DEBUG, env });
59+
debug(str);
60+
const result = shell.exec(str, { silent: !DEBUG, env });
6461

6562
if (result.code !== 0) {
6663
const failureObj = {
67-
command: s,
64+
command: str,
6865
code: result.code,
6966
};
7067
if (!printFailure) {

0 commit comments

Comments
 (0)