Aller au contenu principal
Version: 3.0.0

Lint tools, rules and formatting

Midway's framework and business code are written by TypeScript. The default Midway provides a set of default lint, editor and formatting rules for more convenient development and testing.

Code style library

The code style library of Midway is called mwts, which is derived from Google's gts. Mwts is Midway's TypeScript style guide and the configuration of formatter, linter and automatic code fix.


In the midway project, we will add mwts by default. The following process is just to explain how to use mwts.

In order to use mwts, we need to add it to the development dependency.

  "devDependencies": {
"mwts": "^1.0.5 ",
"typescript": "^4.0.0"

ESLint configuration

Mwts provides a default set of ESLint configurations (TSLint has been abandoned and merged into ESLint).

Create a .eslintrc.json file in the root directory of the project, with the following contents (usually scaffolding will bring it with it):

"extends": "./node_modules/mwts /",
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "interface.ts"]
"env": {
"jest": true

The above is the default configuration of midway project. Other project ignorePatterns and env can be adjusted according to ESLint.

For more information about the default rules for mwts, see here.

Perform code checking and formatting

You can run the mwts check command and the mwts fix command to check the code. For example, add script commands to the project (usually scaffolding will come with it).

  "scripts": {
"lint": "mwts check ",
"lint:fix": "mwts fix",

Prettier configuration

Mwts provides a set of default prettier configurations, creating a .prettierrc.js file with the following configuration contents (usually scaffolding comes with it).

module.exports = {

Configure save automatic formatting

Let's take VSCode as an example.

The first step is to install the Prettier plug-in.

Open the configuration, search for "save", find "Format On Save" on the right, and check.

If saving the file has no effect, the editor usually has multiple formatting methods, you can right-click to make the default selection.

Select Configure Default Formatters ".

Select Prettier.