Skip to content

Commit

Permalink
eslint ignores (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatethurston authored Jul 28, 2023
1 parent 0dc1a4b commit 9624783
Show file tree
Hide file tree
Showing 19 changed files with 50 additions and 29 deletions.
17 changes: 11 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
ignorePatterns: ["dist"],
ignorePatterns: ["dist", "examples/nextjs"],
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
},
env: {
browser: true,
node: true,
},
plugins: ["@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
],
extends: ["eslint:recommended", "prettier"],
overrides: [
{
files: ["*.ts"],
Expand All @@ -18,6 +22,7 @@ module.exports = {
project: ["./tsconfig.json"],
},
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
rules: {
Expand Down
16 changes: 8 additions & 8 deletions e2e/protos/__snapshots__/test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ Groups are not supported. Found group optionalgroup

exports[`TwirpScript Compiler generates JavaScript 2`] = `
[
"/Users/tatethurston/TwirpScript/e2e/protos/dist/javascript/twirpscript/empty.pb.js",
"/Users/tatethurston/TwirpScript/e2e/protos/dist/javascript/twirpscript/services.pb.js",
"/Users/tatethurston/TwirpScript/e2e/protos/dist/javascript/google/protobuf/map_unittest.pb.js",
"/Users/tatethurston/TwirpScript/e2e/protos/dist/javascript/google/protobuf/unittest.pb.js",
"/dist/javascript/twirpscript/empty.pb.js",
"/dist/javascript/twirpscript/services.pb.js",
"/dist/javascript/google/protobuf/map_unittest.pb.js",
"/dist/javascript/google/protobuf/unittest.pb.js",
]
`;

Expand Down Expand Up @@ -23470,10 +23470,10 @@ Groups are not supported. Found group optionalgroup

exports[`TwirpScript Compiler generates TypeScript 2`] = `
[
"/Users/tatethurston/TwirpScript/e2e/protos/dist/typescript/twirpscript/empty.pb.ts",
"/Users/tatethurston/TwirpScript/e2e/protos/dist/typescript/twirpscript/services.pb.ts",
"/Users/tatethurston/TwirpScript/e2e/protos/dist/typescript/google/protobuf/map_unittest.pb.ts",
"/Users/tatethurston/TwirpScript/e2e/protos/dist/typescript/google/protobuf/unittest.pb.ts",
"/dist/typescript/twirpscript/empty.pb.ts",
"/dist/typescript/twirpscript/services.pb.ts",
"/dist/typescript/google/protobuf/map_unittest.pb.ts",
"/dist/typescript/google/protobuf/unittest.pb.ts",
]
`;

Expand Down
23 changes: 13 additions & 10 deletions e2e/protos/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import { mkdirSync, readFileSync, readdirSync, rmdirSync } from "fs";
import { join } from "path";

describe("TwirpScript Compiler", () => {
const TYPESCRIPT_DEST = join(__dirname, "dist/typescript");
const JAVASCRIPT_DEST = join(__dirname, "dist/javascript");

beforeAll(() => {
mkdirSync(join(__dirname, "dist/typescript"), { recursive: true });
mkdirSync(join(__dirname, "dist/javascript"), { recursive: true });
mkdirSync(TYPESCRIPT_DEST, { recursive: true });
mkdirSync(JAVASCRIPT_DEST, { recursive: true });
});

afterAll(() => {
rmdirSync(join(__dirname, "dist/typescript"), { recursive: true });
rmdirSync(join(__dirname, "dist/javascript"), { recursive: true });
rmdirSync(TYPESCRIPT_DEST, { recursive: true });
rmdirSync(JAVASCRIPT_DEST, { recursive: true });
});

it("generates TypeScript", () => {
const child = spawnSync(
`protoc \
--plugin=protoc-gen-twirpscript=./node_modules/twirpscript/dist/compiler.js \
--twirpscript_out=./dist/typescript \
--twirpscript_out=${TYPESCRIPT_DEST} \
--twirpscript_opt=language=typescript \
$(find . -name '*.proto')`,
{
Expand All @@ -28,13 +31,13 @@ describe("TwirpScript Compiler", () => {
);

expect(child.output).toMatchSnapshot();
const files = readdirSync(join(__dirname, "dist/typescript"), {
const files = readdirSync(join(TYPESCRIPT_DEST), {
recursive: true,
withFileTypes: true,
})
.filter((f) => f.isFile())
.map((f) => join(f.path, f.name));
expect(files).toMatchSnapshot();
expect(files.map((f) => f.replace(__dirname, ""))).toMatchSnapshot();
files.forEach((file) =>
expect(readFileSync(file, { encoding: "utf8" })).toMatchSnapshot(),
);
Expand All @@ -44,7 +47,7 @@ describe("TwirpScript Compiler", () => {
const child = spawnSync(
`protoc \
--plugin=protoc-gen-twirpscript=./node_modules/twirpscript/dist/compiler.js \
--twirpscript_out=./dist/javascript \
--twirpscript_out=${JAVASCRIPT_DEST} \
--twirpscript_opt=language=javascript \
$(find . -name '*.proto')`,
{
Expand All @@ -55,13 +58,13 @@ describe("TwirpScript Compiler", () => {
);

expect(child.output).toMatchSnapshot();
const files = readdirSync(join(__dirname, "dist/javascript"), {
const files = readdirSync(JAVASCRIPT_DEST, {
recursive: true,
withFileTypes: true,
})
.filter((f) => f.isFile())
.map((f) => join(f.path, f.name));
expect(files).toMatchSnapshot();
expect(files.map((f) => f.replace(__dirname, ""))).toMatchSnapshot();
files.forEach((file) =>
expect(readFileSync(file, { encoding: "utf8" })).toMatchSnapshot(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function requireAuthentication({
exceptions,
}: RequireAuthenticationOpts): Middleware<Context, IncomingMessage> {
return async (req, ctx, next) => {
for (let exception of exceptions) {
for (const exception of exceptions) {
if (ctx.service?.name === exception) {
ctx.currentUser = unauthenticatedUser;
return next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe("Haberdasher", () => {
expect(haberdasher.MakeHat(size, ctx)).toEqual(
expect.objectContaining({
inches: size.inches,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
name: expect.stringMatching("tate"),
}),
);
Expand Down
3 changes: 2 additions & 1 deletion examples/aws-lambda/cdk.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { App, Stack, StackProps } from "@aws-cdk/core";
import * as lambda from "@aws-cdk/aws-lambda";
import * as apigateway from "@aws-cdk/aws-apigateway";

export class AwsLambdaStack extends Stack {
constructor(scope: any, id: string, props?: StackProps) {
constructor(scope: unknown, id: string, props?: StackProps) {
super(scope, id, props);

const handler = new lambda.Function(this, "TwirpHandler", {
Expand Down
2 changes: 1 addition & 1 deletion examples/aws-lambda/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MakeHat } from "./haberdasher.pb";
client.baseURL = "https://jr8wrw06og.execute-api.us-west-1.amazonaws.com";
client.prefix = "/prod/twirp";

(async function () {
void (async function () {
try {
const hat = await MakeHat({ inches: 12 });
console.log(hat);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
import { haberdasher } from ".";

describe("Haberdasher", () => {
Expand Down
1 change: 1 addition & 0 deletions examples/javascript-fullstack/src/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ app.use(async (req, _ctx, next) => {
});

createServer(app).listen(PORT, () =>
// eslint-disable-next-line no-undef
console.log(`Server listening on port ${PORT}`),
);
2 changes: 1 addition & 1 deletion examples/server-to-server/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ async function main() {
console.log();
}

main();
void main();
1 change: 1 addition & 0 deletions examples/server-to-server/src/server/haberdasher/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
import { haberdasher } from ".";

describe("Haberdasher", () => {
Expand Down
1 change: 1 addition & 0 deletions packages/twirpscript/src/autogenerate/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-assignment */
import { RUNTIME_MIN_CODE_GEN_SUPPORTED_VERSION } from "../runtime/index.js";
import {
printComments,
Expand Down
1 change: 1 addition & 0 deletions packages/twirpscript/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ const compiler = join(
`compiler.${isWindows ? "cmd" : "js"}`,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
void main({ compiler: { path: compiler }, logger: { name: "TwirpScript" } });
1 change: 1 addition & 0 deletions packages/twirpscript/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ import { compile as protocompile } from "protoscript/plugin";
import { plugin } from "./autogenerate/index.js";

export const compile: typeof protocompile = (input) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
protocompile(input, [plugin]);
1 change: 1 addition & 0 deletions packages/twirpscript/src/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import { compiler } from "protoscript/plugin";
import { compile } from "./compile.js";
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
await compiler(compile);
2 changes: 1 addition & 1 deletion packages/twirpscript/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const nodeHttpTransport: RpcTransport = (url, options) => {
});
};
res.on("error", reject);
res.on("data", (chunk) => chunks.push(chunk));
res.on("data", (chunk: Buffer) => chunks.push(chunk));
res.on("end", onResolve);
},
).on("error", reject);
Expand Down
1 change: 1 addition & 0 deletions packages/twirpscript/src/runtime/client/test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-assignment */
import {
client,
JSONrequest,
Expand Down
1 change: 1 addition & 0 deletions packages/twirpscript/src/runtime/error/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */
import type { RpcTransportResponse } from "../client/index.js";

export interface TwirpError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { withRequestLogging, timingField } from "./index.js";
import { createEventEmitter } from "../../eventEmitter/index.js";
import { ServerHooks } from "../index.js";
Expand Down Expand Up @@ -41,6 +42,7 @@ describe("withRequestLogging", () => {
});

it("responseSent", () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
ee.emit("responseSent", { [timingField]: Date.now() - 10 }, {
statusCode: 200,
} as any);
Expand Down

0 comments on commit 9624783

Please sign in to comment.