Skip to content

Commit 8fd10bc

Browse files
committed
harmonize eslint and vite configuration with hightable
1 parent 6a31a27 commit 8fd10bc

21 files changed

+89
-91
lines changed

bin/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ if (arg === 'chat') {
2323
console.log(packageJson.version)
2424
} else if (!arg) {
2525
serve(process.cwd(), undefined) // current directory
26-
} else if (arg.match(/^https?:\/\//)) {
26+
} else if (/^https?:\/\//.exec(arg)) {
2727
serve(undefined, arg) // url
2828
} else {
2929
// resolve file or directory

bin/serve.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function handleRequest(req, serveDirectory) {
123123
*/
124124
async function handleStatic(filePath, range) {
125125
const stats = await fs.stat(filePath).catch(() => undefined)
126-
if (!stats || !stats.isFile()) {
126+
if (!stats?.isFile()) {
127127
return { status: 404, content: 'not found' }
128128
}
129129
const contentLength = stats.size
@@ -164,7 +164,7 @@ async function handleStatic(filePath, range) {
164164
*/
165165
async function handleHead(filePath) {
166166
const stats = await fs.stat(filePath).catch(() => undefined)
167-
if (!stats || !stats.isFile()) {
167+
if (!stats?.isFile()) {
168168
console.error(`file not found ${filePath}`)
169169
return { status: 404, content: 'not found' }
170170
}
@@ -271,7 +271,7 @@ function startServer(port, path) {
271271
if (result.contentType) headers['Content-Type'] = result.contentType
272272
if (status === 301 && typeof content === 'string') {
273273
// handle redirect
274-
headers['Location'] = content
274+
headers.Location = content
275275
content = ''
276276
}
277277
// compress content

bin/streamConverters.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export async function pipe(input, output) {
2626
export function readStreamToReadableStream(fsStream) {
2727
return new ReadableStream({
2828
start(/** @type {ReadableStreamDefaultController} */ controller) {
29-
fsStream.on('data', (chunk) => controller.enqueue(chunk))
30-
fsStream.on('end', () => controller.close())
31-
fsStream.on('error', (error) => controller.error(error))
29+
fsStream.on('data', (chunk) => { controller.enqueue(chunk) })
30+
fsStream.on('end', () => { controller.close() })
31+
fsStream.on('error', (error) => { controller.error(error) })
3232
},
3333
cancel() {
3434
fsStream.destroy()

eslint.config.js

Lines changed: 55 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,22 @@ import react from 'eslint-plugin-react'
33
import reactHooks from 'eslint-plugin-react-hooks'
44
import reactRefresh from 'eslint-plugin-react-refresh'
55
import globals from 'globals'
6-
import tseslint from 'typescript-eslint'
6+
import typescript from 'typescript-eslint'
77

8-
/** @type {import('eslint').Linter.Config.RulesRecord} */
9-
const sharedJsRules = {
10-
'arrow-spacing': 'error',
11-
camelcase: 'off',
12-
'comma-spacing': 'error',
13-
'comma-dangle': ['error', 'always-multiline'],
14-
'eol-last': 'error',
15-
eqeqeq: 'error',
16-
'func-style': ['error', 'declaration'],
17-
indent: ['error', 2],
18-
'no-constant-condition': 'off',
19-
'no-extra-parens': 'error',
20-
'no-multi-spaces': 'error',
21-
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
22-
'no-trailing-spaces': 'error',
23-
'no-unused-vars': 'off',
24-
'no-useless-concat': 'error',
25-
'no-useless-rename': 'error',
26-
'no-useless-return': 'error',
27-
'no-var': 'error',
28-
'object-curly-spacing': ['error', 'always'],
29-
'prefer-const': 'warn',
30-
'prefer-destructuring': ['warn', {
31-
object: true,
32-
array: false,
33-
}],
34-
'prefer-promise-reject-errors': 'error',
35-
quotes: ['error', 'single'],
36-
'require-await': 'warn',
37-
semi: ['error', 'never'],
38-
39-
'sort-imports': ['error', {
40-
ignoreDeclarationSort: true,
41-
ignoreMemberSort: false,
42-
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
43-
}],
44-
45-
'space-infix-ops': 'error',
46-
}
47-
48-
/** @type {import('eslint').Linter.Config.RulesRecord} */
49-
const sharedTsRules = {
50-
'@typescript-eslint/restrict-template-expressions': 'off',
51-
'@typescript-eslint/no-unused-vars': 'warn',
52-
'@typescript-eslint/require-await': 'warn',
53-
}
54-
55-
export default tseslint.config(
56-
{ ignores: ['coverage/', 'dist/', 'lib/', 'packages/'] },
8+
export default typescript.config(
9+
{ ignores: ['coverage/', 'dist/', 'lib/'] },
5710
{
58-
settings: { react: { version: '18.3' } },
59-
extends: [javascript.configs.recommended, ...tseslint.configs.strictTypeChecked, ...tseslint.configs.stylisticTypeChecked],
11+
extends: [javascript.configs.recommended, ...typescript.configs.strictTypeChecked, ...typescript.configs.stylisticTypeChecked],
6012
files: ['**/*.{ts,tsx,js}'],
6113
languageOptions: {
62-
ecmaVersion: 2020,
6314
globals: globals.browser,
6415
parserOptions: {
6516
project: ['./tsconfig.json', './tsconfig.eslint.json'],
6617
tsconfigRootDir: import.meta.dirname,
6718
},
6819
},
6920
plugins: {
70-
'react': react,
21+
react,
7122
'react-hooks': reactHooks,
7223
'react-refresh': reactRefresh,
7324
},
@@ -80,11 +31,55 @@ export default tseslint.config(
8031
{ allowConstantExport: true },
8132
],
8233
...javascript.configs.recommended.rules,
83-
...tseslint.configs.recommended.rules,
84-
...sharedJsRules,
85-
...sharedTsRules,
86-
'no-extra-parens': 'warn',
34+
...typescript.configs.recommended.rules,
35+
// javascript
36+
'arrow-spacing': 'error',
37+
camelcase: 'off',
38+
'comma-spacing': 'error',
39+
'comma-dangle': ['error', {
40+
arrays: 'always-multiline',
41+
objects: 'always-multiline',
42+
imports: 'always-multiline',
43+
exports: 'always-multiline',
44+
functions: 'never',
45+
}],
46+
'eol-last': 'error',
47+
eqeqeq: 'error',
48+
'func-style': ['error', 'declaration'],
49+
indent: ['error', 2],
50+
'no-constant-condition': 'off',
51+
'no-extra-parens': 'error',
52+
'no-multi-spaces': 'error',
53+
'no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
54+
'no-trailing-spaces': 'error',
55+
// 'no-undef': 'error',
56+
'no-unused-vars': 'off',
57+
'no-useless-concat': 'error',
58+
'no-useless-rename': 'error',
59+
'no-useless-return': 'error',
60+
'no-var': 'error',
61+
'object-curly-spacing': ['error', 'always'],
62+
'prefer-const': 'warn',
63+
'prefer-destructuring': ['warn', {
64+
object: true,
65+
array: false,
66+
}],
67+
'prefer-promise-reject-errors': 'error',
68+
quotes: ['error', 'single'],
69+
'require-await': 'warn',
70+
semi: ['error', 'never'],
71+
'sort-imports': ['error', {
72+
ignoreDeclarationSort: true,
73+
ignoreMemberSort: false,
74+
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
75+
}],
76+
'space-infix-ops': 'error',
77+
// typescript
78+
'@typescript-eslint/restrict-template-expressions': 'off',
79+
'@typescript-eslint/no-unused-vars': 'warn',
80+
'@typescript-eslint/require-await': 'warn',
8781
},
82+
settings: { react: { version: 'detect' } },
8883
},
8984
{
9085
files: ['test/**/*.{ts,tsx}', '*.{js,ts}'],
@@ -98,7 +93,7 @@ export default tseslint.config(
9893
},
9994
{
10095
files: ['**/*.js'],
101-
...tseslint.configs.disableTypeChecked,
96+
...typescript.configs.disableTypeChecked,
10297
},
10398
{
10499
files: ['bin/**/*.js', 'test/bin/**/*.js'],
@@ -107,5 +102,5 @@ export default tseslint.config(
107102
...globals.node,
108103
},
109104
},
110-
},
105+
}
111106
)

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
],
2929
"scripts": {
3030
"build:types": "tsc -b",
31-
"build:lib": "vite build -c vite.lib.config.ts",
32-
"build:app": "vite build -c vite.app.config.ts",
31+
"build:lib": "vite build -c vite.lib.config.js",
32+
"build:app": "vite build -c vite.app.config.js",
3333
"build": "run-s build:lib build:types build:app",
34-
"coverage": "vitest run -c vite.lib.config.ts --coverage --coverage.include=src --coverage.include=bin",
34+
"coverage": "vitest run -c vite.lib.config.js --coverage --coverage.include=src --coverage.include=bin",
3535
"dev": "run-p -l watch:ts watch:vite watch:serve",
3636
"lint": "eslint .",
3737
"prepublishOnly": "npm run build",
3838
"serve": "node bin/cli.js",
3939
"preserve": "npm run build",
40-
"test": "vitest run -c vite.lib.config.ts",
40+
"test": "vitest run -c vite.lib.config.js",
4141
"typecheck": "tsc --noEmit",
4242
"url": "run-p -l watch:ts watch:vite watch:url",
4343
"watch:ts": "tsc --watch",

src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ if (!root) throw new Error('missing root element')
99
createRoot(root).render(
1010
<StrictMode>
1111
<App />
12-
</StrictMode>,
12+
</StrictMode>
1313
)

src/components/Breadcrumb.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function Breadcrumb({ source, config, children }: BreadcrumbProps
1616
return <nav className='top-header top-header-divided'>
1717
<div className='path'>
1818
{source.sourceParts.map((part, depth) =>
19-
<a href={config?.routes?.getSourceRouteUrl?.({ sourceId: part.sourceId }) ?? ''} key={depth}>{part.text}</a>,
19+
<a href={config?.routes?.getSourceRouteUrl?.({ sourceId: part.sourceId }) ?? ''} key={depth}>{part.text}</a>
2020
)}
2121
</div>
2222
{children}

src/components/Folder.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export default function Folder({ source, config }: FolderProps) {
105105
</span>
106106
</>}
107107
</a>
108-
</li>,
108+
</li>
109109
)}
110110
</ul>}
111111
{files?.length === 0 && <div className='center'>No files</div>}

src/components/Json.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function JsonObject({ obj, label }: { obj: object, label?: string }): ReactNode
7575
{Object.entries(obj).map(([key, value]) =>
7676
<li key={key}>
7777
<Json json={value as unknown} label={key} />
78-
</li>,
78+
</li>
7979
)}
8080
</ul>
8181
<div className={styles.object}>{'}'}</div>

src/components/Markdown.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default function Markdown({ text, className }: MarkdownProps) {
2828
function applyRegex(
2929
currentText: ReactNode[],
3030
regex: RegExp,
31-
renderFn: (match: RegExpExecArray) => ReactNode,
31+
renderFn: (match: RegExpExecArray) => ReactNode
3232
) {
3333
const newResult: ReactNode[] = []
3434
for (const segment of currentText) {

0 commit comments

Comments
 (0)