Skip to content

Commit e5a077c

Browse files
committed
✨ Add a search bar to docs
Also updated ESLint and improved config (sorry not sorry that I did it all in one commit 😈)
1 parent e827cbc commit e5a077c

File tree

8 files changed

+993
-269
lines changed

8 files changed

+993
-269
lines changed

eslint.config.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

eslint.config.ts

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
import svelteEslint from 'eslint-plugin-svelte'
2+
import svelteParser from 'svelte-eslint-parser'
3+
import tsESLint, { type ConfigWithExtends } from 'typescript-eslint'
4+
import svelteConfig from './svelte.config'
5+
import type { NamingConventionRule } from './tslintNamingConventionRule'
6+
7+
console.log(`[${new Date().toLocaleTimeString()}] Loading ESLint config`)
8+
9+
const IGNORE_PATTERNS = [
10+
'.DS_Store',
11+
'.env',
12+
'.env.*',
13+
'.github',
14+
'.vscode',
15+
'**/node_modules/**',
16+
17+
// Blockbench Plugin Template
18+
'dist/**/*',
19+
20+
// Ignore files for PNPM, NPM and YARN
21+
'pnpm-lock.yaml',
22+
'package-lock.json',
23+
'yarn.lock'
24+
]
25+
26+
const CUSTOM_RULES: ConfigWithExtends['rules'] = {
27+
// ESLint
28+
semi: ['error', 'never'],
29+
'prefer-const': 'warn',
30+
'no-fallthrough': 'off',
31+
'no-mixed-spaces-and-tabs': 'off',
32+
'no-unreachable': 'warn',
33+
'@typescript-eslint/no-unused-vars': [
34+
'warn',
35+
{
36+
vars: 'local',
37+
args: 'after-used',
38+
argsIgnorePattern: '^_',
39+
ignoreRestSiblings: true
40+
}
41+
],
42+
// Svelte
43+
'svelte/html-quotes': ['warn', { prefer: 'double' }],
44+
'svelte/block-lang': ['error', { script: ['ts', null], style: null }],
45+
'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }],
46+
// Check File
47+
'check-file/filename-naming-convention': [
48+
'error',
49+
{
50+
'src/**/*.{ts.d.ts}': 'CAMEL_CASE',
51+
'tools/**/*.{ts.d.ts}': 'CAMEL_CASE'
52+
}
53+
],
54+
'check-file/folder-naming-convention': [
55+
'error',
56+
{
57+
'src/**': 'KEBAB_CASE',
58+
'tools/**': 'KEBAB_CASE'
59+
}
60+
],
61+
// TypeScript
62+
'@typescript-eslint/no-explicit-any': 'off',
63+
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
64+
'@typescript-eslint/array-type': ['warn', { default: 'array-simple' }],
65+
'@typescript-eslint/consistent-indexed-object-style': ['warn', 'record'],
66+
'@typescript-eslint/consistent-generic-constructors': 'warn',
67+
'@typescript-eslint/no-namespace': 'off',
68+
'@typescript-eslint/restrict-template-expressions': 'off',
69+
'@typescript-eslint/no-unsafe-member-access': 'off',
70+
'@typescript-eslint/no-unsafe-assignment': 'off',
71+
'@typescript-eslint/ban-ts-comment': 'off',
72+
'@typescript-eslint/require-await': 'warn',
73+
'@typescript-eslint/no-unsafe-call': 'off',
74+
'@typescript-eslint/unbound-method': 'off',
75+
'@typescript-eslint/no-non-null-assertion': 'off',
76+
'@typescript-eslint/triple-slash-reference': 'off',
77+
// Naming conventions
78+
'@typescript-eslint/naming-convention': [
79+
'warn',
80+
{
81+
// DFU Version imports
82+
selector: ['import'],
83+
modifiers: ['default'],
84+
filter: {
85+
regex: 'v\\d+_\\d+_\\d+$',
86+
match: true
87+
},
88+
custom: {
89+
match: true,
90+
regex: 'v\\d+_\\d+_\\d+$'
91+
},
92+
format: null
93+
},
94+
{
95+
selector: ['import'],
96+
modifiers: ['default'],
97+
format: ['camelCase', 'PascalCase', 'UPPER_CASE']
98+
},
99+
{
100+
selector: 'class',
101+
format: ['PascalCase']
102+
},
103+
{
104+
selector: ['classProperty', 'classMethod'],
105+
format: ['camelCase']
106+
},
107+
{
108+
selector: ['classProperty', 'classMethod'],
109+
leadingUnderscore: 'allow',
110+
format: ['camelCase']
111+
},
112+
{
113+
selector: ['classProperty', 'classMethod'],
114+
modifiers: ['private'],
115+
leadingUnderscore: 'allowDouble',
116+
trailingUnderscore: 'allowDouble',
117+
format: ['camelCase']
118+
},
119+
{
120+
selector: 'typeProperty',
121+
format: null
122+
},
123+
{
124+
selector: 'variable',
125+
modifiers: ['const', 'destructured'],
126+
format: null
127+
},
128+
{
129+
selector: 'variable',
130+
modifiers: ['const', 'global'],
131+
types: ['function'],
132+
leadingUnderscore: 'allow',
133+
format: ['UPPER_CASE', 'camelCase']
134+
},
135+
{
136+
selector: 'variable',
137+
modifiers: ['const', 'global'],
138+
leadingUnderscore: 'allow',
139+
format: ['UPPER_CASE']
140+
},
141+
{
142+
selector: 'variable',
143+
modifiers: ['const', 'exported'],
144+
format: ['camelCase', 'UPPER_CASE']
145+
},
146+
{
147+
selector: 'variableLike',
148+
format: ['camelCase']
149+
},
150+
{ selector: 'interface', format: ['PascalCase'] },
151+
{
152+
selector: 'interface',
153+
modifiers: ['exported'],
154+
format: ['PascalCase'],
155+
prefix: ['I']
156+
},
157+
{ selector: 'typeLike', format: ['PascalCase'] },
158+
{ selector: 'objectLiteralProperty', format: null },
159+
{ selector: 'default', format: ['camelCase'] },
160+
{
161+
selector: 'parameter',
162+
modifiers: ['unused'],
163+
format: ['camelCase'],
164+
leadingUnderscore: 'allow'
165+
},
166+
{
167+
selector: 'parameter',
168+
format: ['camelCase']
169+
},
170+
{
171+
selector: 'enumMember',
172+
format: ['camelCase', 'PascalCase', 'UPPER_CASE']
173+
},
174+
{
175+
selector: 'enum',
176+
format: ['UPPER_CASE']
177+
}
178+
] satisfies NamingConventionRule
179+
}
180+
181+
export default tsESLint.config(
182+
{
183+
ignores: IGNORE_PATTERNS
184+
},
185+
...tsESLint.configs.stylisticTypeChecked,
186+
...svelteEslint.configs['flat/prettier'],
187+
{
188+
plugins: {
189+
'@typescript-eslint': tsESLint.plugin,
190+
svelte: svelteEslint
191+
}
192+
},
193+
{
194+
rules: CUSTOM_RULES
195+
},
196+
{
197+
languageOptions: {
198+
parser: tsESLint.parser,
199+
parserOptions: {
200+
project: './tsconfig.json',
201+
extraFileExtensions: ['.svelte']
202+
},
203+
globals: {
204+
browser: true,
205+
node: true
206+
}
207+
}
208+
},
209+
{
210+
files: ['**/*.svelte'],
211+
rules: {
212+
// Causes issues with Svelte and global types
213+
'no-undef': 'off',
214+
'@typescript-eslint/naming-convention': [
215+
'warn',
216+
{
217+
selector: 'variable',
218+
modifiers: ['exported'],
219+
format: ['camelCase']
220+
},
221+
{
222+
selector: 'variable',
223+
modifiers: ['const', 'global'],
224+
format: ['UPPER_CASE']
225+
},
226+
{
227+
selector: 'variable',
228+
modifiers: ['const', 'global'],
229+
types: ['function'],
230+
format: ['camelCase']
231+
},
232+
{
233+
selector: 'variable',
234+
format: ['camelCase'],
235+
leadingUnderscore: 'allow'
236+
}
237+
] satisfies NamingConventionRule
238+
},
239+
languageOptions: {
240+
parser: svelteParser,
241+
parserOptions: {
242+
parser: tsESLint.parser,
243+
svelteConfig: svelteConfig,
244+
extraFileExtensions: ['.svelte']
245+
},
246+
globals: {
247+
browser: true,
248+
node: true
249+
}
250+
},
251+
settings: {
252+
ignoreWarnings: ['svelte/a11y-no-onchange', 'a11y-no-onchange']
253+
}
254+
},
255+
{
256+
languageOptions: {
257+
parserOptions: {
258+
projectService: true,
259+
tsconfigRootDir: '.'
260+
}
261+
},
262+
linterOptions: {
263+
reportUnusedDisableDirectives: true
264+
}
265+
}
266+
)

package.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
"format": "prettier --write ."
1313
},
1414
"devDependencies": {
15+
"@algolia/client-search": "^5.20.3",
16+
"@docsearch/css": "^3.9.0",
17+
"@docsearch/js": "^3.9.0",
1518
"@iconify-json/ri": "^1.0.0",
1619
"@iconify/json": "^2.2.219",
1720
"@sveltejs/adapter-auto": "^3.0.0",
@@ -20,24 +23,30 @@
2023
"@sveltejs/vite-plugin-svelte": "^3.0.0",
2124
"@svelteness/kit-docs": "^1.1.5",
2225
"@types/eslint": "^8.56.7",
26+
"@types/react": "^19.0.10",
2327
"clsx": "^1.0.0",
24-
"eslint": "^9.0.0",
28+
"eslint": "^9.21.0",
2529
"eslint-config-prettier": "^9.1.0",
26-
"eslint-plugin-svelte": "^2.36.0",
30+
"eslint-plugin-svelte": "^3.0.2",
2731
"globals": "^15.0.0",
32+
"jiti": "^2.4.2",
2833
"prettier": "^3.1.1",
2934
"prettier-plugin-svelte": "^3.1.2",
35+
"react": "^19.0.0",
36+
"react-dom": "^19.0.0",
3037
"shiki": "^0.12.0",
3138
"svelte": "^4.2.7",
3239
"svelte-check": "^3.6.0",
40+
"svelte-eslint-parser": "^1.0.0",
3341
"tslib": "^2.4.1",
3442
"typescript": "^5.0.0",
35-
"typescript-eslint": "^8.0.0-alpha.20",
43+
"typescript-eslint": "^8.25.0",
3644
"unplugin-icons": "^0.19.0",
3745
"vite": "^5.0.3"
3846
},
3947
"type": "module",
4048
"dependencies": {
4149
"svelte-youtube-embed": "^0.3.0"
42-
}
50+
},
51+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
4352
}

src/lib/styles/kit-docs.css

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
:root,
22
.prefers-light-scheme {
33
--kd-color-brand: 0 172 237;
4-
--kd-color-focus: 79 70 229;
4+
--kd-color-focus: 0 172 237 !important;
55
--kd-color-soft: 68 78 94;
66
--kd-color-body: 250 250 250;
77
--kd-color-elevate: 243 244 246;
88
--kd-color-inverse: 5 11 23;
99
--kd-color-border: 209 213 219;
1010

11+
--kd-color-subtle: rgb(181 186 199);
12+
1113
--kd-code-fence-bg: rgb(212 217 251);
1214
--kd-code-fence-fg: rgb(26, 29, 36);
1315
}

src/routes/+layout.svelte

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<script lang="ts">
2+
import '@docsearch/css' // Must come first.
3+
import '@svelteness/kit-docs/client/styles/docsearch.css'
4+
25
import '@svelteness/kit-docs/client/polyfills/index.js'
36
import '@svelteness/kit-docs/client/styles/normalize.css'
47
import '@svelteness/kit-docs/client/styles/fonts.css'
58
import '@svelteness/kit-docs/client/styles/theme.css'
69
import '$lib/styles/kit-docs.css'
710
11+
import { Algolia } from '@svelteness/kit-docs/client/algolia'
12+
813
import { page } from '$app/stores'
914
1015
import DiscordIcon from '~icons/ri/discord-fill'
@@ -60,7 +65,16 @@
6065
</svelte:head>
6166

6267
<KitDocs {meta}>
63-
<KitDocsLayout {navbar} {sidebar}>
68+
<KitDocsLayout {navbar} {sidebar} search>
69+
<!-- FIXME - Add actual Animated Java site's API keys (These are placeholders from the Algolia docs) -->
70+
<Algolia
71+
apiKey="599cec31baffa4868cae4e79f180729b"
72+
appId="R2IYF7ETH7"
73+
indexName="docsearch"
74+
placeholder="Search the Docs..."
75+
slot="search"
76+
/>
77+
6478
<div class="logo" slot="navbar-left">
6579
<Button href="/">
6680
<div class="header-container">

0 commit comments

Comments
 (0)