Skip to content

Commit 4aee6fc

Browse files
committed
chore: tailwind linter
- use clsx to build complex classNames
1 parent 40ca5d6 commit 4aee6fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+368
-94
lines changed

.vscode/settings.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
2-
"typescript.tsdk": "node_modules/typescript/lib",
2+
"editor.codeActionsOnSave": {
3+
"source.fixAll.eslint": "explicit"
4+
},
35
"files.associations": {
46
"*.css": "tailwindcss"
57
},
6-
"tailwindCSS.rootFontSize": 14,
78
"search.exclude": {
89
"cs2-server-plugin/cs2-server-plugin/deps": true,
910
"csgo-server-plugin/csgo-server-plugin/deps": true
10-
}
11+
},
12+
"tailwindCSS.rootFontSize": 14,
13+
"typescript.tsdk": "node_modules/typescript/lib"
1114
}

eslint.config.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import checkFile from 'eslint-plugin-check-file';
66
import localRules from 'eslint-plugin-local-rules';
77
import lingui from 'eslint-plugin-lingui';
88
import prettier from 'eslint-plugin-prettier/recommended';
9+
import eslintPluginBetterTailwindcss from 'eslint-plugin-better-tailwindcss';
910

1011
export default [
1112
{
@@ -57,6 +58,7 @@ export default [
5758
plugins: {
5859
'check-file': checkFile,
5960
lingui,
61+
'better-tailwindcss': eslintPluginBetterTailwindcss,
6062
'local-rules': localRules,
6163
'react-hooks': reactHooks,
6264
},
@@ -72,6 +74,9 @@ export default [
7274
react: {
7375
version: 'detect',
7476
},
77+
'better-tailwindcss': {
78+
entryPoint: 'src/ui/index.css',
79+
},
7580
},
7681

7782
rules: {
@@ -141,6 +146,11 @@ export default [
141146
],
142147
'check-file/no-index': 'error',
143148
eqeqeq: 'error',
149+
...eslintPluginBetterTailwindcss.configs['recommended-warn'].rules,
150+
...eslintPluginBetterTailwindcss.configs['recommended-error'].rules,
151+
'better-tailwindcss/enforce-consistent-class-order': 'off',
152+
'better-tailwindcss/enforce-consistent-line-wrapping': 'off',
153+
'better-tailwindcss/no-unregistered-classes': ['error', { ignore: ['dark', 'changelog', 'waveform'] }],
144154
'lingui/no-unlocalized-strings': [
145155
'error',
146156
{

package-lock.json

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"archiver": "7.0.1",
7979
"babel-plugin-react-compiler": "19.1.0-rc.2",
8080
"chokidar": "4.0.3",
81+
"clsx": "2.1.1",
8182
"crc64-ecma": "2.0.0",
8283
"csgo-protobuf": "4.0.2",
8384
"csgo-sharecode": "3.1.2",
@@ -94,6 +95,7 @@
9495
"esbuild": "0.25.9",
9596
"eslint": "9.34.0",
9697
"eslint-config-prettier": "10.1.8",
98+
"eslint-plugin-better-tailwindcss": "3.7.8",
9799
"eslint-plugin-check-file": "3.3.0",
98100
"eslint-plugin-deprecation": "3.0.0",
99101
"eslint-plugin-lingui": "0.11.0",

src/ui/components/avatar.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useEffect, useState } from 'react';
2+
import clsx from 'clsx';
23
import type { PlayerColor } from 'csdm/common/types/counter-strike';
34
import { getPlayerColorBorderClassName } from 'csdm/ui/styles/get-player-color-border-class-name';
45

@@ -23,7 +24,10 @@ export function Avatar({ avatarUrl, playerName, playerColor, size }: Props) {
2324

2425
return (
2526
<img
26-
className={`border ${playerColor ? getPlayerColorBorderClassName(playerColor) : 'border-gray-300'} size-[100px]`}
27+
className={clsx(
28+
'border size-[100px]',
29+
playerColor ? getPlayerColorBorderClassName(playerColor) : 'border-gray-300',
30+
)}
2731
style={{
2832
width: size,
2933
height: size,

src/ui/components/buttons/button.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ButtonHTMLAttributes, MouseEventHandler, ReactNode } from 'react';
22
import React from 'react';
3+
import clsx from 'clsx';
34

45
export const ButtonVariant = {
56
Default: 'default',
@@ -39,14 +40,15 @@ export function Button({
3940
return (
4041
<button
4142
ref={ref}
42-
className={`px-12 leading-none whitespace-nowrap rounded border flex items-center duration-85 transition-all relative cursor-default h-[30px] aria-disabled:bg-gray-300 aria-disabled:text-gray-600 aria-disabled:border-transparent ${
43+
className={clsx(
44+
'px-12 leading-none whitespace-nowrap rounded border flex items-center duration-85 transition-all relative cursor-default h-[30px] aria-disabled:bg-gray-300 aria-disabled:text-gray-600 aria-disabled:border-transparent',
4345
{
4446
[ButtonVariant.Default]:
4547
'bg-gray-50 border-gray-400 text-gray-800 active:bg-gray-200 hover:text-gray-900 hover:border-gray-900 focus:border-gray-800 focus-visible:outline-hidden',
4648
[ButtonVariant.Danger]: 'bg-red-700 border-red-700 text-white active:bg-red-500 hover:bg-red-600',
4749
[ButtonVariant.Primary]: 'bg-blue-600 border-blue-600 text-white active:bg-blue-800 hover:bg-blue-700',
48-
}[variant]
49-
}`}
50+
}[variant],
51+
)}
5052
aria-disabled={isDisabled}
5153
type={type}
5254
onClick={isDisabled ? undefined : handleClick}

src/ui/components/context-menu/context-menu-item.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ReactNode } from 'react';
22
import React from 'react';
3+
import clsx from 'clsx';
34
import { useContextMenu } from 'csdm/ui/components/context-menu/use-context-menu';
45

56
type Props = {
@@ -18,9 +19,10 @@ export function ContextMenuItem({ onClick, children, isDisabled }: Props) {
1819

1920
return (
2021
<div
21-
className={`flex items-center leading-none h-32 px-16 min-w-[224px] hover:bg-gray-200 select-none rounded ${
22-
isDisabled ? 'opacity-50 pointer-events-none' : 'opacity-100 pointer-events-auto hover:text-gray-900'
23-
}`}
22+
className={clsx(
23+
'flex items-center leading-none h-32 px-16 min-w-[224px] hover:bg-gray-200 select-none rounded',
24+
isDisabled ? 'opacity-50 pointer-events-none' : 'opacity-100 pointer-events-auto hover:text-gray-900',
25+
)}
2426
onClick={handleClick}
2527
>
2628
<div className="flex justify-between items-center flex-1">{children}</div>

src/ui/components/context-menu/sub-context-menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function SubContextMenu({ label, children }: Props) {
5151

5252
return (
5353
<div
54-
className={`relative flex items-center h-32 leading-none px-16 min-w-[224px] hover:bg-gray-300`}
54+
className="relative flex items-center h-32 leading-none px-16 min-w-[224px] hover:bg-gray-300"
5555
onMouseEnter={onMouseEnter}
5656
onMouseLeave={onMouseLeave}
5757
>

0 commit comments

Comments
 (0)