Skip to content

[DOCS][OV JS] Add js codestyle rules #25523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions src/bindings/js/docs/CODESTYLE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Code Style Guide

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.

Make sure your IDE has ESLint plugin installed. Its rules are specified in the [.eslint-global.js file](../.eslintrc-global.js). Keep in mind that your PR will not be approved if it does not meet the following requirements.

## General Rules

### 1. Semicolons
- **Rule**: Always use semicolons at the end of statements.
- **Enforced By**: `semi: ['error']`

### 2. Variable Declarations
- **Rule**: Use `let` or `const` instead of `var`.
- **Enforced By**: `no-var: ['error']`

### 3. Line Length
- **Rule**: Lines cannot exceed the maximum length of 80 characters.
- **Enforced By**: `max-len: ['error']`

### 4. End of Line
- **Rule**: Files have to end with a newline.
- **Enforced By**: `eol-last: ['error']`

### 5. Indentation
- **Rule**: Use two spaces for indentation.
- **Enforced By**: `indent: ['error', 2]`

### 6. Naming Conventions
- **Rule**: Use camelCase for variable and function names.
- **Enforced By**: `camelcase: ['error']`

### 7. Semicolon Spacing
- **Rule**: Keep spacing around semicolons.
- **Enforced By**: `semi-spacing: ['error']`

### 8. Arrow Function Spacing
- **Rule**: Keep spacing around arrow functions.
- **Enforced By**: `arrow-spacing: ['error']`

### 9. Comma Spacing
- **Rule**: Keep spacing around commas.
- **Enforced By**: `comma-spacing: ['error']`

### 10. Multiple Spaces
- **Rule**: Do not use multiple spaces, except for indentation.
- **Enforced By**: `no-multi-spaces: ['error']`

### 11. Quotes
- **Rule**: Start and end strings with a single quote.
- **Enforced By**: `quotes: ['error', 'single']`

### 12. Trailing Spaces
- **Rule**: Trailing spaces at the end of lines are not allowed.
- **Enforced By**: `no-trailing-spaces: ['error']`

### 13. Space before Blocks
- **Rule**: Space before blocks is required.
- **Enforced By**: `space-before-blocks: ['error']`

### 14. Newline before Return
- **Rule**: Use a newline before return statements.
- **Enforced By**: `newline-before-return: ['error']`

### 15. Comma Dangle
- **Rule**: Use trailing commas in multiline object literals.
- **Enforced By**: `comma-dangle: ['error', 'always-multiline']`

### 16. Space before Function Parentheses
- **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' }]`

### 17. Key Spacing in Object Literals
- **Rule**: Maintain consistent spacing between keys and values in object literals.
- **Enforced By**: `key-spacing: ['error', { beforeColon: false }]`

### 18. Multiple Empty Lines
- **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 }]`

### 19. Keyword Spacing
- **Rule**: Maintain consistent spacing around keywords.
- Special case for the `catch` keyword: No space after `catch`
- **Enforced By**: `keyword-spacing: ['error', { overrides: { catch: { after: false } } }]`

## Additional Resources

For further details on each rule, refer to the [ESLint documentation](https://eslint.org/docs/rules/).
4 changes: 4 additions & 0 deletions src/bindings/js/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@

[OpenVINO™ Node.js Bindings Examples of Usage](../../../../samples/js/node/README.md)

## Contribution

If you want to contribute to the project, refer to the [code style rules](./CODESTYLE.md) and [contribution guide](../../../../CONTRIBUTING.md) first.

## See Also

* [OpenVINO™ README](../../../../README.md)
Expand Down
Loading