Skip to content

Commit

Permalink
[OV JS] npm run lint on .js files (#26543)
Browse files Browse the repository at this point in the history
### Details:
 - include *.js files
 - Fix codestyle errors about max-len, snake-case etc.

### Tickets:
 - *ticket-id*
  • Loading branch information
almilosz authored Sep 19, 2024
1 parent b368c31 commit bcd9162
Show file tree
Hide file tree
Showing 16 changed files with 632 additions and 484 deletions.
3 changes: 2 additions & 1 deletion src/bindings/js/.eslintrc-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
rules: {
'semi': ['error'],
'no-var': ['error'],
'max-len': ['error'],
'max-len': ['error', { 'ignoreUrls': true }],
'eol-last': ['error'],
'indent': ['error', 2],
'camelcase': ['error'],
Expand All @@ -23,5 +23,6 @@ module.exports = {
'key-spacing': ['error', { beforeColon: false }],
'no-multiple-empty-lines': ['error', { max: 1, maxBOF: 0, maxEOF: 0 }],
'keyword-spacing': ['error', { overrides: { catch: { after: false } } }],
'@typescript-eslint/no-var-requires': 0,
}
};
2 changes: 1 addition & 1 deletion src/bindings/js/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
'./.eslintrc-global.js',
],
ignorePatterns: ['**/*.js', 'node_modules/', 'types/', 'dist/', 'bin/'],
ignorePatterns: ['node_modules/', 'types/', 'dist/', 'bin/', '.eslintrc.js'],
root: true,
};
3 changes: 3 additions & 0 deletions src/bindings/js/node/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
extends: ['../.eslintrc.js'],
env: {
node: true,
},
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
};
98 changes: 52 additions & 46 deletions src/bindings/js/node/lib/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ interface Core {
compileModel(
model: Model,
deviceName: string,
config?: { [propertyName: string]: string }
config?: { [propertyName: string]: string },
): Promise<CompiledModel>;
/**
* Asynchronously reads a model and creates a compiled model
Expand All @@ -67,7 +67,7 @@ interface Core {
compileModel(
modelPath: string,
deviceName: string,
config?: { [propertyName: string]: string }
config?: { [propertyName: string]: string },
): Promise<CompiledModel>;
/**
* A synchronous version of {@link Core.compileModel}.
Expand All @@ -76,7 +76,7 @@ interface Core {
compileModelSync(
model: Model,
deviceName: string,
config?: { [propertyName: string]: string }
config?: { [propertyName: string]: string },
): CompiledModel;
/**
* A synchronous version of {@link Core.compileModel}.
Expand All @@ -85,7 +85,7 @@ interface Core {
compileModelSync(
modelPath: string,
deviceName: string,
config?: { [propertyName: string]: string }
config?: { [propertyName: string]: string },
): CompiledModel;
/**
* It returns a list of available inference devices.
Expand Down Expand Up @@ -118,9 +118,9 @@ interface Core {
*/
getVersions(deviceName: string): {
[deviceName: string]: {
buildNumber: string,
description: string,
},
buildNumber: string;
description: string;
};
};
/**
* Asynchronously imports a previously exported compiled model.
Expand All @@ -135,7 +135,7 @@ interface Core {
importModel(
modelStream: Buffer,
device: string,
config?: { [key: string]: string | number | boolean }
config?: { [key: string]: string | number | boolean },
): Promise<CompiledModel>;
/**
* A synchronous version of {@link Core.importModel}.
Expand All @@ -144,7 +144,7 @@ interface Core {
importModelSync(
modelStream: Buffer,
device: string,
config?: { [key: string]: string | number | boolean }
config?: { [key: string]: string | number | boolean },
): CompiledModel;
/**
* It reads models from the IR / ONNX / PDPD / TF and TFLite formats.
Expand Down Expand Up @@ -175,7 +175,9 @@ interface Core {
* @param weightsBuffer Binary data with tensor data.
*/
readModel(
modelBuffer: Uint8Array, weightsBuffer?: Uint8Array): Promise<Model>;
modelBuffer: Uint8Array,
weightsBuffer?: Uint8Array,
): Promise<Model>;
/**
* A synchronous version of {@link Core.readModel}.
* It reads models from the IR / ONNX / PDPD / TF and TFLite formats.
Expand Down Expand Up @@ -220,7 +222,7 @@ interface Core {
): {[key: string]: string | number | boolean};
}
interface CoreConstructor {
new(): Core;
new (): Core;
}

/**
Expand Down Expand Up @@ -277,9 +279,9 @@ interface Model {
*/
isDynamic(): boolean;
/**
* It gets the output of the model.
* If a model has more than one output, this method throws an exception.
*/
* It gets the output of the model.
* If a model has more than one output, this method throws an exception.
*/
output(): Output;
/**
* It gets the output of the model identified by the tensor name.
Expand Down Expand Up @@ -372,15 +374,15 @@ interface CompiledModel {
* @returns {Output} A compiled model input.
*/
input(name: string): Output;
/**
/**
* It sets properties for the current compiled model. Properties
* can be retrieved via {@link CompiledModel.getProperty}.
* @param property An object with the key-value pairs.
* (property name, property value)
*/
setProperty(properties: {
[propertyName: string]: string | number | boolean
}): void;
setProperty(properties: {
[propertyName: string]: string | number | boolean;
}): void;
}

/**
Expand Down Expand Up @@ -438,7 +440,7 @@ interface TensorConstructor {
* @param type The element type of the new tensor.
* @param shape The shape of the new tensor.
*/
new(type: element | elementTypeString, shape: number[]): Tensor;
new (type: element | elementTypeString, shape: number[]): Tensor;
/**
* It constructs a tensor using the element type and shape. The new tensor
* wraps allocated host memory.
Expand All @@ -447,14 +449,17 @@ interface TensorConstructor {
* @param tensorData A subclass of TypedArray that will be wrapped
* by a {@link Tensor}.
*/
new(type: element | elementTypeString, shape: number[],
tensorData: SupportedTypedArray): Tensor;
new (
type: element | elementTypeString,
shape: number[],
tensorData: SupportedTypedArray,
): Tensor;
/**
* It constructs a tensor using the element type and shape. The strings from
* the array are used to fill the new tensor. Each element of a string tensor
* is a string of arbitrary length, including an empty string.
*/
new(tensorData: string[]): Tensor;
new (tensorData: string[]): Tensor;
}

/**
Expand All @@ -478,25 +483,28 @@ interface InferRequest {
* TypedArray will be wrapped into Tensor underneath using the input shape
* and element type of the deployed model.
*/
infer(inputData: { [inputName: string]: Tensor | SupportedTypedArray })
: { [outputName: string]: Tensor };
infer(inputData: { [inputName: string]: Tensor | SupportedTypedArray }): {
[outputName: string]: Tensor;
};
/**
* It infers specified input(s) in the synchronous mode.
* @param inputData An array with tensors or TypedArrays. TypedArrays will be
* wrapped into Tensors underneath using the input shape and element type
* of the deployed model. If the model has multiple inputs, the Tensors
* and TypedArrays must be passed in the correct order.
*/
infer(inputData: Tensor[] | SupportedTypedArray[])
: { [outputName: string]: Tensor };
infer(inputData: Tensor[] | SupportedTypedArray[]): {
[outputName: string]: Tensor;
};
/**
* It infers specified input(s) in the asynchronous mode.
* @param inputData An object with the key-value pairs where the key is the
* input name and value is a tensor or an array with tensors. If the model has
* multiple inputs, the Tensors must be passed in the correct order.
*/
inferAsync(inputData: { [inputName: string]: Tensor }
| Tensor[]): Promise<{ [outputName: string]: Tensor }>;
inferAsync(
inputData: { [inputName: string]: Tensor } | Tensor[],
): Promise<{ [outputName: string]: Tensor }>;
/**
* It gets the compiled model used by the InferRequest object.
*/
Expand All @@ -521,11 +529,11 @@ interface InferRequest {
*/
getOutputTensor(): Tensor;
/**
* It gets the output tensor for inference.
* @param idx An index of the tensor to get.
* @returns A tensor at the specified index. If the tensor with the specified
* idx is not found, an exception is thrown.
*/
* It gets the output tensor for inference.
* @param idx An index of the tensor to get.
* @returns A tensor at the specified index. If the tensor with the specified
* idx is not found, an exception is thrown.
*/
getOutputTensor(idx?: number): Tensor;
/**
* It gets an input/output tensor for inference.
Expand Down Expand Up @@ -619,7 +627,7 @@ interface PrePostProcessor {
output(idxOrTensorName?: number | string): OutputInfo;
}
interface PrePostProcessorConstructor {
new(model: Model): PrePostProcessor;
new (model: Model): PrePostProcessor;
}

interface PartialShape {
Expand All @@ -638,7 +646,7 @@ interface PartialShapeConstructor {
* Omit parameter to create empty shape.
* @param [shape] String representation of the shape.
*/
new(shape?: string): PartialShape;
new (shape?: string): PartialShape;
}

declare enum element {
Expand All @@ -662,18 +670,16 @@ declare enum resizeAlgorithm {
}

export interface NodeAddon {
Core: CoreConstructor,
Tensor: TensorConstructor,
PartialShape: PartialShapeConstructor,
Core: CoreConstructor;
Tensor: TensorConstructor;
PartialShape: PartialShapeConstructor;

preprocess: {
resizeAlgorithm: typeof resizeAlgorithm,
PrePostProcessor: PrePostProcessorConstructor,
},
element: typeof element,
resizeAlgorithm: typeof resizeAlgorithm;
PrePostProcessor: PrePostProcessorConstructor;
};
element: typeof element;
}

export default
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('../bin/ov_node_addon.node') as
NodeAddon;
export default // eslint-disable-next-line @typescript-eslint/no-var-requires
require('../bin/ov_node_addon.node') as NodeAddon;
Loading

0 comments on commit bcd9162

Please sign in to comment.