Skip to content

Commit

Permalink
Refactor: Migrate ESLint configuration to new format and update depen…
Browse files Browse the repository at this point in the history
…dencies
  • Loading branch information
1aron committed Dec 2, 2024
1 parent cf2bf43 commit 7e9ea82
Show file tree
Hide file tree
Showing 16 changed files with 2,325 additions and 1,007 deletions.
3 changes: 0 additions & 3 deletions .eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: 'pnpm'
- run: pnpm install
- run: pnpm exec playwright install --with-deps
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
version: 8
- uses: actions/setup-node@v4
with:
node-version: 20
node-version: 22
cache: "pnpm"
- run: pnpm install
- run: pnpm install semantic-release-config-techor --workspace-root
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"url": "https://github.com/master-co/styled.git"
},
"dependencies": {
"@techor/repo": "^3.0.17"
"@techor/repo": "^3.1.4",
"eslint": "^9.16.0"
},
"devDependencies": {
"class-variant": "workspace:^"
Expand Down
2 changes: 0 additions & 2 deletions packages/core/.eslintrc.yml

This file was deleted.

7 changes: 7 additions & 0 deletions packages/core/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import techor from 'eslint-config-techor'

export default [
techor.configs.base,
techor.configs.stylistic,
techor.configs.typescript,
]
6 changes: 3 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ type ReturnType<T> = { default?: Partial<T> } & ((valueByProp?: T) => string)
* 5. { intent: { primary: 'bg:blue-50 fg:white', secondary: 'bg:white fg:gray-80' }, size: { sm: 'font:20 py:1 px:2', md: 'font:16 py:2 px:4' }, disabled: 'opacity:.5' }
* 6. ({ $intent, $size }) => $intent && $size && 'font:italic'
*/
function cv<T extends Record<string, string | number | boolean>>(...params: Array<Param<T>>): ReturnType<T>
function cv<T extends Record<string, string | number | boolean>>(firstParam: TemplateStringsArray, ...params: Array<Param<T>>): ReturnType<T>
function cv<T extends Record<string, string | number | boolean>>(firstParam: TemplateStringsArray | Param<T>, ...params: Array<Param<T>>): ReturnType<T> {
function cv<T extends Record<string, string | number | boolean>>(...params: Param<T>[]): ReturnType<T>
function cv<T extends Record<string, string | number | boolean>>(firstParam: TemplateStringsArray, ...params: Param<T>[]): ReturnType<T>
function cv<T extends Record<string, string | number | boolean>>(firstParam: TemplateStringsArray | Param<T>, ...params: Param<T>[]): ReturnType<T> {
return function getClassNames(valueByProp: T = {} as any) {
// 如果 valueByProps 中的屬性是 undefined 或是 null,則使用 default 中的值
const defaultProps = (getClassNames as ReturnType<T>).default
Expand Down
32 changes: 0 additions & 32 deletions packages/react/.eslintrc.yml

This file was deleted.

8 changes: 8 additions & 0 deletions packages/react/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import techor from 'eslint-config-techor'

export default [
techor.configs.base,
techor.configs.stylistic,
techor.configs.typescript,
techor.configs.react
]
3 changes: 1 addition & 2 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
},
"devDependencies": {
"@playwright/experimental-ct-react": "1.49.0",
"@playwright/test": "1.49.0",
"eslint-plugin-react-hooks": "^4.6.0"
"@playwright/test": "1.49.0"
}
}
20 changes: 7 additions & 13 deletions packages/react/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ type baseType<E> = string
| Record<string, boolean>
| [string, { [key in keyof E]?: E[key] }]
| { [key in keyof E]?: E[key] extends boolean | undefined ? string : Record<string, string> }
type baseLoopType<E> = baseType<E> | Array<baseType<E>>;
type extraType<E> = { className?: baseLoopType<E> | undefined, [key: string]: any };
type TagParams = Array<[TemplateStringsArray, any[]]>;
type baseLoopType<E> = baseType<E> | baseType<E>[];
interface extraType<E> { className?: baseLoopType<E> | undefined, [key: string]: any }
type TagParams = [TemplateStringsArray, any[]][];

type IntrinsicElementsKeys = keyof JSX.IntrinsicElements;
type MasterComponentProps<K extends IntrinsicElementsKeys | React.ComponentType<any>, E extends object = object> = extraType<E> & (Omit<(K extends IntrinsicElementsKeys
Expand All @@ -22,7 +22,7 @@ type MasterComponentProps<K extends IntrinsicElementsKeys | React.ComponentType<
type MasterExoticComponent<K extends IntrinsicElementsKeys | React.ComponentType<any>, E extends object = object> = React.ForwardRefExoticComponent<MasterComponentProps<K, E> & React.RefAttributes<K>> & { tag: K, params: TagParams, default?: MasterComponentProps<K, E> };

type ParamType<K extends IntrinsicElementsKeys | React.ComponentType<any>, E extends object = object> = ((props: MasterComponentProps<K, E>) => baseLoopType<MasterComponentProps<K, E>> | undefined) | baseLoopType<MasterComponentProps<K, E>>
type ParamsType<K extends IntrinsicElementsKeys | React.ComponentType<any>, E extends object = object> = Array<ParamType<K, E>>;
type ParamsType<K extends IntrinsicElementsKeys | React.ComponentType<any>, E extends object = object> = ParamType<K, E>[];

type ReturnType<K extends IntrinsicElementsKeys | React.ComponentType<any>, E extends object = object> = <F extends TemplateStringsArray | MasterExoticComponent<any> | baseType<E>>(
firstParam: F,
Expand All @@ -36,14 +36,8 @@ type ReturnType<K extends IntrinsicElementsKeys | React.ComponentType<any>, E ex
const styled: {
[key in IntrinsicElementsKeys]: (<E extends object = object>(firstParam: TemplateStringsArray | ParamType<key, E>, ...params: ParamsType<key, E>) => MasterExoticComponent<key, E>)
& (<F extends MasterExoticComponent<any, any>, E extends object = object>(firstParam: F) => F extends MasterExoticComponent<any, infer ME> ? ReturnType<key, ME & E> : never)
} & {
<F extends MasterExoticComponent<any>, E extends object = object>(firstParam: F): F extends MasterExoticComponent<infer K, infer ME> ? ReturnType<K, ME & E> : never
} & {
<E extends object = object>(firstParam: TemplateStringsArray | ParamType<'div', E>, ...params: ParamsType<'div', E>): MasterExoticComponent<'div', E>
} & {
//@ts-ignore
<F extends React.ComponentType<any>, E extends object = object>(firstParam: F, ...params: F extends React.ComponentType<infer RE> ? ParamsType<'div', RE & E> : never): F extends React.ComponentType<infer RE> ? ReturnType<React.ComponentType<RE & E>> : never
} = new Proxy(
} & (<F extends MasterExoticComponent<any>, E extends object = object>(firstParam: F) => F extends MasterExoticComponent<infer K, infer ME> ? ReturnType<K, ME & E> : never) & (<E extends object = object>(firstParam: TemplateStringsArray | ParamType<'div', E>, ...params: ParamsType<'div', E>) => MasterExoticComponent<'div', E>) & //@ts-ignore
(<F extends React.ComponentType<any>, E extends object = object>(firstParam: F, ...params: F extends React.ComponentType<infer RE> ? ParamsType<'div', RE & E> : never) => F extends React.ComponentType<infer RE> ? ReturnType<React.ComponentType<RE & E>> : never) = new Proxy(
((firstParam: any, ...params: any[]) => {
return (Array.isArray(firstParam) && 'raw' in firstParam || typeof firstParam !== 'object' || !('render' in firstParam))
? styled.div(firstParam as any, ...params)
Expand Down Expand Up @@ -139,7 +133,7 @@ function handle<K extends IntrinsicElementsKeys | React.ComponentType<any>, E ex
}
break
case 'function':
// eslint-disable-next-line no-case-declarations
const transformedParam = param(props)
if (typeof transformedParam === 'object' && handleParam(transformedParam))
return true
Expand Down
32 changes: 0 additions & 32 deletions packages/vue/.eslintrc.yml

This file was deleted.

20 changes: 20 additions & 0 deletions packages/vue/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import techor from 'eslint-config-techor'
import vue from 'eslint-plugin-vue'

export default [
techor.configs.base,
techor.configs.stylistic,
techor.configs.typescript,
...vue.configs['flat/essential'],
{
files: ['**/*.vue'],
rules: {
'vue/multi-word-component-names': 'off'
},
languageOptions: {
parserOptions: {
parser: '@typescript-eslint/parser'
}
}
}
]
1 change: 1 addition & 0 deletions packages/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@vue/server-renderer": "^3.4.19",
"@vue/test-utils": "^2.4.4",
"@vue/tsconfig": "^0.7.0",
"eslint-plugin-vue": "^9.32.0",
"typescript": "5.6.2",
"vite": "^6.0.1",
"vue-tsc": "^2.0.29"
Expand Down
24 changes: 8 additions & 16 deletions packages/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends (
: B
type WritableKeys<T> = {
[P in keyof T]-?: IfEquals<
{ [Q in P]: T[P]; },
{ -readonly [Q in P]: T[P] },
Record<P, T[P]>,
Record<P, T[P]>,
P
>
}[keyof T];
Expand All @@ -23,15 +23,15 @@ type BaseType<E> = string
| string[]
| Record<string, boolean>
| (
E extends Array<any>
E extends any[]
? never
: [string, { [key in keyof E]?: E[key] }]
| { [key in keyof E]?: E[key] extends boolean | undefined ? string : Record<string, string> }
)
type BaseLoopType<E> = BaseType<E> | Array<BaseType<E>>
type TagParams = Array<[TemplateStringsArray, any[]]>;
type BaseLoopType<E> = BaseType<E> | BaseType<E>[]
type TagParams = [TemplateStringsArray, any[]][];
type ParamType<K extends HTMLElementTagNameKeys | VNode, E extends object = object> = ((props: MasterComponentProps<K, E>) => BaseLoopType<MasterComponentProps<K, E>> | undefined) | BaseLoopType<MasterComponentProps<K, E>>
type ParamsType<K extends HTMLElementTagNameKeys | VNode, E extends object = object> = Array<ParamType<K, E>>;
type ParamsType<K extends HTMLElementTagNameKeys | VNode, E extends object = object> = ParamType<K, E>[];
type MasterComponentProps<K extends HTMLElementTagNameKeys | VNode, E extends object = object> =
Partial<E>
& { className?: BaseLoopType<E> | undefined, [key: string]: any }
Expand All @@ -55,15 +55,7 @@ const styled: {
& (<E extends object>(firstParam: TemplateStringsArray | ParamType<K, E>, ...params: ParamsType<K, E>) => MasterComponent<K, E>)
& (<F extends MasterComponent<any>, E extends object = object>(firstParam: F) => F extends MasterComponent<any, infer ME> ? ReturnType<K, ME & E> : never)
& (<F extends VNode, E extends object = object>(firstParam: F) => ReturnType<K, E>)
} & {
<F extends MasterComponent<any>, E extends object = object>(firstParam: F): F extends MasterComponent<infer K, infer ME> ? ReturnType<K, ME & E> : never
} & {
<F extends VNode, E extends object = object>(firstParam: F): ReturnType<F, E>
} & {
(firstParam: TemplateStringsArray | ParamType<'div'>, ...params: ParamsType<'div'>): MasterComponent<'div'>
} & {
<E extends object = object>(firstParam: TemplateStringsArray | ParamType<'div', E>, ...params: ParamsType<'div', E>): MasterComponent<'div', E>
} = new Proxy(
} & (<F extends MasterComponent<any>, E extends object = object>(firstParam: F) => F extends MasterComponent<infer K, infer ME> ? ReturnType<K, ME & E> : never) & (<F extends VNode, E extends object = object>(firstParam: F) => ReturnType<F, E>) & ((firstParam: TemplateStringsArray | ParamType<'div'>, ...params: ParamsType<'div'>) => MasterComponent<'div'>) & (<E extends object = object>(firstParam: TemplateStringsArray | ParamType<'div', E>, ...params: ParamsType<'div', E>) => MasterComponent<'div', E>) = new Proxy(
// @ts-ignore
((firstParam, ...params) => {
return (
Expand Down Expand Up @@ -161,7 +153,7 @@ function handle<K extends string | VNode, E extends object = object>(tag: K, tag
}
break
case 'function':
// eslint-disable-next-line no-case-declarations

const transformedParam = param(mergedProps)
if (typeof transformedParam === 'object' && handleParam(transformedParam))
return true
Expand Down
Loading

0 comments on commit 7e9ea82

Please sign in to comment.