WORK IN PROGRESS
The Artemis client is an Angular project. Keep https://angular.io/guide/styleguide in mind.
Some general aspects:
- Never invoke methods from the html template. The automatic change tracking in Angular will kill the application performance
- The Artemis client uses lazy loading to keep the initial bundle size below 2 MB.
- Code quality and test coverage are important. Try to reuse code and avoid code duplication. Write meaningful tests!
- Use PascalCase for type names.
- Do not use "I" as a prefix for interface names.
- Use PascalCase for enum values.
- Use camelCase for function names.
- Use camelCase for property names and local variables.
- Do not use "_" as a prefix for private properties.
- Use whole words in names when possible.
- 1 file per logical component (e.g. parser, scanner, emitter, checker).
- Do not add new files. :)
- files with ".generated.*" suffix are auto-generated, do not hand-edit them.
- Do not export types/functions unless you need to share it across multiple components.
- Do not introduce new types/values to the global namespace.
- Shared types should be defined in 'types.ts'.
- Within a file, type definitions should come first.
- Use undefined. Do not use null.
- Consider objects like Nodes, Symbols, etc. as immutable outside the component that created them. Do not change them.
- Consider arrays as immutable by default after creation.
- Use JSDoc style comments for functions, interfaces, enums, and classes.
- Use single quotes for strings.
- All strings visible to the user need to be localized (make an entry in the corresponding
*.json
file).
- Use arrow functions over anonymous function expressions.
- Always surround arrow function parameters.
For example,
x => x + x
is wrong but the following are correct:(x) => x + x
(x,y) => x + y
<T>(x: T, y: T) => x === y
- Always surround loop and conditional bodies with curly braces. Statements on the same line are allowed to omit braces.
- Open curly braces always go on the same line as whatever necessitates them.
- Parenthesized constructs should have no surrounding whitespace.
A single space follows commas, colons, and semicolons in those constructs. For example:
for (var i = 0, n = str.length; i < 10; i++) { }
if (x < 10) { }
function f(x: number, y: string): void { }
- Use a single declaration per variable statement (i.e. use
var x = 1; var y = 2;
overvar x = 1, y = 2;
). else
goes on the same line from the closing curly brace.- Use 4 spaces per indentation.
We use prettier
to style code automatically and eslint
to find additional issues. You can find the corresponding commands to invoked those tools in package.json
.
Some parts of these guidelines are adapted from https://github.com/microsoft/TypeScript-wiki/blob/master/Coding-guidelines.md