UNPKG

4.62 kBMarkdownView Raw
1# gts
2
3> Google TypeScript Style
4
5[![NPM Version][npm-image]][npm-url]
6[![GitHub Actions][github-image]][github-url]
7[![Known Vulnerabilities][snyk-image]][snyk-url]
8[![codecov][codecov-image]][codecov-url]
9[![TypeScript Style Guide][gts-image]][gts-url]
10
11[gts][npm-url] is Google's TypeScript style guide, and the configuration for our formatter, linter, and automatic code fixer. No lint rules to edit, no configuration to update, no more bike shedding over syntax.
12
13To borrow from [standardjs][standardjs-url]:
14
15- **No configuration**. The easiest way to enforce consistent style in your project. Just drop it in.
16- **Automatically format code**. Just run `gts fix` and say goodbye to messy or inconsistent code.
17- **Catch style issues & programmer errors early**. Save precious code review time by eliminating back-and-forth between reviewer & contributor.
18- **Opinionated, but not to a fault**. We recommend you use the default configuration, but if you _need_ to customize compiler or linter config, you can.
19
20Under the covers, we use [eslint][eslint-url] to enforce the style guide and provide automated fixes, and [prettier][prettier-url] to re-format code.
21
22## Getting Started
23
24The easiest way to get started is to run:
25
26```sh
27npx gts init
28```
29
30## How it works
31
32When you run the `npx gts init` command, it's going to do a few things for you:
33
34- Adds an opinionated `tsconfig.json` file to your project that uses the Google TypeScript Style.
35- Adds the necessary devDependencies to your `package.json`.
36- Adds scripts to your `package.json`:
37 - `lint`: Lints and checks for formatting problems.
38 - `fix`: Automatically fixes formatting and linting problems (if possible).
39 - `clean`: Removes output files.
40 - `compile`: Compiles the source code using TypeScript compiler.
41 - `pretest`, `posttest` and `prepare`: convenience integrations.
42- If a source folder is not already present it will add a default template project.
43
44### Individual files
45
46The commands above will all run in the scope of the current folder. Some commands can be run on individual files:
47
48```sh
49gts lint index.ts
50gts lint one.ts two.ts three.ts
51gts lint *.ts
52```
53
54### Working with eslint
55
56Under the covers, we use [eslint][eslint-url] to enforce the style guide and provide automated fixes, and [prettier][prettier-url] to re-format code. To use the shared `eslint` configuration, create an `.eslintrc` in your project directory, and extend the shared config:
57
58```yml
59---
60extends:
61 - './node_modules/gts'
62```
63
64If you don't want to use the `gts` CLI, you can drop down to using the module as a basic `eslint` config, and just use the `eslint` cli:
65
66```
67$ eslint --fix
68```
69
70This opens the ability to use the vast `eslint` ecosystem including custom rules, and tools like the VSCode plugin for eslint:
71
72- https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
73
74## Badge
75
76Show your love for `gts` and include a badge!
77
78[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)
79
80```md
81[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)
82```
83
84## Supported Node.js Versions
85
86Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/). Libraries are compatible with all current _active_ and _maintenance_ versions of Node.js.
87
88## Can I use *gts* with the [pre-commit](https://pre-commit.com/) framework?
89
90Yes! You can put the following in your `.pre-commit-config.yaml` file:
91
92```yaml
93repos:
94 - repo: https://github.com/google/gts
95 rev: '' # Use the sha / tag you want to point at
96 hooks:
97 - id: gts
98```
99
100## License
101
102[Apache-2.0](LICENSE)
103
104---
105
106Made with ❤️ by the Google Node.js team.
107
108> **_NOTE: This is not an official Google product._**
109
110[github-image]: https://github.com/google/gts/workflows/ci/badge.svg
111[github-url]: https://github.com/google/gts/actions
112[prettier-url]: https://prettier.io/
113[codecov-image]: https://codecov.io/gh/google/gts/branch/main/graph/badge.svg
114[codecov-url]: https://codecov.io/gh/google/gts
115[david-image]: https://david-dm.org/google/gts.svg
116[david-url]: https://david-dm.org/google/gts
117[gts-image]: https://img.shields.io/badge/code%20style-google-blueviolet.svg
118[gts-url]: https://github.com/google/gts
119[npm-image]: https://img.shields.io/npm/v/gts.svg
120[npm-url]: https://npmjs.org/package/gts
121[snyk-image]: https://snyk.io/test/github/google/gts/badge.svg
122[snyk-url]: https://snyk.io/test/github/google/gts
123[standardjs-url]: https://www.npmjs.com/package/standard
124[eslint-url]: https://eslint.org/