-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Javascript Coding Style
Linter setup in VSCode
- Install Node.js.
- Install ESLint with
npm install -g eslint. - Install ESlint extension in VSCode.
- Configure ESLint in VSCode to set options (format on save, etc.).
#CS400 - #CS499 Javascript
#CS400 Use the w3school JS convention
Use the w3school JS convention where not specified otherwise by our coding style.
#CS401 Use 2 spaces indentation
To be consistent with our C/C++ coding style, we must use 2 spaces (instead of 4) to indent code.
#CS402 Don't use unneeded curly brackets
To be consistent with our C/C++ coding style, don't use curly brackets when not needed (e.g., for single instruction blocks).
#CS403 Check for undefined variable
Use the following syntax to check for an undefined variable:
#CS404 Naming of private variables and functions
The names of private variables and functions must begin with a _.
#CS405 Use ES6 features
Use ES6 features in the code. For example:
- OOP-style class instead of prototypes
- arrow functions
- constants
- blocked scoped variables
- let and const instead of var
#CS406 Use ESLint linter (atom package: linter-eslint)
All the errors reported by ESLint based on the https://github.com/cyberbotics/webots/blob/master/.eslintrc.json configuration file should be fixed. Warnings may be accepted.
#CS407 Don't exceed 128 character for line of code
Line size is limited to 128 characters (instead of 80 in w3school).
#CS408 Private fields
The # prefix should be used to declare private fields or methods:
class ClassWithPrivate {
#privateField;
#privateFieldWithInitializer = 42;
constructor(value) {
this.#privateField = value;
}
#privateMethod() {
// ...
}
static #privateStaticField;
static #privateStaticFieldWithInitializer = 42;
static #privateStaticMethod() {
// ...
}
}
Note: such values are not inherited by child classes.
#CS409 Protected fields
Protected attributes and methods should be prefixed with a _.
Note: This is only informative and not actually enforced by JavaScript.
Environment Installation
Development Guidelines
- Git workflow
- CI Test Labels
- Coding Style
- New Node and API Function
- Adding a New Robot
- 3D Modelling & Material Design
- Release Procedure
- How to adapt your world or PROTO to Webots R2022a
- How to adapt your world or PROTO to Webots R2022b
Debugging Tools
Technical Doc
- WREN Shadows Volume
- Dependencies re-compilation