Skip to content

Commit 34bfd13

Browse files
fix: lint
1 parent 8e53ee5 commit 34bfd13

File tree

11 files changed

+63
-94
lines changed

11 files changed

+63
-94
lines changed

adapters/docusaurus-theme-search-algolia/scripts/copy-assets.mjs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,20 @@ function watchAssets() {
5050

5151
copyAssetsOnce();
5252

53-
fs.watch(
54-
srcRoot,
55-
{ recursive: true },
56-
(_eventType, filename) => {
57-
if (!filename) {
58-
return;
59-
}
60-
const filePath = path.join(srcRoot, filename);
61-
const extension = path.extname(filePath);
62-
if (IGNORED_EXTENSIONS.has(extension) || !ASSET_EXTENSIONS.has(extension)) {
63-
return;
64-
}
65-
if (!fs.existsSync(filePath)) {
66-
return;
67-
}
68-
copyAssetFile(filePath);
69-
},
70-
);
53+
fs.watch(srcRoot, { recursive: true }, (_eventType, filename) => {
54+
if (!filename) {
55+
return;
56+
}
57+
const filePath = path.join(srcRoot, filename);
58+
const extension = path.extname(filePath);
59+
if (IGNORED_EXTENSIONS.has(extension) || !ASSET_EXTENSIONS.has(extension)) {
60+
return;
61+
}
62+
if (!fs.existsSync(filePath)) {
63+
return;
64+
}
65+
copyAssetFile(filePath);
66+
});
7167
}
7268

7369
if (process.argv.includes(WATCH_FLAG)) {

adapters/docusaurus-theme-search-algolia/scripts/format-theme.mjs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { execSync } from 'node:child_process';
2-
import { existsSync } from 'node:fs';
2+
33
import { glob } from 'glob';
44

55
const pattern = 'lib/theme/**/*.js';
@@ -11,7 +11,6 @@ if (files.length > 0) {
1111
stdio: 'inherit',
1212
});
1313
} catch (error) {
14-
console.error('Prettier failed:', error.message);
15-
process.exit(1);
14+
throw new Error(`Prettier failed: ${error instanceof Error ? error.message : String(error)}`);
1615
}
1716
}

adapters/docusaurus-theme-search-algolia/src/client/useAlgoliaAskAi.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {useCallback, useMemo, useState} from 'react';
8+
import type { AskAiConfig } from '@docsearch/docusaurus-adapter';
9+
import type { DocSearchModalProps, DocSearchTranslations } from '@docsearch/react';
910
import translations from '@theme/SearchTranslations';
10-
import {useAlgoliaContextualFacetFiltersIfEnabled} from './useAlgoliaContextualFacetFilters';
11-
import {mergeFacetFilters} from './utils';
12-
import type {AskAiConfig} from '@docsearch/docusaurus-adapter';
13-
import type {
14-
DocSearchModalProps,
15-
DocSearchTranslations,
16-
} from '@docsearch/react';
17-
import type {FacetFilters} from 'algoliasearch/lite';
11+
import type { FacetFilters } from 'algoliasearch/lite';
12+
import { useCallback, useMemo, useState } from 'react';
13+
14+
import { useAlgoliaContextualFacetFiltersIfEnabled } from './useAlgoliaContextualFacetFilters';
15+
import { mergeFacetFilters } from './utils';
1816

1917
// The minimal props the hook needs from DocSearch
2018
interface DocSearchPropsLite {
@@ -67,10 +65,7 @@ function applyAskAiContextualSearch(
6765
...askAi,
6866
searchParameters: {
6967
...askAi.searchParameters,
70-
facetFilters: mergeFacetFilters(
71-
askAiFacetFilters,
72-
contextualSearchFilters,
73-
),
68+
facetFilters: mergeFacetFilters(askAiFacetFilters, contextualSearchFilters),
7469
},
7570
};
7671
}
@@ -83,13 +78,11 @@ export function useAlgoliaAskAi(props: DocSearchPropsLite): UseAskAiResult {
8378
return applyAskAiContextualSearch(props.askAi, contextualSearchFilters);
8479
}, [props.askAi, contextualSearchFilters]);
8580

86-
const askAiWithoutSidePanel = useMemo<
87-
AskAiConfigWithoutSidePanel | undefined
88-
>(() => {
81+
const askAiWithoutSidePanel = useMemo<AskAiConfigWithoutSidePanel | undefined>(() => {
8982
if (!askAi) {
9083
return undefined;
9184
}
92-
const {sidePanel: _sidePanel, ...docsearchAskAi} = askAi;
85+
const { sidePanel: _sidePanel, ...docsearchAskAi } = askAi;
9386
return docsearchAskAi;
9487
}, [askAi]);
9588

adapters/docusaurus-theme-search-algolia/src/client/useAlgoliaAskAiSidepanel.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {useCallback, useMemo, useRef, useState} from 'react';
9-
import type {AskAiConfig} from '@docsearch/docusaurus-adapter';
8+
import type { AskAiConfig } from '@docsearch/docusaurus-adapter';
9+
import { useCallback, useMemo, useRef, useState } from 'react';
1010

1111
type AskAiTogglePayload = {
1212
query: string;
@@ -41,17 +41,13 @@ export function useAlgoliaAskAiSidepanel({
4141
importSidepanel,
4242
}: UseAlgoliaAskAiSidepanelParams): UseAlgoliaAskAiSidepanelResult {
4343
const [isSidepanelOpen, setIsSidepanelOpen] = useState(false);
44-
const [sidepanelInitialMessage, setSidepanelInitialMessage] = useState<
45-
AskAiTogglePayload | undefined
46-
>(undefined);
44+
const [sidepanelInitialMessage, setSidepanelInitialMessage] = useState<AskAiTogglePayload | undefined>(undefined);
4745
const openRequestId = useRef(0);
4846

4947
const sidePanelConfig = askAiConfig?.sidePanel;
5048
const sidePanelEnabled = Boolean(sidePanelConfig);
51-
const sidePanelOptions =
52-
typeof sidePanelConfig === 'object' ? sidePanelConfig : undefined;
53-
const showSidepanelButton =
54-
sidePanelEnabled && sidePanelOptions?.hideButton !== true;
49+
const sidePanelOptions = typeof sidePanelConfig === 'object' ? sidePanelConfig : undefined;
50+
const showSidepanelButton = sidePanelEnabled && sidePanelOptions?.hideButton !== true;
5551
const sidePanelAgentStudio = askAiConfig?.agentStudio ?? false;
5652

5753
const sidepanelPortalContainer = useMemo(() => {
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
@@ -9,13 +9,11 @@ declare module '@docsearch/react/modal';
99
declare module '@docsearch/react/style';
1010
declare module '@docsearch/react/style/sidepanel';
1111

12-
13-
// TODO incompatible declaration file
1412
declare module 'eta' {
15-
export const defaultConfig: object;
13+
export const defaultConfig: Record<string, unknown>;
1614

1715
export function compile(
1816
template: string,
19-
options?: object,
20-
): (data: object, config: object) => string;
17+
options?: Record<string, unknown>,
18+
): (data: Record<string, unknown>, config: Record<string, unknown>) => string;
2119
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
import {version as docSearchVersion} from '@docsearch/react';
8+
import { version as docSearchVersion } from '@docsearch/react';
99

1010
export const docSearchVersionString = docSearchVersion;

adapters/docusaurus-theme-search-algolia/src/theme-search-algolia.d.ts

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

88
declare module '@docsearch/docusaurus-adapter' {
9-
import type {DeepPartial, Overwrite, Optional} from 'utility-types';
10-
11-
import type {DocSearchProps} from '@docsearch/react';
12-
import type {SidepanelProps} from '@docsearch/react/sidepanel';
13-
import type {FacetFilters} from 'algoliasearch/lite';
9+
import type { DocSearchProps } from '@docsearch/react';
10+
import type { SidepanelProps } from '@docsearch/react/sidepanel';
11+
import type { FacetFilters } from 'algoliasearch/lite';
12+
import type { DeepPartial, Overwrite, Optional } from 'utility-types';
1413

1514
type AskAiSearchParameters = {
1615
facetFilters?: FacetFilters;
@@ -20,10 +19,7 @@ declare module '@docsearch/docusaurus-adapter' {
2019
distinct?: boolean | number | string;
2120
};
2221

23-
type AgentStudioSearchParameters = Record<
24-
string,
25-
Omit<AskAiSearchParameters, 'facetFilters'>
26-
>;
22+
type AgentStudioSearchParameters = Record<string, Omit<AskAiSearchParameters, 'facetFilters'>>;
2723

2824
// The config after normalization (e.g. AskAI string -> object)
2925
// This matches DocSearch v4.3+ AskAi configuration
@@ -34,12 +30,8 @@ declare module '@docsearch/docusaurus-adapter' {
3430
assistantId: string;
3531
suggestedQuestions?: boolean;
3632
useStagingEnv?: boolean;
37-
sidePanel?: boolean | (SidepanelProps & {hideButton?: boolean});
33+
sidePanel?: boolean | (SidepanelProps & { hideButton?: boolean });
3834
} & (
39-
| {
40-
agentStudio?: never;
41-
searchParameters?: AskAiSearchParameters;
42-
}
4335
| {
4436
agentStudio: false;
4537
searchParameters?: AskAiSearchParameters;
@@ -48,19 +40,16 @@ declare module '@docsearch/docusaurus-adapter' {
4840
agentStudio: true;
4941
searchParameters?: AgentStudioSearchParameters;
5042
}
43+
| {
44+
agentStudio?: never;
45+
searchParameters?: AskAiSearchParameters;
46+
}
5147
);
5248

5349
// DocSearch props that Docusaurus exposes directly through props forwarding
5450
type DocusaurusDocSearchProps = Pick<
5551
DocSearchProps,
56-
| 'appId'
57-
| 'apiKey'
58-
| 'indexName'
59-
| 'placeholder'
60-
| 'translations'
61-
| 'searchParameters'
62-
| 'insights'
63-
| 'initialQuery'
52+
'apiKey' | 'appId' | 'indexName' | 'initialQuery' | 'insights' | 'placeholder' | 'searchParameters' | 'translations'
6453
> & {
6554
// Docusaurus normalizes the AskAI config to an object
6655
askAi?: AskAiConfig;
@@ -87,9 +76,7 @@ declare module '@docsearch/docusaurus-adapter' {
8776
apiKey: ThemeConfigAlgolia['apiKey'];
8877
indexName: ThemeConfigAlgolia['indexName'];
8978
// askAi also accepts a shorter string form
90-
askAi?:
91-
| string
92-
| Optional<AskAiConfig, 'indexName' | 'appId' | 'apiKey'>;
79+
askAi?: Optional<AskAiConfig, 'apiKey' | 'appId' | 'indexName'> | string;
9380
}
9481
>;
9582

@@ -109,19 +96,19 @@ declare module '@docsearch/docusaurus-adapter' {
10996
}
11097

11198
declare module '@theme/SearchPage' {
112-
import type {ReactNode} from 'react';
99+
import type { ReactNode } from 'react';
113100

114101
export default function SearchPage(): ReactNode;
115102
}
116103

117104
declare module '@theme/SearchBar' {
118-
import type {ReactNode} from 'react';
105+
import type { ReactNode } from 'react';
119106

120107
export default function SearchBar(): ReactNode;
121108
}
122109

123110
declare module '@theme/SearchTranslations' {
124-
import type {DocSearchTranslations} from '@docsearch/react';
111+
import type { DocSearchTranslations } from '@docsearch/react';
125112

126113
const translations: DocSearchTranslations & {
127114
placeholder: string;

adapters/docusaurus-theme-search-algolia/src/types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.

adapters/docusaurus-theme-search-algolia/src/utils/escapeRegexp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Copyright (c) Facebook, Inc. and its affiliates.
2+
* Copyright (c) Facebook, Inc. And its affiliates.
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
export {normalizeUrl} from './normalizeUrl';
9-
export {escapeRegexp} from './escapeRegexp';
8+
export { normalizeUrl } from './normalizeUrl';
9+
export { escapeRegexp } from './escapeRegexp';

0 commit comments

Comments
 (0)