From b9d19316b9be87b95c46ddde31061e773d9c7c58 Mon Sep 17 00:00:00 2001 From: Vishniakov Nikolai Date: Fri, 12 Jul 2024 01:40:50 +0200 Subject: [PATCH 1/3] Add js codestyle rules --- src/bindings/js/docs/CODESTYLE.md | 95 +++++++++++++++++++++++++++++++ src/bindings/js/docs/README.md | 4 ++ 2 files changed, 99 insertions(+) create mode 100644 src/bindings/js/docs/CODESTYLE.md diff --git a/src/bindings/js/docs/CODESTYLE.md b/src/bindings/js/docs/CODESTYLE.md new file mode 100644 index 00000000000000..f66362a8eaac57 --- /dev/null +++ b/src/bindings/js/docs/CODESTYLE.md @@ -0,0 +1,95 @@ +# Code Style Guide + +This document outlines the coding standards and guidelines of javascript and typescript part of **openvino-node** package. These rules help maintain code quality and consistency throughout the codebase. + +Please, make sure that eslint activated in your IDE. +Rules specified in [.eslint-global.js file](../.eslintrc-global.js). Pay attention that PR wont get approve without following these rules. + +## 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 should not exceed the maximum length. +- **Enforced By**: `max-len: ['error']` + +### 4. End of Line +- **Rule**: Ensure that files end with a newline. +- **Enforced By**: `eol-last: ['error']` + +### 5. Indentation +- **Rule**: Use 2 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**: Enforce spacing around semicolons. +- **Enforced By**: `semi-spacing: ['error']` + +### 8. Arrow Function Spacing +- **Rule**: Enforce spacing around arrow functions. +- **Enforced By**: `arrow-spacing: ['error']` + +### 9. Comma Spacing +- **Rule**: Enforce spacing around commas. +- **Enforced By**: `comma-spacing: ['error']` + +### 10. Multiple Spaces +- **Rule**: Disallow multiple spaces except for indentation. +- **Enforced By**: `no-multi-spaces: ['error']` + +### 11. Quotes +- **Rule**: Use single quotes for strings. +- **Enforced By**: `quotes: ['error', 'single']` + +### 12. Trailing Spaces +- **Rule**: Disallow trailing spaces at the end of lines. +- **Enforced By**: `no-trailing-spaces: ['error']` + +### 13. Space Before Blocks +- **Rule**: Require space before blocks. +- **Enforced By**: `space-before-blocks: ['error']` + +### 14. Newline Before Return +- **Rule**: Enforce newline before return statements. +- **Enforced By**: `newline-before-return: ['error']` + +### 15. Comma Dangle +- **Rule**: Require trailing commas in multiline object literals. +- **Enforced By**: `comma-dangle: ['error', 'always-multiline']` + +### 16. Space Before Function Parentheses +- **Rule**: Enforce 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**: Enforce consistent spacing between keys and values in object literals. +- **Enforced By**: `key-spacing: ['error', { beforeColon: false }]` + +### 18. Multiple Empty Lines +- **Rule**: Disallow 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**: Enforce consistent spacing around keywords. + - Special case for `catch` keyword: No space after `catch` +- **Enforced By**: `keyword-spacing: ['error', { overrides: { catch: { after: false } } }]` + +## Additional Resources + +For further details on each rule, please refer to the [ESLint documentation](https://eslint.org/docs/rules/). diff --git a/src/bindings/js/docs/README.md b/src/bindings/js/docs/README.md index 2e8b8a299f613b..51e47bc4938964 100644 --- a/src/bindings/js/docs/README.md +++ b/src/bindings/js/docs/README.md @@ -75,6 +75,10 @@ [OpenVINO™ Node.js Bindings Examples of Usage](../../../../samples/js/node/README.md) +## Contribution + +Look at codestyle rules [Codestyle](./CODESTYLE.md) + ## See Also * [OpenVINO™ README](../../../../README.md) From 91792b7598172e5a805bfbaad05675a1cee5781c Mon Sep 17 00:00:00 2001 From: Vishniakov Nikolai Date: Sat, 13 Jul 2024 10:26:15 +0200 Subject: [PATCH 2/3] Fix disclaimer about .eslint config file Co-authored-by: Sebastian Golebiewski --- src/bindings/js/docs/CODESTYLE.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bindings/js/docs/CODESTYLE.md b/src/bindings/js/docs/CODESTYLE.md index f66362a8eaac57..63b743926cf4c6 100644 --- a/src/bindings/js/docs/CODESTYLE.md +++ b/src/bindings/js/docs/CODESTYLE.md @@ -2,8 +2,7 @@ This document outlines the coding standards and guidelines of javascript and typescript part of **openvino-node** package. These rules help maintain code quality and consistency throughout the codebase. -Please, make sure that eslint activated in your IDE. -Rules specified in [.eslint-global.js file](../.eslintrc-global.js). Pay attention that PR wont get approve without following these rules. +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 From 39b6399ea0d5665acf387fb49faacbaa60d504a5 Mon Sep 17 00:00:00 2001 From: Vishniakov Nikolai Date: Sat, 13 Jul 2024 10:28:07 +0200 Subject: [PATCH 3/3] Apply suggestions about text style Co-authored-by: Sebastian Golebiewski --- src/bindings/js/docs/CODESTYLE.md | 44 +++++++++++++++---------------- src/bindings/js/docs/README.md | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/bindings/js/docs/CODESTYLE.md b/src/bindings/js/docs/CODESTYLE.md index 63b743926cf4c6..0ebfd322767b57 100644 --- a/src/bindings/js/docs/CODESTYLE.md +++ b/src/bindings/js/docs/CODESTYLE.md @@ -1,6 +1,6 @@ # Code Style Guide -This document outlines the coding standards and guidelines of javascript and typescript part of **openvino-node** package. These rules help maintain code quality and consistency throughout the codebase. +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. @@ -15,15 +15,15 @@ Make sure your IDE has ESLint plugin installed. Its rules are specified in the [ - **Enforced By**: `no-var: ['error']` ### 3. Line Length -- **Rule**: Lines should not exceed the maximum length. +- **Rule**: Lines cannot exceed the maximum length of 80 characters. - **Enforced By**: `max-len: ['error']` ### 4. End of Line -- **Rule**: Ensure that files end with a newline. +- **Rule**: Files have to end with a newline. - **Enforced By**: `eol-last: ['error']` ### 5. Indentation -- **Rule**: Use 2 spaces for indentation. +- **Rule**: Use two spaces for indentation. - **Enforced By**: `indent: ['error', 2]` ### 6. Naming Conventions @@ -31,64 +31,64 @@ Make sure your IDE has ESLint plugin installed. Its rules are specified in the [ - **Enforced By**: `camelcase: ['error']` ### 7. Semicolon Spacing -- **Rule**: Enforce spacing around semicolons. +- **Rule**: Keep spacing around semicolons. - **Enforced By**: `semi-spacing: ['error']` ### 8. Arrow Function Spacing -- **Rule**: Enforce spacing around arrow functions. +- **Rule**: Keep spacing around arrow functions. - **Enforced By**: `arrow-spacing: ['error']` ### 9. Comma Spacing -- **Rule**: Enforce spacing around commas. +- **Rule**: Keep spacing around commas. - **Enforced By**: `comma-spacing: ['error']` ### 10. Multiple Spaces -- **Rule**: Disallow multiple spaces except for indentation. +- **Rule**: Do not use multiple spaces, except for indentation. - **Enforced By**: `no-multi-spaces: ['error']` ### 11. Quotes -- **Rule**: Use single quotes for strings. +- **Rule**: Start and end strings with a single quote. - **Enforced By**: `quotes: ['error', 'single']` ### 12. Trailing Spaces -- **Rule**: Disallow trailing spaces at the end of lines. +- **Rule**: Trailing spaces at the end of lines are not allowed. - **Enforced By**: `no-trailing-spaces: ['error']` -### 13. Space Before Blocks -- **Rule**: Require space before blocks. +### 13. Space before Blocks +- **Rule**: Space before blocks is required. - **Enforced By**: `space-before-blocks: ['error']` -### 14. Newline Before Return -- **Rule**: Enforce newline before return statements. +### 14. Newline before Return +- **Rule**: Use a newline before return statements. - **Enforced By**: `newline-before-return: ['error']` ### 15. Comma Dangle -- **Rule**: Require trailing commas in multiline object literals. +- **Rule**: Use trailing commas in multiline object literals. - **Enforced By**: `comma-dangle: ['error', 'always-multiline']` -### 16. Space Before Function Parentheses -- **Rule**: Enforce consistent spacing before function parentheses. +### 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**: Enforce consistent spacing between keys and values 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**: Disallow 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**: Enforce consistent spacing around keywords. - - Special case for `catch` keyword: No space after `catch` +- **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, please refer to the [ESLint documentation](https://eslint.org/docs/rules/). +For further details on each rule, refer to the [ESLint documentation](https://eslint.org/docs/rules/). diff --git a/src/bindings/js/docs/README.md b/src/bindings/js/docs/README.md index 51e47bc4938964..bada676878847f 100644 --- a/src/bindings/js/docs/README.md +++ b/src/bindings/js/docs/README.md @@ -77,7 +77,7 @@ ## Contribution -Look at codestyle rules [Codestyle](./CODESTYLE.md) +If you want to contribute to the project, refer to the [code style rules](./CODESTYLE.md) and [contribution guide](../../../../CONTRIBUTING.md) first. ## See Also