Skip to content

Commit

Permalink
refactor: update
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Sep 22, 2024
1 parent fb2b02f commit 459e95e
Show file tree
Hide file tree
Showing 33 changed files with 426 additions and 236 deletions.
72 changes: 34 additions & 38 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
// @ts-check
import { defineConfig } from 'eslint-config-hyoban'

import recursiveSort from './plugins/eslint-recursive-sort'

export default defineConfig(
{
formatting: false,
lessOpinionated: true,
ignores: [],
ignores: [
'src/renderer/src/hono.ts',
'src/hono.ts',
'packages/shared/src/hono.ts',
'resources/**',
],
preferESM: false,
react: 'vite',
tailwindCSS: true,
},
{
settings: {
Expand All @@ -17,45 +22,36 @@ export default defineConfig(
},
},
rules: {
'package-json/valid-package-def': 'off',
'@eslint-react/no-missing-key': 'warn',
'no-restricted-syntax': 'off',
'import/no-anonymous-default-export': 'off',
eqeqeq: 'warn',
'no-console': 'warn',
'@typescript-eslint/no-unsafe-function-type': 'off',
'no-empty': 'warn',
'@typescript-eslint/no-empty-object-type': 'warn',
'unicorn/prefer-query-selector': 0,
'regexp/no-super-linear-backtracking': 0,
'regexp/no-useless-assertions': 0,
'unicorn/no-new-array': 0,
'@typescript-eslint/method-signature-style': 0,
'unicorn/prefer-code-point': 'warn',
'unicorn/no-object-as-default-parameter': 'warn',
'unused-imports/no-unused-vars': 'warn',
'@eslint-react/no-unstable-default-props': 'warn',
'unicorn/prefer-regexp-test': 'warn',
'no-unsafe-optional-chaining': 'warn',
'unicorn/prefer-logical-operator-over-ternary': 'warn',
'arrow-body-style': 0,
'unicorn/no-array-callback-reference': 0,
'prefer-regex-literals': 0,
'regexp/optimal-quantifier-concatenation': 'warn',
'unicorn/prefer-string-slice': 0,
'array-callback-return': 0,
'regexp/no-unused-capturing-group': 1,
'unicorn/no-anonymous-default-export': 0,
'unicorn/no-magic-array-flat-depth': 1,
'react-refresh/only-export-components': 'error',
'unicorn/prefer-math-trunc': 'off',
'@eslint-react/no-clone-element': 0,
'@eslint-react/hooks-extra/no-direct-set-state-in-use-effect': 0,
// NOTE: Disable this temporarily
'react-compiler/react-compiler': 0,
'no-restricted-syntax': 0,
'no-restricted-globals': [
'error',
{
name: 'location',
message:
"Since you don't use the same router instance in electron and browser, you can't use the global location to get the route info. \n\n" +
'You can use `useLocaltion` or `getReadonlyRoute` to get the route info.',
},
],
},
},

{
files: ['**/*/package.json', 'package.json'],
files: ['**/*.tsx'],
rules: {
'@stylistic/jsx-self-closing-comp': 'error',
},
},
{
files: ['locales/**/*.json'],
plugins: {
'recursive-sort': recursiveSort,
},
rules: {
'package-json/valid-package-def': 0,
'package-json/valid-name': 0,
'recursive-sort/recursive-sort': 'error',
},
},
)
33 changes: 32 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script>
function setTheme() {
let e = 'color-mode',
t = document.documentElement,
a = localStorage.getItem(e)
function h() {
return window.matchMedia
? window.matchMedia('(prefers-color-scheme: dark)').matches
? 'dark'
: window.matchMedia('(prefers-color-scheme: light)').matches
? 'light'
: void 0
: void 0
}
if (!a) {
t.dataset.theme = h() || 'light'
return
}
switch ((a = JSON.parse(a))) {
case 'dark':
t.dataset.theme = 'dark'
break
case 'light':
t.dataset.theme = 'light'
break
case 'system':
t.dataset.theme = h() || 'light'
}
}
setTheme()
</script>
</head>
<body>
<div id="root"></div>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"react-dom": "18.3.1",
"react-router-dom": "6.26.2",
"sonner": "1.5.0",
"tailwind-merge": "2.5.2"
"tailwind-merge": "2.5.2",
"usehooks-ts": "3.1.0"
},
"devDependencies": {
"@egoist/tailwindcss-icons": "1.8.1",
Expand Down
File renamed without changes.
60 changes: 60 additions & 0 deletions plugins/eslint-recursive-sort.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const sortObjectKeys = (obj) => {
if (typeof obj !== 'object' || obj === null) {
return obj
}

if (Array.isArray(obj)) {
return obj.map((element) => sortObjectKeys(element))
}

return Object.keys(obj)
.sort()
.reduce((acc, key) => {
acc[key] = sortObjectKeys(obj[key])
return acc
}, {})
}
/**
* @type {import("eslint").ESLint.Plugin}
*/
export default {
rules: {
'recursive-sort': {
meta: {
type: 'layout',
fixable: 'code',
},
create(context) {
return {
Program(node) {
if (context.getFilename().endsWith('.json')) {
const sourceCode = context.getSourceCode()
const text = sourceCode.getText()

try {
const json = JSON.parse(text)
const sortedJson = sortObjectKeys(json)
const sortedText = JSON.stringify(sortedJson, null, 2)

if (text.trim() !== sortedText.trim()) {
context.report({
node,
message: 'JSON keys are not sorted recursively',
fix(fixer) {
return fixer.replaceText(node, sortedText)
},
})
}
} catch (error) {
context.report({
node,
message: `Invalid JSON: ${error.message}`,
})
}
}
},
}
},
},
},
}
19 changes: 19 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/atoms/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { selectAtom } from 'jotai/utils'
import { useMemo } from 'react'
import type { Location, NavigateFunction, Params } from 'react-router-dom'

import { createAtomHooks } from '~/utils/jotai'
import { createAtomHooks } from '~/lib/jotai'

interface RouteAtom {
params: Readonly<Params<string>>
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/ErrorElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { repository } from '@pkg'
import { useEffect, useRef } from 'react'
import { isRouteErrorResponse, useRouteError } from 'react-router-dom'

import { attachOpenInEditor } from '~/utils/dev'
import { attachOpenInEditor } from '~/lib/dev'

import { StyledButton } from '../ui'

Expand Down
84 changes: 0 additions & 84 deletions src/components/hooks/common/useBizQuery.ts

This file was deleted.

Loading

0 comments on commit 459e95e

Please sign in to comment.