From 0e724dfeb43f65963335c6ac5845a59301609b16 Mon Sep 17 00:00:00 2001 From: Pierric Cistac Date: Fri, 24 Jan 2020 17:18:31 -0500 Subject: [PATCH] node: remove redundant types in jsdoc --- bindings/node/.eslintrc.json | 4 +- bindings/node/lib/bindings/decoders.d.ts | 8 +-- bindings/node/lib/bindings/models.d.ts | 2 +- bindings/node/lib/bindings/normalizers.d.ts | 2 +- .../node/lib/bindings/post-processors.d.ts | 4 +- .../node/lib/bindings/pre-tokenizers.d.ts | 8 +-- bindings/node/lib/bindings/tokenizer.d.ts | 14 ++--- bindings/node/lib/bindings/trainers.d.ts | 4 +- .../node/lib/tokenizers/base.tokenizer.ts | 6 +- bindings/node/package-lock.json | 57 +++++++++++++++++++ bindings/node/package.json | 2 + 11 files changed, 86 insertions(+), 25 deletions(-) diff --git a/bindings/node/.eslintrc.json b/bindings/node/.eslintrc.json index 3a7185e9..57b200d9 100644 --- a/bindings/node/.eslintrc.json +++ b/bindings/node/.eslintrc.json @@ -26,6 +26,7 @@ "overrides": [ { "files": "**/*.ts", + "plugins": ["jsdoc"], "extends": [ "plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", @@ -35,7 +36,8 @@ ], "rules": { "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/camelcase": "warn" + "@typescript-eslint/camelcase": "warn", + "jsdoc/no-types": "error" } } ] diff --git a/bindings/node/lib/bindings/decoders.d.ts b/bindings/node/lib/bindings/decoders.d.ts index 2f4a2921..c5978d32 100644 --- a/bindings/node/lib/bindings/decoders.d.ts +++ b/bindings/node/lib/bindings/decoders.d.ts @@ -12,23 +12,23 @@ export function byteLevelDecoder(): Decoder; /** * Instantiate a new WordPiece Decoder - * @param {string} [prefix='##'] The prefix to use for subwords that are not a beginning-of-word + * @param [prefix='##'] The prefix to use for subwords that are not a beginning-of-word */ export function wordPieceDecoder(prefix?: string): Decoder; /** * Instantiate a new Metaspace * - * @param {string} [replacement='▁'] The replacement character. + * @param [replacement='▁'] The replacement character. * Must be exactly one character. By default we use the `▁` (U+2581) meta symbol (same as in SentencePiece). - * @param {boolean} [addPrefixSpace=true] Whether to add a space to the first word if there isn't already one. + * @param [addPrefixSpace=true] Whether to add a space to the first word if there isn't already one. * This lets us treat `hello` exactly like `say hello`. */ export function metaspaceDecoder(replacement?: string, addPrefixSpace?: boolean): Decoder; /** * Instantiate a new BPE Decoder - * @param {string} [suffix=''] The suffix that was used to caracterize an end-of-word. + * @param [suffix=''] The suffix that was used to characterize an end-of-word. * This suffix will be replaced by whitespaces during the decoding */ export function bpeDecoder(suffix?: string): Decoder; diff --git a/bindings/node/lib/bindings/models.d.ts b/bindings/node/lib/bindings/models.d.ts index 66ae26af..80ddbf49 100644 --- a/bindings/node/lib/bindings/models.d.ts +++ b/bindings/node/lib/bindings/models.d.ts @@ -78,7 +78,7 @@ export namespace WordPiece { /** * Instantiate a WordPiece model from the given vocab file * - * @param {string} vocab Path to a vocabulary file + * @param vocab Path to a vocabulary file * @param [options] WordPiece model options */ export function fromFiles(vocab: string, options?: WordPieceOptions): Model; diff --git a/bindings/node/lib/bindings/normalizers.d.ts b/bindings/node/lib/bindings/normalizers.d.ts index bc458695..f8239ef8 100644 --- a/bindings/node/lib/bindings/normalizers.d.ts +++ b/bindings/node/lib/bindings/normalizers.d.ts @@ -33,7 +33,7 @@ export interface BertNormalizerOptions { * Instantiate a Bert Normalizer with the given options * * @param [options] Normalizer options - * @returns {Normalizer} Bert Normalizer. Takes care of normalizing raw text before giving it to a Bert model. + * @returns Bert Normalizer. Takes care of normalizing raw text before giving it to a Bert model. * This includes cleaning the text, handling accents, chinese chars and lowercasing */ export function bertNormalizer(options?: BertNormalizerOptions): Normalizer; diff --git a/bindings/node/lib/bindings/post-processors.d.ts b/bindings/node/lib/bindings/post-processors.d.ts index f537e1de..202d9b3f 100644 --- a/bindings/node/lib/bindings/post-processors.d.ts +++ b/bindings/node/lib/bindings/post-processors.d.ts @@ -8,8 +8,8 @@ interface PostProcessor {} /** * Instantiate a new BertProcessing with the given tokens * - * @param {[string, number]} sep A tuple with the string representation of the SEP token, and its id - * @param {[string, number]} cls A tuple with the string representation of the CLS token, and its id + * @param sep A tuple with the string representation of the SEP token, and its id + * @param cls A tuple with the string representation of the CLS token, and its id */ export function bertProcessing( sep: [string, number], diff --git a/bindings/node/lib/bindings/pre-tokenizers.d.ts b/bindings/node/lib/bindings/pre-tokenizers.d.ts index e97df8ee..6283f8da 100644 --- a/bindings/node/lib/bindings/pre-tokenizers.d.ts +++ b/bindings/node/lib/bindings/pre-tokenizers.d.ts @@ -8,9 +8,9 @@ interface PreTokenizer {} /** * Instantiate a new ByteLevel PreTokenizer * - * @param {boolean} [addPrefixSpace=true] Whether to add a space to the first word if there isn't already one. + * @param [addPrefixSpace=true] Whether to add a space to the first word if there isn't already one. * This lets us treat `hello` exactly like `say hello`. - * @returns {PreTokenizer} ByteLevel PreTokenizer. + * @returns ByteLevel PreTokenizer. * This pre-tokenizer takes care of replacing all bytes of the given string * with a corresponding representation, as well as splitting into words. */ @@ -49,9 +49,9 @@ export function bertPreTokenizer(): PreTokenizer; * This pre-tokenizer replaces any whitespace by the provided replacement character. * It then tries to split on these spaces. * - * @param {string} [replacement="▁"] The replacement character. Must be exactly one character. + * @param [replacement="▁"] The replacement character. Must be exactly one character. * By default we use the `▁` (U+2581) meta symbol (Same as in SentencePiece). - * @param {boolean} [addPrefixSpace] Whether to add a space to the first word if there isn't already one. + * @param [addPrefixSpace] Whether to add a space to the first word if there isn't already one. * This lets us treat `hello` exactly like `say hello`. */ export function metaspacePreTokenizer( diff --git a/bindings/node/lib/bindings/tokenizer.d.ts b/bindings/node/lib/bindings/tokenizer.d.ts index d03f8ef7..96732c85 100644 --- a/bindings/node/lib/bindings/tokenizer.d.ts +++ b/bindings/node/lib/bindings/tokenizer.d.ts @@ -40,7 +40,7 @@ export class Tokenizer { * The special tokens will never be processed by the model, and will be removed while decoding. * * @param tokens The list of special tokens to add - * @returns {number} The number of tokens that were added to the vocabulary + * @returns The number of tokens that were added to the vocabulary */ addSpecialTokens(tokens: string[]): number; @@ -72,7 +72,7 @@ export class Tokenizer { * Decode the given list of ids to a string sequence * * @param ids A list of ids to be decoded - * @param {boolean} [skipSpecialTokens=true] Whether to remove all the special tokens from the output string + * @param [skipSpecialTokens=true] Whether to remove all the special tokens from the output string * @returns The decoded string */ decode(ids: number[], skipSpecialTokens?: boolean): string; @@ -81,7 +81,7 @@ export class Tokenizer { * Decode the list of sequences to a list of string sequences * * @param sequences A list of sequence of ids to be decoded - * @param {boolean} [skipSpecialTokens] Whether to remove all the special tokens from the output strings + * @param [skipSpecialTokens] Whether to remove all the special tokens from the output strings * @returns A list of decoded strings */ decodeBatch(sequences: number[][], skipSpecialTokens?: boolean): string[]; @@ -113,7 +113,7 @@ export class Tokenizer { /** * Returns the size of the vocabulary * - * @param {boolean} [withAddedTokens=true] Whether to include the added tokens in the vocabulary's size + * @param [withAddedTokens=true] Whether to include the added tokens in the vocabulary's size */ getVocabSize(withAddedTokens?: boolean): number; @@ -231,7 +231,7 @@ interface Encoding { * Pad the current Encoding at the given length * * @param length The length at which to pad - * @param {PaddingOptions} [options] Padding options + * @param [options] Padding options */ pad(length: number, options?: PaddingOptions): void; @@ -239,8 +239,8 @@ interface Encoding { * Truncate the current Encoding at the given max_length * * @param length The maximum length to be kept - * @param {number} [stride=0] The length of the previous first sequence - * to be includedin the overflowing sequence + * @param [stride=0] The length of the previous first sequence + * to be included in the overflowing sequence */ truncate(length: number, stride?: number): void; } diff --git a/bindings/node/lib/bindings/trainers.d.ts b/bindings/node/lib/bindings/trainers.d.ts index 26fa6e97..f2615a01 100644 --- a/bindings/node/lib/bindings/trainers.d.ts +++ b/bindings/node/lib/bindings/trainers.d.ts @@ -50,12 +50,12 @@ export interface TrainerOptions { /** * Instantiate a new BPE Trainer - * @param {TrainerOptions} [options] BPE Trainer options + * @param [options] BPE Trainer options */ export function bpeTrainer(options?: TrainerOptions): Trainer; /** * Instantiate a new WordPiece Trainer - * @param {TrainerOptions} [options] WordPiece Trainer options + * @param [options] WordPiece Trainer options */ export function wordPieceTrainer(options?: TrainerOptions): Trainer; diff --git a/bindings/node/lib/tokenizers/base.tokenizer.ts b/bindings/node/lib/tokenizers/base.tokenizer.ts index d5f454c3..09250d55 100644 --- a/bindings/node/lib/tokenizers/base.tokenizer.ts +++ b/bindings/node/lib/tokenizers/base.tokenizer.ts @@ -8,8 +8,8 @@ export class BaseTokenizer { /** * Encode the given sequence * - * @param {string} sequence The sequence to encode - * @param {(string | null)} pair The optional pair sequence + * @param sequence The sequence to encode + * @param pair The optional pair sequence */ async encode(sequence: string, pair?: string): Promise { const encode = promisify(this.tokenizer.encode.bind(this.tokenizer)); @@ -19,7 +19,7 @@ export class BaseTokenizer { /** * Encode the given sequences or pair of sequences * - * @param {((string | [string, string])[])} sequences A list of sequences or pair of sequences. + * @param sequences A list of sequences or pair of sequences. * The list can contain both at the same time. */ async encodeBatch(sequences: (string | [string, string])[]): Promise { diff --git a/bindings/node/package-lock.json b/bindings/node/package-lock.json index 2232a776..dbd02631 100644 --- a/bindings/node/package-lock.json +++ b/bindings/node/package-lock.json @@ -1281,6 +1281,12 @@ "dev": true, "optional": true }, + "comment-parser": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/comment-parser/-/comment-parser-0.7.2.tgz", + "integrity": "sha512-4Rjb1FnxtOcv9qsfuaNuVsmmVn4ooVoBHzYfyKteiXwIU84PClyGA5jASoFMwPV93+FPh9spwueXauxFJZkGAg==", + "dev": true + }, "component-emitter": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", @@ -1916,6 +1922,39 @@ } } }, + "eslint-plugin-jsdoc": { + "version": "20.4.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-20.4.0.tgz", + "integrity": "sha512-c/fnEpwWLFeQn+A7pb1qLOdyhovpqGCWCeUv1wtzFNL5G+xedl9wHUnXtp3b1sGHolVimi9DxKVTuhK/snXoOw==", + "dev": true, + "requires": { + "comment-parser": "^0.7.2", + "debug": "^4.1.1", + "jsdoctypeparser": "^6.1.0", + "lodash": "^4.17.15", + "object.entries-ponyfill": "^1.0.1", + "regextras": "^0.7.0", + "semver": "^6.3.0", + "spdx-expression-parse": "^3.0.0" + }, + "dependencies": { + "debug": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", + "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } + } + }, "eslint-plugin-prettier": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.2.tgz", @@ -4144,6 +4183,12 @@ "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", "dev": true }, + "jsdoctypeparser": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsdoctypeparser/-/jsdoctypeparser-6.1.0.tgz", + "integrity": "sha512-UCQBZ3xCUBv/PLfwKAJhp6jmGOSLFNKzrotXGNgbKhWvz27wPsCsVeP7gIcHPElQw2agBmynAitXqhxR58XAmA==", + "dev": true + }, "jsdom": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-11.12.0.tgz", @@ -4785,6 +4830,12 @@ "object-keys": "^1.0.11" } }, + "object.entries-ponyfill": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/object.entries-ponyfill/-/object.entries-ponyfill-1.0.1.tgz", + "integrity": "sha1-Kavfd8v70mVm3RqiTp2I9lQz0lY=", + "dev": true + }, "object.getownpropertydescriptors": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.1.0.tgz", @@ -5218,6 +5269,12 @@ "integrity": "sha512-Z+hNr7RAVWxznLPuA7DIh8UNX1j9CDrUQxskw9IrBE1Dxue2lyXT+shqEIeLUjrokxIP8CMy1WkjgG3rTsd5/g==", "dev": true }, + "regextras": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/regextras/-/regextras-0.7.0.tgz", + "integrity": "sha512-ds+fL+Vhl918gbAUb0k2gVKbTZLsg84Re3DI6p85Et0U0tYME3hyW4nMK8Px4dtDaBA2qNjvG5uWyW7eK5gfmw==", + "dev": true + }, "remove-trailing-separator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz", diff --git a/bindings/node/package.json b/bindings/node/package.json index 4bbf7dc6..b2cada36 100644 --- a/bindings/node/package.json +++ b/bindings/node/package.json @@ -21,6 +21,7 @@ "eslint": "^6.8.0", "eslint-config-prettier": "^6.9.0", "eslint-plugin-jest": "^23.6.0", + "eslint-plugin-jsdoc": "^20.4.0", "eslint-plugin-prettier": "^3.1.2", "eslint-plugin-simple-import-sort": "^5.0.0", "jest": "^24.9.0", @@ -36,6 +37,7 @@ "scripts": { "dev-ts": "rm -rf dist && tsc -p tsconfig.prod.json && ln -s $(pwd)/lib/bindings dist/bindings", "dev-rs": "neon build", + "dev": "npm run dev-rs && npm run dev-ts", "compile": "neon build --release", "clean-rs": "neon clean", "package": "node-pre-gyp package",