Skip to content

Commit b2c97fb

Browse files
authored
Ran prettier and eslint over codebase (#386)
1 parent 94e8f43 commit b2c97fb

37 files changed

+431
-572
lines changed

.eslintrc.cjs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
const { buildEslintConfig } = require("@snowcoders/renovate-config");
22

3+
const config = buildEslintConfig({
4+
esm: true,
5+
prettier: true,
6+
typescript: true,
7+
});
8+
39
module.exports = {
4-
...buildEslintConfig({
5-
esm: true,
6-
prettier: true,
7-
typescript: true,
8-
}),
10+
...config,
11+
rules: {
12+
...config.rules,
13+
"@typescript-eslint/ban-ts-comment": "warn",
14+
"@typescript-eslint/no-explicit-any": "warn",
15+
"@typescript-eslint/no-unused-vars": "warn",
16+
},
917
};

src/context-store--basic/index.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import { useCallback, useState } from "react";
2-
import { getNotImplementedPromise } from "../shared";
3-
import { ContextStore, ContextStoreData } from "./interfaces";
4-
import { getReplaceContextData } from "./modifiers";
2+
import { getNotImplementedPromise } from "../shared/index.js";
3+
import { ContextStore, ContextStoreData } from "./interfaces.js";
4+
import { getReplaceContextData } from "./modifiers/index.js";
55

66
export { ContextStore, getNotImplementedPromise };
77

8-
export function useContextStore<TContextStore extends ContextStore<any>>(
9-
defaultValue: TContextStore
10-
) {
8+
export function useContextStore<TContextStore extends ContextStore<any>>(defaultValue: TContextStore) {
119
const [contextData, setContextData] = useState(defaultValue);
1210

1311
const useUpdateFactory = <Params = void>(
@@ -16,20 +14,15 @@ export function useContextStore<TContextStore extends ContextStore<any>>(
1614
error?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
1715
preload?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
1816
},
19-
deps: React.DependencyList = []
17+
deps: React.DependencyList = [],
2018
) => {
2119
return useCallback(
2220
async (params: Params) => {
23-
return await getReplaceContextData(
24-
contextData,
25-
setContextData,
26-
params,
27-
dataHandlers
28-
);
21+
return await getReplaceContextData(contextData, setContextData, params, dataHandlers);
2922
},
30-
[contextData, setContextData, ...deps]
23+
[contextData, setContextData, ...deps],
3124
);
3225
};
3326

34-
return [contextData, { useUpdateFactory, setContextData }] as const;
27+
return [contextData, { setContextData, useUpdateFactory }] as const;
3528
}
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { Stateful } from "../shared";
1+
import { Stateful } from "../shared/index.js";
22

33
export interface ContextStore<TData> extends Stateful {
44
data: TData;
55
}
66

7-
export type ContextStoreData<
8-
TContextStore extends ContextStore<any>
9-
> = TContextStore["data"];
7+
export type ContextStoreData<TContextStore extends ContextStore<any>> = TContextStore["data"];

src/context-store--basic/modifiers/index.test.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, jest } from "@jest/globals";
2-
import { errorMessages } from "../../shared";
2+
import { errorMessages } from "../../shared/index.js";
33
import { getReplaceContextData } from "./index";
44

55
describe("getReplaceContextData", () => {
@@ -16,8 +16,8 @@ describe("getReplaceContextData", () => {
1616
},
1717
spy,
1818
undefined,
19-
{}
20-
)
19+
{},
20+
),
2121
).resolves.toMatchObject(data);
2222

2323
expect(spy).toHaveBeenCalledTimes(2);
@@ -50,8 +50,8 @@ describe("getReplaceContextData", () => {
5050
preload: () => {
5151
return Promise.reject(rejectMessage);
5252
},
53-
}
54-
)
53+
},
54+
),
5555
).rejects.toEqual(rejectMessage);
5656

5757
expect(spy).toHaveBeenCalledTimes(1);
@@ -79,8 +79,8 @@ describe("getReplaceContextData", () => {
7979
action: () => {
8080
return Promise.reject(rejectMessage);
8181
},
82-
}
83-
)
82+
},
83+
),
8484
).rejects.toEqual(rejectMessage);
8585

8686
expect(spy).toHaveBeenCalledTimes(2);
@@ -115,8 +115,8 @@ describe("getReplaceContextData", () => {
115115
error: () => {
116116
return Promise.reject(rejectMessage);
117117
},
118-
}
119-
)
118+
},
119+
),
120120
).rejects.toEqual(errorMessages.errorCallbackRejected);
121121

122122
expect(spy).toHaveBeenCalledTimes(2);
@@ -150,8 +150,8 @@ describe("getReplaceContextData", () => {
150150
preload: () => {
151151
throw new Error(rejectMessage);
152152
},
153-
}
154-
)
153+
},
154+
),
155155
).rejects.toEqual(rejectMessage);
156156

157157
expect(spy).toHaveBeenCalledTimes(1);
@@ -179,8 +179,8 @@ describe("getReplaceContextData", () => {
179179
action: () => {
180180
throw new Error(rejectMessage);
181181
},
182-
}
183-
)
182+
},
183+
),
184184
).rejects.toEqual(rejectMessage);
185185

186186
expect(spy).toHaveBeenCalledTimes(2);
@@ -215,8 +215,8 @@ describe("getReplaceContextData", () => {
215215
error: () => {
216216
throw new Error(rejectMessage);
217217
},
218-
}
219-
)
218+
},
219+
),
220220
).rejects.toEqual(errorMessages.errorCallbackRejected);
221221

222222
expect(spy).toHaveBeenCalledTimes(2);

src/context-store--basic/modifiers/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { errorMessages, statefulStates } from "../../shared";
2-
import { ContextStore, ContextStoreData } from "../interfaces";
1+
import { errorMessages, statefulStates } from "../../shared/index.js";
2+
import { ContextStore, ContextStoreData } from "../interfaces.js";
33

44
export async function getReplaceContextData<Params, TContextStore extends ContextStore<any>>(
55
contextData: TContextStore,
@@ -9,7 +9,7 @@ export async function getReplaceContextData<Params, TContextStore extends Contex
99
action?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
1010
error?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
1111
preload?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
12-
}
12+
},
1313
): Promise<ContextStoreData<TContextStore>> {
1414
const { action, error, preload } = dataHandlers;
1515

src/context-store--basic/tests/object/index.mock.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import React, { PropsWithChildren } from "react";
2-
import {
3-
ContextStore,
4-
getNotImplementedPromise,
5-
useContextStore,
6-
} from "../../../index";
2+
import { ContextStore, getNotImplementedPromise, useContextStore } from "../../../index";
73

84
export type Item = {
95
id: 0;
@@ -39,9 +35,5 @@ export function ApiProvider(props: ProviderProps) {
3935
},
4036
});
4137

42-
return (
43-
<Context.Provider value={{ ...contextValue, changeName: up }}>
44-
{children}
45-
</Context.Provider>
46-
);
38+
return <Context.Provider value={{ ...contextValue, changeName: up }}>{children}</Context.Provider>;
4739
}

src/context-store--basic/tests/primative/index.mock.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import React, { PropsWithChildren } from "react";
2-
import {
3-
ContextStore,
4-
getNotImplementedPromise,
5-
useContextStore,
6-
} from "../../../index";
2+
import { ContextStore, getNotImplementedPromise, useContextStore } from "../../../index";
73

84
export type Item = number;
95
export interface ContextValue extends ContextStore<Item> {
@@ -30,9 +26,5 @@ export function ApiProvider(props: ProviderProps) {
3026
},
3127
});
3228

33-
return (
34-
<Context.Provider value={{ ...contextValue, oneUp: up }}>
35-
{children}
36-
</Context.Provider>
37-
);
29+
return <Context.Provider value={{ ...contextValue, oneUp: up }}>{children}</Context.Provider>;
3830
}

src/context-store--indexable/index.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { useCallback, useState } from "react";
2-
import { ContextStoreData } from "../context-store--basic/interfaces";
3-
import { getReplaceContextData } from "../context-store--basic/modifiers";
4-
import { IndexableContextStore, IndexableContextStoreKey, IndexableContextStoreValue } from "./interfaces";
5-
import { getCreateOneContextData, getDeleteOneContextData, getUpdateOneContextData } from "./modifiers";
2+
import { ContextStoreData } from "../context-store--basic/interfaces.js";
3+
import { getReplaceContextData } from "../context-store--basic/modifiers/index.js";
4+
import { IndexableContextStore, IndexableContextStoreKey, IndexableContextStoreValue } from "./interfaces.js";
5+
import { getCreateOneContextData, getDeleteOneContextData, getUpdateOneContextData } from "./modifiers/index.js";
66

77
export { IndexableContextStore };
88

99
export function useIndexableContextStore<TContextStore extends IndexableContextStore<any>>(
10-
defaultValue: TContextStore
10+
defaultValue: TContextStore,
1111
) {
1212
const [contextData, setContextData] = useState(defaultValue);
1313

@@ -17,13 +17,13 @@ export function useIndexableContextStore<TContextStore extends IndexableContextS
1717
error?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
1818
preload?: (params: Params) => Promise<ContextStoreData<TContextStore>>;
1919
},
20-
deps: React.DependencyList = []
20+
deps: React.DependencyList = [],
2121
) => {
2222
return useCallback(
2323
async (params: Params) => {
2424
return await getReplaceContextData(contextData, setContextData, params, dataHandlers);
2525
},
26-
[contextData, setContextData, ...deps]
26+
[contextData, setContextData, ...deps],
2727
);
2828
};
2929

@@ -34,13 +34,13 @@ export function useIndexableContextStore<TContextStore extends IndexableContextS
3434
getIndex: (params: Params) => IndexableContextStoreKey<TContextStore>;
3535
preload?: (params: Params) => Promise<IndexableContextStoreValue<TContextStore>>;
3636
},
37-
deps: React.DependencyList = []
37+
deps: React.DependencyList = [],
3838
) => {
3939
return useCallback(
4040
async (params: Params) => {
4141
return await getCreateOneContextData(contextData, setContextData, params, dataHandlers);
4242
},
43-
[contextData, setContextData, ...deps]
43+
[contextData, setContextData, ...deps],
4444
);
4545
};
4646

@@ -51,13 +51,13 @@ export function useIndexableContextStore<TContextStore extends IndexableContextS
5151
getIndex: (params: Params) => IndexableContextStoreKey<TContextStore>;
5252
preload?: (params: Params) => Promise<Partial<IndexableContextStoreValue<TContextStore>>>;
5353
},
54-
deps: React.DependencyList = []
54+
deps: React.DependencyList = [],
5555
) => {
5656
return useCallback(
5757
async (params: Params) => {
5858
return await getUpdateOneContextData(contextData, setContextData, params, dataHandlers);
5959
},
60-
[contextData, setContextData, ...deps]
60+
[contextData, setContextData, ...deps],
6161
);
6262
};
6363

@@ -68,13 +68,13 @@ export function useIndexableContextStore<TContextStore extends IndexableContextS
6868
getIndex: (params: Params) => IndexableContextStoreKey<TContextStore>;
6969
preload?: (params: Params) => Promise<IndexableContextStoreValue<TContextStore>>;
7070
},
71-
deps: React.DependencyList = []
71+
deps: React.DependencyList = [],
7272
) => {
7373
return useCallback(
7474
async (params: Params) => {
7575
return await getDeleteOneContextData(contextData, setContextData, params, dataHandlers);
7676
},
77-
[contextData, setContextData, ...deps]
77+
[contextData, setContextData, ...deps],
7878
);
7979
};
8080

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import { ContextStore } from "../context-store--basic";
1+
import { ContextStore } from "../context-store--basic/index.js";
22

33
// Helper type for when data is an indexable type (map or array)
44
export type IndexableContextStoreData<IndexableContextStoreItem> = Record<
55
number | string | symbol,
66
IndexableContextStoreItem
77
>;
88

9-
export interface IndexableContextStore<TDataItem>
10-
extends ContextStore<IndexableContextStoreData<TDataItem>> {}
9+
export interface IndexableContextStore<TDataItem> extends ContextStore<IndexableContextStoreData<TDataItem>> {}
1110

12-
export type IndexableContextStoreValue<
13-
TContextStore extends IndexableContextStore<any>
14-
> = TContextStore["data"][any];
11+
export type IndexableContextStoreValue<TContextStore extends IndexableContextStore<any>> = TContextStore["data"][any];
1512

16-
export type IndexableContextStoreKey<
17-
TContextStore extends IndexableContextStore<any>
18-
> = TContextStore["data"] extends Array<any>
19-
? number
20-
: keyof TContextStore["data"];
13+
export type IndexableContextStoreKey<TContextStore extends IndexableContextStore<any>> =
14+
TContextStore["data"] extends Array<any> ? number : keyof TContextStore["data"];

0 commit comments

Comments
 (0)