Skip to content

Commit 7502df0

Browse files
authored
chore: add eslint typescript (#16)
1 parent f317950 commit 7502df0

File tree

5 files changed

+88
-54
lines changed

5 files changed

+88
-54
lines changed

.eslintrc.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"env": {
3+
"es2021": true,
4+
"node": true
5+
},
6+
"extends": [
7+
"standard"
8+
],
9+
"parser": "@typescript-eslint/parser",
10+
"parserOptions": {
11+
"ecmaVersion": "latest",
12+
"sourceType": "module"
13+
},
14+
"plugins": [
15+
"@typescript-eslint"
16+
],
17+
"rules": {
18+
},
19+
"ignorePatterns": ["dist/"]
20+
}

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ jobs:
2828
run: |
2929
npm i fastify json-schema-to-ts
3030
31+
- name: Run lint
32+
run: |
33+
npm run lint
34+
3135
- name: Run tests
3236
run: |
3337
npm run test

index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import {
44
RawServerBase,
55
RawServerDefault,
66
FastifyPluginCallback,
7-
FastifyPluginAsync,
8-
} from "fastify";
7+
FastifyPluginAsync
8+
} from 'fastify'
99

10-
import { JSONSchema7, FromSchema } from "json-schema-to-ts";
10+
import { JSONSchema7, FromSchema } from 'json-schema-to-ts'
1111

1212
export interface JsonSchemaToTsProvider extends FastifyTypeProvider {
13-
output: this["input"] extends JSONSchema7 ? FromSchema<this["input"]> : never;
13+
output: this['input'] extends JSONSchema7 ? FromSchema<this['input']> : never;
1414
}
1515

1616
/**

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"scripts": {
88
"build": "rimraf ./dist && mkdir dist && tsc --outDir dist",
99
"test": "npm run build && npm run typescript",
10+
"lint": "eslint \"**/*.ts\"",
11+
"lint:fix": "eslint \"**/*.ts\" --fix",
1012
"typescript": "tsd"
1113
},
1214
"repository": {
@@ -32,8 +34,16 @@
3234
},
3335
"devDependencies": {
3436
"@types/node": "^18.0.0",
37+
"@typescript-eslint/eslint-plugin": "^5.32.0",
38+
"@typescript-eslint/parser": "^5.32.0",
39+
"eslint": "^8.21.0",
40+
"eslint-config-standard": "^17.0.0",
41+
"eslint-plugin-import": "^2.26.0",
42+
"eslint-plugin-n": "^15.2.4",
43+
"eslint-plugin-promise": "^6.0.0",
3544
"fastify-tsconfig": "^1.0.1",
3645
"rimraf": "^3.0.2",
37-
"tsd": "^0.22.0"
46+
"tsd": "^0.22.0",
47+
"typescript": "^4.7.4"
3848
}
3949
}

types/plugin.test-d.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
FastifyPluginAsyncJsonSchemaToTs,
3-
FastifyPluginCallbackJsonSchemaToTs,
4-
} from "../index";
5-
import { expectType } from "tsd";
6-
import Fastify, { FastifyPluginAsync, FastifyPluginCallback } from "fastify";
3+
FastifyPluginCallbackJsonSchemaToTs
4+
} from '../index'
5+
import { expectType } from 'tsd'
6+
import Fastify, { FastifyPluginAsync, FastifyPluginCallback } from 'fastify'
77

8-
import { Http2Server } from "http2";
8+
import { Http2Server } from 'http2'
99

1010
// Ensure the defaults of FastifyPluginAsyncJsonSchemaToTs are the same as FastifyPluginAsync
1111
export const pluginAsyncDefaults: FastifyPluginAsync = async (
@@ -14,11 +14,11 @@ export const pluginAsyncDefaults: FastifyPluginAsync = async (
1414
) => {
1515
const pluginAsyncJSONSchemaToTsDefaults: FastifyPluginAsyncJsonSchemaToTs =
1616
async (fastifyWithJSONSchemaToTs, optionsJSONSchemaToTs) => {
17-
expectType<typeof fastifyWithJSONSchemaToTs["server"]>(fastify.server);
18-
expectType<typeof optionsJSONSchemaToTs>(options);
19-
};
20-
fastify.register(pluginAsyncJSONSchemaToTsDefaults);
21-
};
17+
expectType<typeof fastifyWithJSONSchemaToTs['server']>(fastify.server)
18+
expectType<typeof optionsJSONSchemaToTs>(options)
19+
}
20+
fastify.register(pluginAsyncJSONSchemaToTsDefaults)
21+
}
2222

2323
// Ensure the defaults of FastifyPluginCallbackJsonSchemaToTs are the same as FastifyPluginCallback
2424
export const pluginCallbackDefaults: FastifyPluginCallback = async (
@@ -32,77 +32,77 @@ export const pluginCallbackDefaults: FastifyPluginCallback = async (
3232
optionsJSONSchemaToTs,
3333
doneJSONSchemaToTs
3434
) => {
35-
expectType<typeof fastifyWithJSONSchemaToTs["server"]>(fastify.server);
36-
expectType<typeof optionsJSONSchemaToTs>(options);
37-
};
35+
expectType<typeof fastifyWithJSONSchemaToTs['server']>(fastify.server)
36+
expectType<typeof optionsJSONSchemaToTs>(options)
37+
}
3838

39-
fastify.register(pluginCallbackJSONSchemaToTsDefaults);
40-
};
39+
fastify.register(pluginCallbackJSONSchemaToTsDefaults)
40+
}
4141

4242
const asyncPlugin: FastifyPluginAsyncJsonSchemaToTs<
4343
{ optionA: string },
4444
Http2Server
4545
> = async (fastify, options) => {
46-
expectType<Http2Server>(fastify.server);
46+
expectType<Http2Server>(fastify.server)
4747

48-
expectType<string>(options.optionA);
48+
expectType<string>(options.optionA)
4949

5050
fastify.get(
51-
"/",
51+
'/',
5252
{
5353
schema: {
5454
body: {
55-
type: "object",
55+
type: 'object',
5656
properties: {
57-
x: { type: "string" },
58-
y: { type: "number" },
59-
z: { type: "boolean" },
57+
x: { type: 'string' },
58+
y: { type: 'number' },
59+
z: { type: 'boolean' }
6060
},
61-
required: ["x", "y", "z"],
62-
} as const,
63-
},
61+
required: ['x', 'y', 'z']
62+
} as const
63+
}
6464
},
6565
(req) => {
66-
expectType<boolean>(req.body.z);
67-
expectType<number>(req.body.y);
68-
expectType<string>(req.body.x);
66+
expectType<boolean>(req.body.z)
67+
expectType<number>(req.body.y)
68+
expectType<string>(req.body.x)
6969
}
70-
);
71-
};
70+
)
71+
}
7272

7373
const callbackPlugin: FastifyPluginCallbackJsonSchemaToTs<
7474
{ optionA: string },
7575
Http2Server
7676
> = (fastify, options, done) => {
77-
expectType<Http2Server>(fastify.server);
77+
expectType<Http2Server>(fastify.server)
7878

79-
expectType<string>(options.optionA);
79+
expectType<string>(options.optionA)
8080

8181
fastify.get(
82-
"/",
82+
'/',
8383
{
8484
schema: {
8585
body: {
86-
type: "object",
86+
type: 'object',
8787
properties: {
88-
x: { type: "string" },
89-
y: { type: "number" },
90-
z: { type: "boolean" },
88+
x: { type: 'string' },
89+
y: { type: 'number' },
90+
z: { type: 'boolean' }
9191
},
92-
required: ["x", "y", "z"],
93-
} as const,
94-
},
92+
required: ['x', 'y', 'z']
93+
} as const
94+
}
9595
},
9696
(req) => {
97-
expectType<boolean>(req.body.z);
98-
expectType<number>(req.body.y);
99-
expectType<string>(req.body.x);
97+
expectType<boolean>(req.body.z)
98+
expectType<number>(req.body.y)
99+
expectType<string>(req.body.x)
100100
}
101-
);
102-
done();
103-
};
101+
)
102+
done()
103+
}
104104

105-
const fastify = Fastify();
105+
const fastify = Fastify()
106106

107-
fastify.register(asyncPlugin);
108-
fastify.register(callbackPlugin);
107+
fastify.register(asyncPlugin)
108+
fastify.register(callbackPlugin)

0 commit comments

Comments
 (0)