Coaty Coding Style Guide

These guidelines and principles shall provide a common basis for coding Coaty framework components and application projects using TypeScript.

The coding guidelines are obligatory for TypeScript developers that contribute to the Coaty framework. We strongly suggest that application developers shall also follow these guidelines in their Coaty projects.

If you are new to TypeScript programming, we recommend to take a look at the official TypeScript website. Its “Playground” is especially useful to interactively try some TypeScript code in your browser.

To program the Coaty framework, we recommend to use Visual Studio Code, a free, open source IDE that runs everywhere. Install the VS Code extension “TypeScript TSLint Plugin” to enable TypeScript linting within the IDE.

Table of Contents

Linting TypeScript Code

The Coaty framework uses TSLint for linting the TypeScript code. The TS linter is run automatically when building the framework distribution package with npm run build.

To build distribution packages but not lint the source code use npm run build:nolint.

You can also invoke the linter on its own: npm run lint.

To fix linting errors automatically, invoke npm run lint:fix.

Please ensure that the TypeScript files compile correctly before running the linter.

The linter uses a recommended set of rules that conform with the TypeScript Coding Guidelines for Coaty projects as described in the following section. These rules are defined in the TSLint configuration file tslint-config.json which is part of the framework’s distribution package, so a Coaty application project can also use them in its tsconfig.json file:

{
    "extends": "coaty/tslint-config",
    "rules": {
        // You may overwrite some rule settings here
    }
}

All available rules and options for TSLint are described here.

You may enable/disable TSLint or a subset of rules within certain lines of a TypeScript file with the following comment rule flags

/* tslint:disable-next-line:rule1 rule2 rule3... */

/* tslint:disable:rule1 rule2 rule3... */
...
/* tslint:enable:rule1 rule2 rule3... */

TypeScript Coding Guidelines

Naming

Style

undefined and null

Comparison Operators

Variables

Strings

Destructuring

Functions

Classes and Methods

General Types

Generic Types

External Modules

Components and Files

Comments

Typings

Coding Principles

Framework developers who are implementing new framework components must strictly follow the coding principles listed below:

Asynchronous Data Flow

Container Components

Object Models


Copyright (c) 2018 Siemens AG. This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.