eslint-plugin-hyper-fetch 7.5.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +12 -0
- package/__tests__/features/client-generic-types.spec.ts +73 -0
- package/__tests__/features/request-generic-types.spec.ts +95 -0
- package/__tests__/features/utils/generic.utilities.spec.ts +165 -0
- package/__tests__/tsconfig.json +21 -0
- package/__tests__/vitest.setup.ts +4 -0
- package/dist/client-generic-types/client-generic-types.d.ts +12 -0
- package/dist/client-generic-types/client-generic-types.d.ts.map +1 -0
- package/dist/client-generic-types/index.d.ts +2 -0
- package/dist/client-generic-types/index.d.ts.map +1 -0
- package/dist/index.d.ts +8 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110749 -14945
- package/dist/index.js.map +1 -7
- package/dist/request-generic-types/index.d.ts +2 -0
- package/dist/request-generic-types/index.d.ts.map +1 -0
- package/dist/request-generic-types/request-generic-types.d.ts +10 -0
- package/dist/request-generic-types/request-generic-types.d.ts.map +1 -0
- package/dist/utils/generic-utilities.types.d.ts +12 -0
- package/dist/utils/generic-utilities.types.d.ts.map +1 -0
- package/dist/utils/is-hf-declaration.types.d.ts +9 -0
- package/dist/utils/is-hf-declaration.types.d.ts.map +1 -0
- package/package.json +6 -10
- package/project.json +4 -0
- package/src/utils/generic-utilities.types.ts +1 -1
- package/src/utils/is-hf-declaration.types.ts +1 -1
- package/tsconfig.json +1 -1
- package/vite.config.ts +39 -0
- package/.eslintrc.json +0 -11
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ["plugin:@nx/react", "../../.eslintrc.js"],
|
|
3
|
+
parserOptions: {
|
|
4
|
+
tsconfigRootDir: __dirname,
|
|
5
|
+
project: ["./tsconfig.json", "./__tests__/tsconfig.json"],
|
|
6
|
+
},
|
|
7
|
+
rules: {
|
|
8
|
+
"react/jsx-props-no-spreading": 0,
|
|
9
|
+
"react/require-default-props": 0,
|
|
10
|
+
},
|
|
11
|
+
ignorePatterns: ["dist/", "coverage/", "vite.config.ts", "/*.js"],
|
|
12
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
2
|
+
|
|
3
|
+
import { clientGenericTypes } from "client-generic-types";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
parserOptions: { ecmaVersion: 2015 },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
ruleTester.run("client-generics-types", clientGenericTypes, {
|
|
13
|
+
valid: [
|
|
14
|
+
{
|
|
15
|
+
code: `
|
|
16
|
+
import { createClient } from "@hyper-fetch/core";
|
|
17
|
+
const someClient = createClient<{error: any}>();
|
|
18
|
+
`,
|
|
19
|
+
options: [],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
code: `
|
|
23
|
+
import { createClient } from "other-lib";
|
|
24
|
+
const someClient = createClient<{foo: any, bar: any, baz: any}>();
|
|
25
|
+
`,
|
|
26
|
+
options: [],
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
code: `
|
|
30
|
+
import { createClient } from "other-lib";
|
|
31
|
+
const someClient = createClient<number>();
|
|
32
|
+
`,
|
|
33
|
+
options: [],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
code: `
|
|
37
|
+
const someClient = createClient<boolean>();
|
|
38
|
+
`,
|
|
39
|
+
options: [],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
invalid: [
|
|
43
|
+
{
|
|
44
|
+
// typo check
|
|
45
|
+
code: `
|
|
46
|
+
import { createClient } from "@hyper-fetch/core";
|
|
47
|
+
const someClient = createClient<{adapt: any}>();`,
|
|
48
|
+
options: [],
|
|
49
|
+
errors: [{ messageId: "unexpectedGenerics", data: { items: "adapt" } }],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
// extending check
|
|
53
|
+
code: `
|
|
54
|
+
import { createClient } from "@hyper-fetch/core";
|
|
55
|
+
const someClient = createClient<{nonExisting: any}>();`,
|
|
56
|
+
errors: [{ messageId: "unexpectedGenerics", data: { items: "nonExisting" } }],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
// empty check
|
|
60
|
+
code: `
|
|
61
|
+
import { createClient } from "@hyper-fetch/core";
|
|
62
|
+
const someClient = createClient<{}>();`,
|
|
63
|
+
errors: [{ messageId: "emptyGeneric" }],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
// not matching check
|
|
67
|
+
code: `
|
|
68
|
+
import { createClient } from "@hyper-fetch/core";
|
|
69
|
+
const someClient = createClient<string>();`,
|
|
70
|
+
errors: [{ messageId: "notMatchingGenerics" }],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { RuleTester } from "@typescript-eslint/rule-tester";
|
|
2
|
+
|
|
3
|
+
import { requestGenericTypes } from "request-generic-types";
|
|
4
|
+
|
|
5
|
+
const ruleTester = new RuleTester({
|
|
6
|
+
parser: "@typescript-eslint/parser",
|
|
7
|
+
parserOptions: { ecmaVersion: 2015 },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
ruleTester.run("request-generics-types", requestGenericTypes, {
|
|
13
|
+
valid: [
|
|
14
|
+
{
|
|
15
|
+
code: "const someRequest = myClient.createRequest<{response: any}>();",
|
|
16
|
+
options: [],
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
code: "const someRequest = myClient.createRequest<{payload: any}>();",
|
|
20
|
+
options: [],
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
code: "const someRequest = myClient.createRequest<{queryParams: any}>();",
|
|
24
|
+
options: [],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
code: "const someRequest = myClient.createRequest<{error: any}>();",
|
|
28
|
+
options: [],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
code: "const someRequest = myClient.createRequest<{payload: any,response: any}>();",
|
|
32
|
+
options: [],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
code: "const someRequest = myClient.createRequest<{response: any, queryParams: any}>();",
|
|
36
|
+
options: [],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: "const someRequest = myClient.createRequest<{error: any, response: any}>();",
|
|
40
|
+
options: [],
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
code: "const someRequest = myClient.createRequest<{payload: any, response: any, queryParams: any, error: any}>();",
|
|
44
|
+
options: [],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
code: `
|
|
48
|
+
type RequestType = {queryParams?: {search?: string; page?: number} | undefined}
|
|
49
|
+
const someRequest = myClient.createRequest<RequestType>();
|
|
50
|
+
`,
|
|
51
|
+
options: [],
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
code: `
|
|
55
|
+
type RequestType = {
|
|
56
|
+
response: { id: string };
|
|
57
|
+
payload: { name: string };
|
|
58
|
+
queryParams: { page: number };
|
|
59
|
+
error: { message: string };
|
|
60
|
+
endpoint: "/users/:id";
|
|
61
|
+
}
|
|
62
|
+
const someRequest = myClient.createRequest<RequestType>();
|
|
63
|
+
`,
|
|
64
|
+
options: [],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
invalid: [
|
|
68
|
+
{
|
|
69
|
+
// typo check
|
|
70
|
+
code: "const someRequest = myClient.createRequest<{respse: any}>();",
|
|
71
|
+
options: [],
|
|
72
|
+
errors: [{ messageId: "unexpectedGenerics", data: { items: "respse" } }],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
// extending check
|
|
76
|
+
code: "const someRequest = myClient.createRequest<{nonExisting: any}>();",
|
|
77
|
+
errors: [{ messageId: "unexpectedGenerics", data: { items: "nonExisting" } }],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
// mixed check
|
|
81
|
+
code: "const someRequest = myClient.createRequest<{response: any, nonExisting: any, queryParams: any}>();",
|
|
82
|
+
errors: [{ messageId: "unexpectedGenerics", data: { items: "nonExisting" } }],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
// empty check
|
|
86
|
+
code: "const someRequest = myClient.createRequest<{}>();",
|
|
87
|
+
errors: [{ messageId: "emptyGeneric" }],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
// not matching check
|
|
91
|
+
code: "const someRequest = myClient.createRequest<string>();",
|
|
92
|
+
errors: [{ messageId: "notMatchingGenerics" }],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
});
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getUnexpectedGenerics,
|
|
3
|
+
getEmptyGenerics,
|
|
4
|
+
getNotMatchingGeneric,
|
|
5
|
+
} from "../../../src/utils/generic-utilities.types";
|
|
6
|
+
|
|
7
|
+
describe("Generic Utilities", () => {
|
|
8
|
+
describe("getUnexpectedGenerics", () => {
|
|
9
|
+
it("should return empty array when no type parameters are provided", () => {
|
|
10
|
+
const result = getUnexpectedGenerics({
|
|
11
|
+
typeParameters: undefined,
|
|
12
|
+
allowedGenerics: ["endpoint", "headers"],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(result).toEqual([]);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should return unexpected generic members", () => {
|
|
19
|
+
const typeParameters: any = {
|
|
20
|
+
type: "TSTypeParameterInstantiation",
|
|
21
|
+
params: [
|
|
22
|
+
{
|
|
23
|
+
type: "TSTypeLiteral",
|
|
24
|
+
members: [
|
|
25
|
+
{
|
|
26
|
+
type: "TSPropertySignature",
|
|
27
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: "TSPropertySignature",
|
|
31
|
+
key: { type: "Identifier", name: "unexpectedProp" },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const result = getUnexpectedGenerics({
|
|
39
|
+
typeParameters,
|
|
40
|
+
allowedGenerics: ["endpoint", "headers"],
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(result).toEqual(["unexpectedProp"]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should handle non-object generic type", () => {
|
|
47
|
+
const typeParameters: any = {
|
|
48
|
+
type: "TSTypeParameterInstantiation",
|
|
49
|
+
params: [
|
|
50
|
+
{
|
|
51
|
+
type: "TSStringKeyword",
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const result = getUnexpectedGenerics({
|
|
57
|
+
typeParameters,
|
|
58
|
+
allowedGenerics: ["endpoint", "headers"],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
expect(result).toEqual(["TSStringKeyword"]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("getEmptyGenerics", () => {
|
|
66
|
+
it("should return false when no type parameters are provided", () => {
|
|
67
|
+
const result = getEmptyGenerics({
|
|
68
|
+
typeParameters: undefined,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should return true for empty generic object", () => {
|
|
75
|
+
const typeParameters: any = {
|
|
76
|
+
type: "TSTypeParameterInstantiation",
|
|
77
|
+
params: [
|
|
78
|
+
{
|
|
79
|
+
type: "TSTypeLiteral",
|
|
80
|
+
members: [],
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const result = getEmptyGenerics({
|
|
86
|
+
typeParameters,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(result).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should return false for non-empty generic object", () => {
|
|
93
|
+
const typeParameters: any = {
|
|
94
|
+
type: "TSTypeParameterInstantiation",
|
|
95
|
+
params: [
|
|
96
|
+
{
|
|
97
|
+
type: "TSTypeLiteral",
|
|
98
|
+
members: [
|
|
99
|
+
{
|
|
100
|
+
type: "TSPropertySignature",
|
|
101
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
105
|
+
],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const result = getEmptyGenerics({
|
|
109
|
+
typeParameters,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(result).toBe(false);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("getNotMatchingGeneric", () => {
|
|
117
|
+
it("should return false when no type parameters are provided", () => {
|
|
118
|
+
const result = getNotMatchingGeneric({
|
|
119
|
+
typeParameters: undefined,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(result).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("should return false for object generic type", () => {
|
|
126
|
+
const typeParameters: any = {
|
|
127
|
+
type: "TSTypeParameterInstantiation",
|
|
128
|
+
params: [
|
|
129
|
+
{
|
|
130
|
+
type: "TSTypeLiteral",
|
|
131
|
+
members: [
|
|
132
|
+
{
|
|
133
|
+
type: "TSPropertySignature",
|
|
134
|
+
key: { type: "Identifier", name: "endpoint" },
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const result = getNotMatchingGeneric({
|
|
142
|
+
typeParameters,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
expect(result).toBe(false);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("should return true for non-object generic type", () => {
|
|
149
|
+
const typeParameters: any = {
|
|
150
|
+
type: "TSTypeParameterInstantiation",
|
|
151
|
+
params: [
|
|
152
|
+
{
|
|
153
|
+
type: "TSStringKeyword",
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const result = getNotMatchingGeneric({
|
|
159
|
+
typeParameters,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
expect(result).toBe(true);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["dom", "dom.iterable", "ESNext"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"isolatedModules": true,
|
|
14
|
+
"noUnusedLocals": false,
|
|
15
|
+
"noUnusedParameters": false,
|
|
16
|
+
"types": ["vitest/globals", "@types/node"],
|
|
17
|
+
"baseUrl": "../src",
|
|
18
|
+
"paths": {}
|
|
19
|
+
},
|
|
20
|
+
"include": ["**/*.ts", "**/*.tsx", "../../../global.d.ts", "../../../vitest.d.ts"]
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export declare const createRule: <TOptions extends readonly unknown[], TMessageIds extends string, TRuleListener extends import('@typescript-eslint/utils/dist/ts-eslint').RuleListener = import('@typescript-eslint/utils/dist/ts-eslint').RuleListener>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds, TRuleListener>>) => import('@typescript-eslint/utils/dist/ts-eslint').RuleModule<TMessageIds, TOptions, TRuleListener>;
|
|
3
|
+
/**
|
|
4
|
+
* Rule for extending typescript possibilities for generic types with HyperFetch
|
|
5
|
+
* @test https://astexplorer.net/
|
|
6
|
+
*/
|
|
7
|
+
export declare const clientGenericTypes: import('@typescript-eslint/utils/dist/ts-eslint').RuleModule<"emptyGeneric" | "unexpectedGenerics" | "notMatchingGenerics", [], {
|
|
8
|
+
CallExpression(node: import('@typescript-eslint/types/dist/generated/ast-spec').CallExpression): void;
|
|
9
|
+
ImportDeclaration: (node: import('@typescript-eslint/types/dist/generated/ast-spec').ImportDeclaration) => void;
|
|
10
|
+
"Program:exit": () => void;
|
|
11
|
+
}>;
|
|
12
|
+
//# sourceMappingURL=client-generic-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-generic-types.d.ts","sourceRoot":"","sources":["../../src/client-generic-types/client-generic-types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAOvD,eAAO,MAAM,UAAU,0aAA4E,CAAC;AAEpG;;;GAGG;AACH,eAAO,MAAM,kBAAkB;;;;EAkE7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client-generic-types/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import * as _typescript_eslint_types_dist_generated_ast_spec from '@typescript-eslint/types/dist/generated/ast-spec';
|
|
3
|
-
|
|
4
|
-
declare const configs: {
|
|
1
|
+
export declare const configs: {
|
|
5
2
|
recommended: {
|
|
6
3
|
plugins: string[];
|
|
7
4
|
rules: {
|
|
@@ -10,15 +7,14 @@ declare const configs: {
|
|
|
10
7
|
};
|
|
11
8
|
};
|
|
12
9
|
};
|
|
13
|
-
declare const rules: {
|
|
14
|
-
"request-generic-types":
|
|
15
|
-
CallExpression(node:
|
|
10
|
+
export declare const rules: {
|
|
11
|
+
"request-generic-types": import('@typescript-eslint/utils/dist/ts-eslint').RuleModule<"emptyGeneric" | "unexpectedGenerics" | "notMatchingGenerics", [], {
|
|
12
|
+
CallExpression(node: import('@typescript-eslint/types/dist/generated/ast-spec').CallExpression): void;
|
|
16
13
|
}>;
|
|
17
|
-
"client-generic-types":
|
|
18
|
-
CallExpression(node:
|
|
19
|
-
ImportDeclaration: (node:
|
|
14
|
+
"client-generic-types": import('@typescript-eslint/utils/dist/ts-eslint').RuleModule<"emptyGeneric" | "unexpectedGenerics" | "notMatchingGenerics", [], {
|
|
15
|
+
CallExpression(node: import('@typescript-eslint/types/dist/generated/ast-spec').CallExpression): void;
|
|
16
|
+
ImportDeclaration: (node: import('@typescript-eslint/types/dist/generated/ast-spec').ImportDeclaration) => void;
|
|
20
17
|
"Program:exit": () => void;
|
|
21
18
|
}>;
|
|
22
19
|
};
|
|
23
|
-
|
|
24
|
-
export { configs, rules };
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO;;;;;;;;CAQnB,CAAC;AAEF,eAAO,MAAM,KAAK;;;;;;;;;CAGjB,CAAC"}
|