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

Fix/lint script #122

Closed
wants to merge 8 commits into from
Closed
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
11 changes: 9 additions & 2 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const path = require('path');

const buildEslintCommand = (filenames) =>
const checkType = () => 'bash -c tsc --skipLibCheck --noEmit';

const checkLint = (filenames) =>
`next lint --fix --file ${filenames
.map((f) => path.relative(process.cwd(), f))
.join(' --file ')}`;

const checkPrettier = (filenames) =>
`prettier --write ${filenames
.map((f) => path.relative(process.cwd(), f))
.join(' ')}`;

module.exports = {
'*.{js,jsx,ts,tsx}': [buildEslintCommand, 'prettier --write'],
'*.{js,jsx,ts,tsx}': [checkType, checkLint, checkPrettier],
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"scripts": {
"dev": "next dev",
"build": "next build",
"lint": "next lint",
"type-check": "tsc --skipLibCheck --noEmit",
"lint": "yarn type-check && next lint",
"lint:staged": "lint-staged",
"start": "yarn build && next start",
"preinstall": "node src/scripts/node-version-checker.js",
Expand All @@ -18,7 +19,7 @@
"test:watch": "jest --watch",
"clean-up": "node src/scripts/remove-unnecessary.js",
"tokript": "tokript",
"theme": "chakra-cli tokens src/configs/theme",
"theme": "chakra-cli tokens src/configs/theme/index.ts",
"theme:open": "code -r node_modules/@chakra-ui/styled-system/dist/theming.types.d.ts",
"gen:source": "tokript gen:source",
"gen:api": "tokript gen:api",
Expand Down
4 changes: 3 additions & 1 deletion src/types/module/react-query/use-infinite-query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { Parameter } from '@/types/utility/parameter';

import { WrapVariables } from './wrap-variables';

// Example : const useAnyQuery = ({ options, variables } : UseInfiniteQueryParams<typeof anyApiFn>) => {...}
/**
* @example const useAnyQuery = ({ options, variables } : UseInfiniteQueryParams<typeof anyApiFn>) => {...}
*/

export type UseInfiniteQueryParams<
T extends AsyncFn,
Expand Down
4 changes: 3 additions & 1 deletion src/types/module/react-query/use-mutation-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import { AsyncFn } from '@/types/static/async-fn';
import { AsyncFnReturn } from '@/types/utility/async-fn-return';
import { Parameter } from '@/types/utility/parameter';

// Example : const useAnyMutation = ({ options, variables } : UseMutationParams<typeof anyApiFn>) => {...}
/**
* @example const useAnyMutation = ({ options, variables } : UseMutationParams<typeof anyApiFn>) => {...}
*/

export type UseMutationParams<
T extends AsyncFn,
Expand Down
5 changes: 4 additions & 1 deletion src/types/module/react-query/use-query-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { Parameter } from '@/types/utility/parameter';

import { WrapVariables } from './wrap-variables';

// Example : const useAnyQuery = ({ options, variables } : UseQueryParams<typeof anyApiFn>) => {...}
/**
* @example const useAnyQuery = ({ options, variables } : UseInfiniteQueryParams<typeof anyApiFn>) => {...}
*/

export type UseQueryParams<
T extends AsyncFn,
Error = AxiosError<any>,
Expand Down
7 changes: 5 additions & 2 deletions src/types/utility/async-fn-return.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { AsyncFn } from '@/types/static/async-fn';

// type Example = AsyncFnReturn<() => Promise<number>>;
// Example = number
/**
* @example
type Example = AsyncFnReturn<() => Promise<number>>;
Example = number
*/

export type AsyncFnReturn<T extends AsyncFn> = Awaited<ReturnType<T>>;
19 changes: 11 additions & 8 deletions src/types/utility/deep-mutable.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Mutable } from './mutable';

// type Example = DeepMutable<{
// readonly a: number;
// readonly b: { readonly c: number; readonly d: string };
// }>;
/**
* @example
type Example = DeepMutable<{
readonly a: number;
readonly b: { readonly c: number; readonly d: string };
}>;

// Example = {
// a: number;
// b?: { c? : number; d? : string };
// }
Example = {
a: number;
b?: { c? : number; d? : string };
}
*/

export type DeepMutable<T extends Record<any, any> | undefined> = Mutable<{
[K in keyof T]: T[K] extends Record<any, any> | undefined
Expand Down
19 changes: 11 additions & 8 deletions src/types/utility/deep-nullable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import { Obj } from '@/types/static/obj';

import { NullAble } from './nullable';

// type Example = DeepNullAble<{
// a: number;
// b: { c : number; d : string };
// }>;
/**
* @example
type Example = DeepNullAble<{
a: number;
b: { c : number; d : string };
}>;

// Example = {
// a: number | null;
// b?: { c? : number | null; d? : string | null } | null;
// }
Example = {
a: number | null;
b?: { c? : number | null; d? : string | null } | null;
}
*/

export type DeepNullAble<T extends Obj | undefined> = NullAble<{
[K in keyof T]: T[K] extends Obj | undefined ? NullAble<T[K]> : T[K];
Expand Down
15 changes: 9 additions & 6 deletions src/types/utility/deep-omit-readonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import { Obj } from '@/types/static/obj';

import { ReadonlyKeysOf } from './readonly-keys-of';

// type Example = OmitReadOnly<{
// readonly a: number;
// readonly b: string;
// c: { readonly d : number; e : string };
// }>;
/**
* @example
type Example = OmitReadOnly<{
readonly a: number;
readonly b: string;
c: { readonly d : number; e : string };
}>;

// Example = { c : { e: string }; }
Example = { c : { e: string }; }
*/

export type DeepOmitReadOnly<T extends Obj | undefined> = Omit<
{
Expand Down
19 changes: 11 additions & 8 deletions src/types/utility/deep-partial.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { Obj } from '@/types/static/obj';

// type Example = DeepPartial<{
// a: number;
// b: { c : number; d : string };
// }>;
/**
* @example
type Example = DeepPartial<{
a: number;
b: { c : number; d : string };
}>;

// Example = {
// a?: number;
// b?: { c? : number; d? : string };
// }
Example = {
a?: number;
b?: { c? : number; d? : string };
}
*/

export type DeepPartial<T extends Obj | undefined> = Partial<{
[K in keyof T]: T[K] extends Obj | undefined ? Partial<T[K]> : T[K];
Expand Down
11 changes: 7 additions & 4 deletions src/types/utility/if-equals.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// type Example1 = IfEquals<number, string, true, false>;
// type Example2 = IfEquals<number, number, true, false>;
/**
* @example
type Example1 = IfEquals<number, string, true, false>;
type Example2 = IfEquals<number, number, true, false>;

// Example1 = true
// Example2 = false
Example1 = true
Example2 = false
*/

export type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X
? 1
Expand Down
7 changes: 5 additions & 2 deletions src/types/utility/item-of.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// type Example = ItemOf<['a', 'b', 'c']>;
// Example = "a" | "b" | "c"
/**
* @example
type Example = ItemOf<['a', 'b', 'c']>;
Example = "a" | "b" | "c"
*/

export type ItemOf<T extends Array<any> | readonly any[]> = T[number];
7 changes: 5 additions & 2 deletions src/types/utility/mutable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// type Example = Mutable<{ readonly a: 1; b: 1 }>;
// Example = { a: 1; b: 1; }
/**
* @example
type Example = Mutable<{ readonly a: 1; b: 1 }>;
Example = { a: 1; b: 1; }
*/

export type Mutable<T extends Record<any, any> | undefined> = {
-readonly [key in keyof T]: T[key];
Expand Down
7 changes: 5 additions & 2 deletions src/types/utility/nullable.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Obj } from '@/types/static/obj';

// type Example = NullAble<{ a: 1; b: 1 }>;
// Example = { a: 1 | null; b: 1 | null}
/**
* @example
type Example = NullAble<{ a: 1; b: 1 }>;
Example = { a: 1 | null; b: 1 | null}
*/

export type NullAble<T extends Obj | undefined> = {
[P in keyof T]: T[P] | null;
Expand Down
16 changes: 9 additions & 7 deletions src/types/utility/omit-readonly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Obj } from '@/types/static/obj';

import { ReadonlyKeysOf } from './readonly-keys-of';

// type Example = OmitReadOnly<{
// readonly a: number;
// b: string;
// readonly c: string;
// }>;

// Example = { b : string; }
/**
* @example
type Example = OmitReadOnly<{
readonly a: number;
b: string;
readonly c: string;
}>;
Example = { b : string; }
*/

export type OmitReadOnly<T extends Obj> = Omit<T, ReadonlyKeysOf<T>>;
7 changes: 5 additions & 2 deletions src/types/utility/parameter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// type Example = Parameter<(value: number) => void>
// Example = number
/**
* @example
type Example = Parameter<(value: number) => void>
Example = number
*/

export type Parameter<T> = T extends (param: infer U) => any ? U : never;
15 changes: 9 additions & 6 deletions src/types/utility/readonly-keys-of.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { IfEquals } from './if-equals';

// type Example = ReadonlyKeysOf<{
// readonly a: number;
// b: string;
// readonly c: string;
// }>;
// Example1 = "a" | "c"
/**
* @example
type Example = ReadonlyKeysOf<{
readonly a: number;
b: string;
readonly c: string;
}>;
Example1 = "a" | "c"
*/

export type ReadonlyKeysOf<T extends object> = {
[P in keyof T]-?: IfEquals<
Expand Down
7 changes: 5 additions & 2 deletions src/types/utility/value-of.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Obj } from '@/types/static/obj';

// type Example = ValueOf<{ a: number; b: string }>;
// Example = number | string
/**
* @example
type Example = ValueOf<{ a: number; b: string }>;
Example = number | string
*/

export type ValueOf<T> = T extends Obj ? T[keyof T] : unknown;
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@/icons": ["./generated/icons/MyIcons.tsx"],
"@/generated/*": ["./generated/*"]
},
"target": "es5",
"target": "ES6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand Down
Loading
Loading