Skip to content

Commit 992d04b

Browse files
chore: configure eslint-jsdoc-plugin (#883)
## Description This PR configures eslint-jsdoc-plugin so: - JSDocs are consistent throughout codebase and jsdocs are consistent with method/interface signature - there is defined set of `@category` tag values to prevent typos and generating additional sections in docs - fixed few jsdocs manually ### Introduces a breaking change? - [ ] Yes - [x] No ### Type of change - [ ] Bug fix (change which fixes an issue) - [ ] New feature (change which adds functionality) - [ ] Documentation update (improves or adds clarity to existing documentation) - [x] Other (chores, tests, code style improvements etc.) ### Tested on - [ ] iOS - [ ] Android ### Testing instructions - try to break some jsdocs (e. g. remove `@returns` tag, set `@category` to some value outside of values defined in `eslintrc.js`, change `@param` tag so it does not match signature) and see if eslint catches these errors. - build and open docs locally and check out if api reference is valid ### Screenshots <!-- Add screenshots here, if applicable --> ### Related issues #831 ### Checklist - [x] I have performed a self-review of my code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have updated the documentation accordingly - [x] My changes generate no new warnings ### Additional notes **NOTE:** for now I switched off required destructured params as that's the convention we are mostly using, but we could move to destructured params eventually. --------- Co-authored-by: Mateusz Słuszniak <mateusz.sluszniak@swmansion.com> Co-authored-by: Mateusz Sluszniak <56299341+msluszniak@users.noreply.github.com>
1 parent 6c1dea0 commit 992d04b

File tree

79 files changed

+301
-407
lines changed

Some content is hidden

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

79 files changed

+301
-407
lines changed

.cspell-wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,4 @@ nˈɛvəɹ
179179
ɹˈiᵊli
180180
ˈɛniwˌʌn
181181
ˈɛls
182+
Synchronizable

.eslintrc.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
11
const path = require('path');
22

3+
const VALID_CATEGORIES = [
4+
'Base Classes',
5+
'Hooks',
6+
'Interfaces',
7+
'Models - Classification',
8+
'Models - Image Embeddings',
9+
'Models - Image Generation',
10+
'Models - LMM',
11+
'Models - Object Detection',
12+
'Models - Instance Segmentation',
13+
'Models - Semantic Segmentation',
14+
'Models - Speech To Text',
15+
'Models - Style Transfer',
16+
'Models - Text Embeddings',
17+
'Models - Text to Speech',
18+
'Models - VLM',
19+
'Models - Voice Activity Detection',
20+
'OCR Supported Alphabets',
21+
'TTS Supported Voices',
22+
'Types',
23+
'Typescript API',
24+
'Utils',
25+
'Utilities - General',
26+
'Utilities - LLM',
27+
];
28+
29+
const CATEGORY_TAG_MATCH = `^(${VALID_CATEGORIES.join('|')})$`;
30+
331
module.exports = {
432
parserOptions: {
533
requireConfigFile: false,
@@ -13,6 +41,7 @@ module.exports = {
1341
'plugin:@cspell/recommended',
1442
'plugin:prettier/recommended',
1543
'plugin:markdown/recommended-legacy',
44+
'plugin:jsdoc/recommended-typescript',
1645
],
1746
rules: {
1847
'react/react-in-jsx-scope': 'off',
@@ -33,8 +62,28 @@ module.exports = {
3362
},
3463
],
3564
'camelcase': 'error',
65+
'jsdoc/require-jsdoc': 'off',
66+
'jsdoc/require-param': ['error', { checkDestructured: false }],
67+
'jsdoc/check-param-names': ['error', { checkDestructured: false }],
68+
'jsdoc/require-yields-type': 'off',
69+
'jsdoc/require-yields-description': 'warn',
70+
'jsdoc/check-tag-names': ['error', { definedTags: ['property'] }],
71+
'jsdoc/match-description': [
72+
'error',
73+
{
74+
contexts: ['any'],
75+
mainDescription: false,
76+
tags: {
77+
category: {
78+
message:
79+
'@category must be one of categories defined in .eslintrc.js',
80+
match: CATEGORY_TAG_MATCH,
81+
},
82+
},
83+
},
84+
],
3685
},
37-
plugins: ['prettier', 'markdown'],
86+
plugins: ['prettier', 'markdown', 'jsdoc'],
3887
overrides: [
3988
{
4089
files: ['packages/react-native-executorch/src/**/*.{js,jsx,ts,tsx}'],
@@ -58,4 +107,11 @@ module.exports = {
58107
},
59108
],
60109
ignorePatterns: ['node_modules/', 'lib/'],
110+
settings: {
111+
jsdoc: {
112+
tagNamePreference: {
113+
typeParam: 'typeParam',
114+
},
115+
},
116+
},
61117
};

apps/computer-vision/components/ImageWithMasks.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface DisplayInstance {
3838
* Convert raw segmentation output into lightweight display instances.
3939
* Call this eagerly (in the forward callback) so raw Uint8Array masks
4040
* can be garbage-collected immediately.
41+
* @param rawInstances - Array of raw segmentation instances with mask buffers to convert.
42+
* @returns Array of lightweight {@link DisplayInstance} objects with pre-rendered Skia images.
4143
*/
4244
export function buildDisplayInstances(
4345
rawInstances: {

apps/speech/screens/TextToSpeechLLMScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ interface TextToSpeechLLMProps {
3030
/**
3131
* Converts an audio vector (Float32Array) to an AudioBuffer for playback
3232
* @param audioVector - The generated audio samples from the model
33+
* @param audioContext - The audio context used to create the buffer.
3334
* @param sampleRate - The sample rate (default: 24000 Hz for Kokoro)
3435
* @returns AudioBuffer ready for playback
3536
*/

apps/speech/screens/TextToSpeechScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import SWMIcon from '../assets/swm_icon.svg';
5353
/**
5454
* Converts an audio vector (Float32Array) to an AudioBuffer for playback
5555
* @param audioVector - The generated audio samples from the model
56+
* @param audioContext - An optional AudioContext to create the buffer in. If not provided, a new one will be created.
5657
* @param sampleRate - The sample rate (default: 24000 Hz for Kokoro)
5758
* @returns AudioBuffer ready for playback
5859
*/

docs/docs/03-hooks/02-computer-vision/visioncamera-integration.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,17 @@ export default function App() {
184184
const frameOutput = useFrameOutput({
185185
pixelFormat: 'rgb',
186186
dropFramesWhileBusy: true,
187-
onFrame: useCallback(
188-
(frame: Frame) => {
189-
'worklet';
190-
try {
191-
if (!runOnFrame) return;
192-
const isFrontCamera = cameraPositionSync.getDirty() === 'front';
193-
const result = runOnFrame(frame, isFrontCamera);
194-
// ... handle result
195-
} finally {
196-
frame.dispose();
197-
}
198-
},
199-
[runOnFrame]
200-
),
187+
onFrame: useCallback((frame: Frame) => {
188+
'worklet';
189+
try {
190+
if (!runOnFrame) return;
191+
const isFrontCamera = cameraPositionSync.getDirty() === 'front';
192+
const result = runOnFrame(frame, isFrontCamera);
193+
// ... handle result
194+
} finally {
195+
frame.dispose();
196+
}
197+
}, []),
201198
});
202199

203200
// ...

docs/docusaurus.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const config = {
1818
projectName: 'react-native-executorch',
1919

2020
onBrokenLinks: 'throw',
21+
onBrokenAnchors: 'throw',
2122
markdown: {
2223
hooks: {
2324
onBrokenMarkdownLinks: 'warn',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"cspell": "^8.19.0",
2323
"eslint": "^8.57.0",
2424
"eslint-plugin-ft-flow": "^2.0.3",
25+
"eslint-plugin-jsdoc": "^62.7.1",
2526
"eslint-plugin-markdown": "^5.1.0",
2627
"eslint-plugin-prettier": "^5.0.1",
2728
"expo-router": "~6.0.17",

packages/bare-resource-fetcher/src/ResourceFetcher.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
* This module provides functions to download and manage files stored in the application's document directory
55
* inside the `react-native-executorch/` directory. These utilities help manage storage and clean up downloaded
66
* files when they are no longer needed.
7-
*
87
* @category Utilities - General
9-
*
108
* @remarks
119
* **Key Functionality:**
1210
* - **Download Control**: Pause, resume, and cancel operations through:
@@ -102,15 +100,13 @@ interface BareResourceFetcherInterface extends ResourceFetcherAdapter {
102100
/**
103101
* This module provides functions to download and work with downloaded files stored in the application's document directory inside the `react-native-executorch/` directory.
104102
* These utilities can help you manage your storage and clean up the downloaded files when they are no longer needed.
105-
*
106103
* @category Utilities - General
107104
*/
108105
export const BareResourceFetcher: BareResourceFetcherInterface = {
109106
downloads: new Map<ResourceSource, DownloadResource>(), //map of currently downloading (or paused) files, if the download was started by .fetch() method.
110107

111108
/**
112109
* Fetches resources (remote URLs, local files or embedded assets), downloads or stores them locally for use by React Native ExecuTorch.
113-
*
114110
* @param callback - Optional callback to track progress of all downloads, reported between 0 and 1.
115111
* @param sources - Multiple resources that can be strings, asset references, or objects.
116112
* @returns If the fetch was successful, it returns a promise which resolves to an array of local file paths for the downloaded/stored resources (without file:// prefix).
@@ -320,7 +316,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
320316

321317
/**
322318
* Pauses an ongoing download of files.
323-
*
324319
* @param sources - The resource identifiers used when calling `fetch`.
325320
* @returns A promise that resolves once the download is paused.
326321
*/
@@ -331,7 +326,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
331326

332327
/**
333328
* Resumes a paused download of files.
334-
*
335329
* @param sources - The resource identifiers used when calling fetch.
336330
* @returns If the fetch was successful, it returns a promise which resolves to an array of local file paths for the downloaded resources (without file:// prefix).
337331
* If the fetch was again interrupted by `pauseFetching` or `cancelFetching`, it returns a promise which resolves to `null`.
@@ -343,7 +337,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
343337

344338
/**
345339
* Cancels an ongoing/paused download of files.
346-
*
347340
* @param sources - The resource identifiers used when calling `fetch()`.
348341
* @returns A promise that resolves once the download is canceled.
349342
*/
@@ -366,7 +359,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
366359

367360
/**
368361
* Lists all the downloaded files used by React Native ExecuTorch.
369-
*
370362
* @returns A promise, which resolves to an array of URIs for all the downloaded files.
371363
*/
372364
async listDownloadedFiles() {
@@ -376,7 +368,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
376368

377369
/**
378370
* Lists all the downloaded models used by React Native ExecuTorch.
379-
*
380371
* @returns A promise, which resolves to an array of URIs for all the downloaded models.
381372
*/
382373
async listDownloadedModels() {
@@ -386,7 +377,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
386377

387378
/**
388379
* Deletes downloaded resources from the local filesystem.
389-
*
390380
* @param sources - The resource identifiers used when calling `fetch`.
391381
* @returns A promise that resolves once all specified resources have been removed.
392382
*/
@@ -404,7 +394,6 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
404394

405395
/**
406396
* Fetches the info about files size. Works only for remote files.
407-
*
408397
* @param sources - The resource identifiers (URLs).
409398
* @returns A promise that resolves to combined size of files in bytes.
410399
*/
@@ -635,10 +624,8 @@ export const BareResourceFetcher: BareResourceFetcherInterface = {
635624

636625
/**
637626
* Reads the contents of a file as a string.
638-
*
639627
* @param path - Absolute file path to read.
640628
* @returns A promise that resolves to the file contents as a string.
641-
*
642629
* @remarks
643630
* **REQUIRED**: Used internally for reading configuration files (e.g., tokenizer configs).
644631
*/

packages/bare-resource-fetcher/src/ResourceFetcherUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export type { ResourceSourceExtended };
1818

1919
/**
2020
* Utility functions for fetching and managing resources.
21-
*
2221
* @category Utilities - General
2322
*/
2423
export namespace ResourceFetcherUtils {

0 commit comments

Comments
 (0)