Node.js bindings contain two parts: C++ and Typescript/JavaScript.
This article presents the coding standards for JavaScript and TypeScript parts of openvino-node package. The following rules will help maintain code quality and consistency throughout the codebase.
For C++ codestyle rules, refer to this document.
Make sure your IDE has ESLint plugin installed. Its rules are specified in the .eslint-global.js file. Keep in mind that your PR will not be approved if it does not meet the following requirements.
- Rule: Always use semicolons at the end of statements.
- Enforced By:
semi: ['error']
- Rule: Use
let
orconst
instead ofvar
. - Enforced By:
no-var: ['error']
- Rule: Lines cannot exceed the maximum length of 80 characters.
- Enforced By:
max-len: ['error']
- Rule: Files have to end with a newline.
- Enforced By:
eol-last: ['error']
- Rule: Use two spaces for indentation.
- Enforced By:
indent: ['error', 2]
- Rule: Use camelCase for variable and function names.
- Enforced By:
camelcase: ['error']
- Rule: Keep spacing around semicolons.
- Enforced By:
semi-spacing: ['error']
- Rule: Keep spacing around arrow functions.
- Enforced By:
arrow-spacing: ['error']
- Rule: Keep spacing around commas.
- Enforced By:
comma-spacing: ['error']
- Rule: Do not use multiple spaces, except for indentation.
- Enforced By:
no-multi-spaces: ['error']
- Rule: Start and end strings with a single quote.
- Enforced By:
quotes: ['error', 'single']
- Rule: Trailing spaces at the end of lines are not allowed.
- Enforced By:
no-trailing-spaces: ['error']
- Rule: Space before blocks is required.
- Enforced By:
space-before-blocks: ['error']
- Rule: Use a newline before return statements.
- Enforced By:
newline-before-return: ['error']
- Rule: Use trailing commas in multiline object literals.
- Enforced By:
comma-dangle: ['error', 'always-multiline']
- Rule: Maintain consistent spacing before function parentheses.
- Named functions: No space
- Anonymous functions: No space
- Async arrow functions: Space
- Enforced By:
space-before-function-paren: ['error', { named: 'never', anonymous: 'never', asyncArrow: 'always' }]
- Rule: Maintain consistent spacing between keys and values in object literals.
- Enforced By:
key-spacing: ['error', { beforeColon: false }]
- Rule: Do not use multiple empty lines.
- Maximum empty lines: 1
- Maximum at the beginning of file: 0
- Maximum at the end of file: 0
- Enforced By:
no-multiple-empty-lines: ['error', { max: 1, maxBOF: 0, maxEOF: 0 }]
- Rule: Maintain consistent spacing around keywords.
- Special case for the
catch
keyword: No space aftercatch
- Special case for the
- Enforced By:
keyword-spacing: ['error', { overrides: { catch: { after: false } } }]
For further details on each rule, refer to the ESLint documentation.