Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update prettier #11

Merged
merged 3 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"**/.pnp.*": true
},
"typescript.tsdk": "node_modules/typescript/lib",
"prettier.prettierPath": "yarn prettier",
"prettier.prettierPath": "./node_modules/prettier",
"prettier.ignorePath": ".prettierignore",
"eslint.format.enable": true,
"editor.formatOnSave": true,
Expand Down
Binary file not shown.
Binary file not shown.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"prettier:fix": "prettier --write ."
},
"devDependencies": {
"@types/prettier": "^2.6.0",
"prettier": "^2.6.2"
"prettier": "^3.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/core/src/UnexpectedStateError.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UnexpectedStateError from "./UnexpectedStateError";
describe("UnexpectedStateError", () => {
it("has correct prototype", () => {
expect(new UnexpectedStateError("a", "b")).toBeInstanceOf(
UnexpectedStateError
UnexpectedStateError,
);
});

Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/UnexpectedStateError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { AnyTaggedState } from "./taggedState";

class UnexpectedStateError<
State extends AnyTaggedState,
ExpectedTag extends State["tag"]
ExpectedTag extends State["tag"],
> extends Error {
constructor(
public readonly expectedTag: ExpectedTag,
public readonly actualTag: State["tag"]
public readonly actualTag: State["tag"],
) {
super(
`The state is expected to be ${JSON.stringify(expectedTag)}, ` +
`but it was ${JSON.stringify(actualTag)}.`
`but it was ${JSON.stringify(actualTag)}.`,
);
this.name = "UnexpectedStateError";
Object.setPrototypeOf(this, UnexpectedStateError.prototype);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/mkts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { StateVariant } from "./taggedState";
// Create a tagged state variant instance from the provided arguments.
function mkts<Tag extends string, Data>(
tag: Tag,
data: Data
data: Data,
): StateVariant<Tag, Data> {
return { tag, data };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/taggedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ export type EmptyObject = Record<string, never>;
export type StateVariant<
Tag extends string,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Data extends { [key: string]: any } = EmptyObject
Data extends { [key: string]: any } = EmptyObject,
> = { tag: Tag; data: Data };

export type DelegatedFlatStateVariant<
Tag extends string,
To extends { [K in "tag" | string]: K extends "tag" ? Tag : To[K] }
To extends { [K in "tag" | string]: K extends "tag" ? Tag : To[K] },
> = StateVariant<Tag, Omit<Extract<To, { tag: Tag }>, "tag">>;

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ComponentGuard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("ComponentGuard", () => {
taggedState={{ tag: "uninit", data: {} }}
uninit={uninit}
ready={ready}
/>
/>,
);

expect(view.baseElement).toHaveTextContent("uninit variant");
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/ComponentGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnyTaggedState, StateProps } from "@tagged-state/core";
export type StateComponentProps<
State extends AnyTaggedState<Tag>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
> = {
[Tag in keyof StateProps<State>]: React.ComponentType<StateProps<State>[Tag]>;
};
Expand All @@ -16,9 +16,9 @@ type Props<State extends AnyTaggedState<Tag>, Tag extends string> = {
function ComponentGuard<
State extends AnyTaggedState<Tag>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
>(
props: Props<State, Tag>
props: Props<State, Tag>,
): React.ReactElement<
React.ComponentProps<StateComponentProps<State>[Tag]>,
StateComponentProps<State>[Tag]
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/ElementGuard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("ElementGuard", () => {
taggedState={{ tag: "uninit", data: {} }}
uninit={uninit}
ready={ready}
/>
/>,
);

expect(view.baseElement).toHaveTextContent("uninit variant");
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/ElementGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AnyTaggedState, StateProps } from "@tagged-state/core";
export type StateElementProps<
State extends AnyTaggedState<Tag>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
> = {
[Tag in keyof StateProps<State>]: React.ReactElement;
};
Expand All @@ -16,7 +16,7 @@ type Props<State extends AnyTaggedState<Tag>, Tag extends string> = {
function ElementGuard<
State extends AnyTaggedState<Tag>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
>(props: Props<State, Tag>): React.ReactElement {
const { taggedState } = props;
const { tag } = taggedState;
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/ExpectContextState.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe("ExpectContextState", () => {
const view = render(
<ExpectContextState context={Test} tag={"ready" as const}>
{ready}
</ExpectContextState>
</ExpectContextState>,
);

expect(view.baseElement).toHaveTextContent("hello world");
Expand All @@ -45,7 +45,7 @@ describe("ExpectContextState", () => {
render(
<ExpectContextState context={Test} tag={"ready" as const}>
{ready}
</ExpectContextState>
</ExpectContextState>,
);
}).toThrowError(new UnexpectedStateError("ready", "uninit"));
});
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/ExpectContextState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import useTaggedState from "./useTaggedState";
type Props<
ExpectedTag,
State extends AnyTaggedState<Tag>,
Tag extends string
Tag extends string,
> = {
context: React.Context<State>;
tag: ExpectedTag;
Expand All @@ -29,7 +29,7 @@ function ExpectContextState<
ExpectedTag,
State extends AnyTaggedState<Tag>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
>(props: Props<ExpectedTag, State, Tag>) {
const { context, tag } = props;
const taggedState = useTaggedState<ExpectedTag, State>(context, tag);
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/createContextComponentGuard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe("ComponentGuard", () => {
const ContextComponentGuard = createContextComponentGuard(Test);

const view = render(
<ContextComponentGuard uninit={uninit} ready={ready} />
<ContextComponentGuard uninit={uninit} ready={ready} />,
);

expect(view.baseElement).toHaveTextContent("uninit variant");
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/createContextComponentGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import ComponentGuard, { StateComponentProps } from "./ComponentGuard";

export type ContextComponentGuardProps<
State extends AnyTaggedState<Tag>,
Tag extends string
Tag extends string,
> = StateComponentProps<State, Tag>;

function createContextComponentGuard<
Context extends React.Context<State>,
State extends AnyTaggedState<Tag> = React.ContextType<Context>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
>(context: Context): React.FC<ContextComponentGuardProps<State, Tag>> {
function ContextComponentGuard(
props: ContextComponentGuardProps<State, Tag>
props: ContextComponentGuardProps<State, Tag>,
): React.ReactElement<
React.ComponentProps<StateComponentProps<State>[Tag]>,
StateComponentProps<State>[Tag]
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/createContextElementGuard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("ElementGuard", () => {
<ContextElementGuard
uninit={<UninitComponent />}
ready={<ReadyComponent />}
/>
/>,
);

expect(view.baseElement).toHaveTextContent("uninit variant");
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/createContextElementGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ import ElementGuard, { StateElementProps } from "./ElementGuard";

export type ContextElementGuardProps<
State extends AnyTaggedState<Tag>,
Tag extends string
Tag extends string,
> = StateElementProps<State, Tag>;

function createContextElementGuard<
Context extends React.Context<State>,
State extends AnyTaggedState<Tag> = React.ContextType<Context>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Tag extends string = any
Tag extends string = any,
>(context: Context): React.FC<ContextElementGuardProps<State, Tag>> {
function ContextElementGuard(
props: ContextElementGuardProps<State, Tag>
props: ContextElementGuardProps<State, Tag>,
): React.ReactElement {
const taggedState = useContext(context);
return <ElementGuard taggedState={taggedState} {...props} />;
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/createExpectContextState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ import ExpectContextState from "./ExpectContextState";

export type BoundExpectContextStateProps<
ExpectedTag,
State extends AnyTaggedState
State extends AnyTaggedState,
> = {
children: React.ComponentType<StateProps<State>[ExpectedTag & State["tag"]]>;
};

function createExpectContextState<
ExpectedTag,
Context extends React.Context<State>,
State extends AnyTaggedState = React.ContextType<Context>
State extends AnyTaggedState = React.ContextType<Context>,
>(
context: Context,
tag: ExpectedTag
tag: ExpectedTag,
): React.VFC<BoundExpectContextStateProps<ExpectedTag, State>> {
const BoundExpectContextState: React.VFC<
BoundExpectContextStateProps<ExpectedTag, State>
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/createTaggedStateHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import useTaggedState from "./useTaggedState";

export type TaggedStateHook<
ExpectedTag,
State extends AnyTaggedState
State extends AnyTaggedState,
> = () => StateProps<State>[ExpectedTag & State["tag"]];

function createTaggedStateHook<ExpectedTag, State extends AnyTaggedState>(
context: React.Context<State>,
expectedTag: ExpectedTag
expectedTag: ExpectedTag,
): TaggedStateHook<ExpectedTag, State> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return () => useTaggedState(context, expectedTag);
Expand Down
23 changes: 13 additions & 10 deletions packages/react/src/createTaggedStateHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@ export type TaggedStateHooks<ExpectedTags, State extends AnyTaggedState> = {
function createTaggedStateHooks<
ExpectedTags extends string,
State extends AnyTaggedState<Tag>,
Tag extends string
Tag extends string,
>(
context: React.Context<State>,
expectTags: readonly ExpectedTags[]
expectTags: readonly ExpectedTags[],
): TaggedStateHooks<ExpectedTags, State> {
return expectTags.reduce((acc, tag) => {
const hookName =
tag.length === 0 ? tag : tag[0].toUpperCase() + tag.slice(1);
return {
...acc,
[`use${hookName}`]: createTaggedStateHook(context, tag),
};
}, {} as TaggedStateHooks<ExpectedTags, State>);
return expectTags.reduce(
(acc, tag) => {
const hookName =
tag.length === 0 ? tag : tag[0].toUpperCase() + tag.slice(1);
return {
...acc,
[`use${hookName}`]: createTaggedStateHook(context, tag),
};
},
{} as TaggedStateHooks<ExpectedTags, State>,
);
}

export default createTaggedStateHooks;
2 changes: 1 addition & 1 deletion packages/react/src/useTaggedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
//
function useTaggedState<ExpectedTag, State extends AnyTaggedState>(
context: React.Context<State>,
expectedTag: ExpectedTag
expectedTag: ExpectedTag,
): StateProps<State>[ExpectedTag & State["tag"]] {
const taggedState = useContext(context);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Expand Down
15 changes: 7 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@tagged-state/root@workspace:."
dependencies:
"@types/prettier": ^2.6.0
prettier: ^2.6.2
prettier: ^3.0.3
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1101,7 +1100,7 @@ __metadata:
languageName: node
linkType: hard

"@types/prettier@npm:^2.1.5, @types/prettier@npm:^2.6.0":
"@types/prettier@npm:^2.1.5":
version: 2.6.0
resolution: "@types/prettier@npm:2.6.0"
checksum: 946f1f82ce6f31664e023a5d65931c31b7d677b454f528f67dce851d72e7fcfe713076f4251b16c3646eecf1545f5f5b909b4962966341ed9ddf5b80113b3674
Expand Down Expand Up @@ -4795,12 +4794,12 @@ __metadata:
languageName: node
linkType: hard

"prettier@npm:^2.6.2":
version: 2.6.2
resolution: "prettier@npm:2.6.2"
"prettier@npm:^3.0.3":
version: 3.0.3
resolution: "prettier@npm:3.0.3"
bin:
prettier: bin-prettier.js
checksum: 48d08dde8e9fb1f5bccdd205baa7f192e9fc8bc98f86e1b97d919de804e28c806b0e6cc685e4a88211aa7987fa9668f30baae19580d87ced3ed0f2ec6572106f
prettier: bin/prettier.cjs
checksum: e10b9af02b281f6c617362ebd2571b1d7fc9fb8a3bd17e371754428cda992e5e8d8b7a046e8f7d3e2da1dcd21aa001e2e3c797402ebb6111b5cd19609dd228e0
languageName: node
linkType: hard

Expand Down