Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

gts

google964.1kApache-2.06.0.2TypeScript support: included

Google TypeScript Style

typescript, linter, formatter, google

readme

gts

Google TypeScript Style

NPM Version GitHub Actions Known Vulnerabilities codecov TypeScript Style Guide

gts 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.

To borrow from standardjs:

  • No configuration. The easiest way to enforce consistent style in your project. Just drop it in.
  • Automatically format code. Just run gts fix and say goodbye to messy or inconsistent code.
  • Catch style issues & programmer errors early. Save precious code review time by eliminating back-and-forth between reviewer & contributor.
  • 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.

Under the covers, we use eslint to enforce the style guide and provide automated fixes, and prettier to re-format code.

Getting Started

The easiest way to get started is to run:

npx gts init

How it works

When you run the npx gts init command, it's going to do a few things for you:

  • Adds an opinionated tsconfig.json file to your project that uses the Google TypeScript Style.
  • Adds the necessary devDependencies to your package.json.
  • Adds scripts to your package.json:
    • lint: Lints and checks for formatting problems.
    • fix: Automatically fixes formatting and linting problems (if possible).
    • clean: Removes output files.
    • compile: Compiles the source code using TypeScript compiler.
    • pretest, posttest and prepare: convenience integrations.
  • If a source folder is not already present it will add a default template project.

Individual files

The commands above will all run in the scope of the current folder. Some commands can be run on individual files:

gts lint index.ts
gts lint one.ts two.ts three.ts
gts lint *.ts

Working with eslint

Under the covers, we use eslint to enforce the style guide and provide automated fixes, and prettier to re-format code. To use the shared eslint configuration, create an .eslintrc in your project directory, and extend the shared config:

---
extends:
  - './node_modules/gts'

If 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:

$ eslint --fix

This opens the ability to use the vast eslint ecosystem including custom rules, and tools like the VSCode plugin for eslint:

Badge

Show your love for gts and include a badge!

Code Style: Google

[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)

Supported Node.js Versions

Our client libraries follow the Node.js release schedule. Libraries are compatible with all current active and maintenance versions of Node.js.

Can I use gts with the pre-commit framework?

Yes! You can put the following in your .pre-commit-config.yaml file:

repos:
  - repo: https://github.com/google/gts
    rev: '' # Use the sha / tag you want to point at
    hooks:
      - id: gts

License

Apache-2.0


Made with ❤️ by the Google Node.js team.

NOTE: This is not an official Google product.

changelog

Changelog

6.0.2 (2024-10-25)

Bug Fixes

6.0.1 (2024-10-22)

Bug Fixes

  • Allow typescript v5+ as a peer dependency (#909) (996aaec)

6.0.0 (2024-10-10)

⚠ BREAKING CHANGES

  • Update '.prettierrc.json' to include trailingComma: "all" to match internal Google config (#822)
  • Update typescript and other dependencies (#902)
  • Set no-floating-promises to error (#901)
  • Set composite: true in tsconfig-google.json (#899)
  • Set stripInternal in tsconfig-google.json (#900)
  • Support Node 18+ (#896)

Features

  • Set composite: true in tsconfig-google.json (#899) (71972dc)
  • Set no-floating-promises to error (#901) (1d28f92)
  • Set stripInternal in tsconfig-google.json (#900) (9b37243)
  • Support Node 18+ (#896) (f011fa3)
  • Update '.prettierrc.json' to include trailingComma: "all" to match internal Google config (#822) (27d0d93)
  • Update typescript and other dependencies (#902) (1c18b3a)

Bug Fixes

  • deps: update dependency eslint to v8.57.1 (#903) (23da8ef)
  • deps: update dependency eslint-plugin-prettier to v5.2.1 (#894) (a6d5e6a)
  • deps: update dependency prettier to v3.3.3 (#883) (52dca7c)

5.3.1 (2024-04-10)

Bug Fixes

  • deps: replace dependency eslint-plugin-node with eslint-plugin-n (#865) (efbe3a8)
  • deps: update dependency eslint to v8.57.0 (#833) (0c0a45c)
  • deps: update dependency prettier to v3.2.5 (#846) (7e60e38)

Performance Improvements

  • Supercharge Performance & Efficiency: Leveraging Promise.all for Resource-Friendly Tasks 🚤 (#838) (7424fe1)

5.3.0 (2024-03-21)

Features

Bug Fixes

  • deps: update dependency eslint to v8.51.0 (#812) (ae913c1)
  • deps: update dependency eslint to v8.52.0 (#821) (50b3ce5)
  • deps: update dependency eslint to v8.53.0 (#829) (7d9ffed)
  • deps: update dependency eslint-config-prettier to v9.1.0 (#836) (9105ebb)
  • deps: update dependency eslint-plugin-prettier to v5.0.1 (#817) (89b8955)
  • deps: update dependency eslint-plugin-prettier to v5.1.2 (#839) (b5ab5c4)
  • deps: update dependency eslint-plugin-prettier to v5.1.3 (#845) (6e13e12)
  • deps: update dependency prettier to v3.1.0 (#832) (faf6d7e)
  • deps: update dependency prettier to v3.1.1 (#837) (6de3e3b)

5.2.0 (2023-10-04)

Features

5.1.1 (2023-10-04)

Bug Fixes

  • revert feat: no-floating-promises (44de7f7)

5.1.0 (2023-09-29)

Features

Bug Fixes

  • deps: update dependency eslint to v8.49.0 (#784) (5e2a05c)
  • deps: update dependency eslint to v8.50.0 (#802) (794abf3)
  • deps: update dependency eslint-config-prettier to v8.10.0 (#785) (5391d89)
  • deps: update dependency eslint-config-prettier to v9 (#777) (470977a)
  • deps: update dependency prettier to v3.0.3 (#782) (5a04e76)
  • run eslint from PATH (#654) (5dc2a76)

5.0.1 (2023-08-21)

Bug Fixes

  • line up linting with owlbot post-processing linting (#778) (a731fe9)

5.0.0 (2023-07-26)

⚠ BREAKING CHANGES

  • Upgrade to node 14 as the minimum version (#771)

Bug Fixes

  • deps: update dependency prettier to ~2.8.0 (#743) (7582516)
  • update eslint-prettier (43d4a06)

Miscellaneous Chores

  • Upgrade to node 14 as the minimum version (#771) (6301178)

4.0.1 (2023-01-09)

Bug Fixes

  • deps: bump json5 from 2.2.1 to 2.2.2 addressing CVE-2022-46175 (2a1fd61)

4.0.0 (2022-07-04)

⚠ BREAKING CHANGES

  • drop support for node.js 10.x (#686)

Features

Bug Fixes

  • deps: update dependency eslint-config-prettier to v8 (#624) (23a4abb)
  • deps: update dependency eslint-plugin-prettier to v4 (#657) (5408bfe)
  • deps: update dependency prettier to ~2.5.0 (#660) (8789fd4)
  • deps: update dependency prettier to ~2.6.0 (#670) (2feba2c)
  • deps: update dependency prettier to ~2.7.0 (#696) (3c677fd)
  • deps: update dependency write-file-atomic to v4 (#687) (f16a3e1)
  • deps: update typescript-eslint monorepo to v5 (#688) (ed2fd0c)
  • deps: upgrade to eslint 8.x (#693) (7ae5c8b)
  • drop update notifier (#706) (cab7704)
  • pin prettier to 2.3.x (#641) (323fb4a)

Build System

3.1.0 (2021-01-11)

Features

Bug Fixes

  • deps: update dependency eslint-config-prettier to v7 (#601) (6e26681)
  • deps: upgrade to latest version of meow (#616) (634bad9)

3.0.3 (2020-12-03)

Bug Fixes

3.0.2 (2020-10-26)

Bug Fixes

3.0.1 (2020-10-12)

Bug Fixes

  • rule: turn off @typescript-eslint/no-var-requires (#578) (3b37229)

3.0.0 (2020-10-08)

⚠ BREAKING CHANGES

  • change default check to lint (#570)
  • deps: require TypeScript 4.x (#565)

Features

Bug Fixes

  • add build/.eslintrc.json to files field (#553) (3b516ad)
  • deps: require TypeScript 4.x (#565) (cbc5267)
  • deps: update dependency update-notifier to v5 (#574) (9a882bf)
  • deps: update typescript-eslint monorepo to v2.34.0 (#509) (998a4ac)
  • deps: update typescript-eslint monorepo to v3 (major) (#528) (e22e173)
  • deps: update typescript-eslint monorepo to v4 (#556) (54148df)
  • better error message for broken tsconfig.json (#501) (0c17a76)
  • prohibit calls for it.only and describe.only (#499) (071c33c)

2.0.2 (2020-05-11)

Bug Fixes

  • Revert 'update dependency eslint to v7'" (#507) (0f9950b)
  • deps: pin release of eslint-typescript (#508) (bd86b42)
  • deps: update dependency eslint to v7 (#504) (6aee159)

2.0.1 (2020-05-07)

Bug Fixes

  • throw an error if running with an unsupported version of nodejs (#493) (94fdf1e)
  • deps: update dependency meow to v7 (#502) (cf91cda)

2.0.0 (2020-04-02)

⚠ BREAKING CHANGES ⚠

This is a major rewrite of the tool. Based on community guidance, we've switched from using tslint to eslint. Please read all of the steps below to upgrade.

Configuring eslint

With the shift to eslint, gts now will format and lint JavaScript as well as TypeScript. Upgrading will require a number of manual steps. To format JavaScript and TypeScript, you can run:

$ npx gts fix

To specify only TypeScript:

$ npx gts fix '**/*.ts'

Delete tslint.json

This file is no longer used, and can lead to confusion.

Create a .eslintrc.json

Now that we're using eslint, you need to extend the eslint configuration baked into the module. Create a new file named .eslintrc.json, and paste the following:

{
  "extends": "./node_modules/gts"
}

Create a .eslintignore

The .eslintignore file lets you ignore specific directories. This tool now lints and formats JavaScript, so it's really important to ignore your build directory! Here is an example of a .eslintignore file:

**/node_modules
build/

Rule changes

The underlying linter was changed, so naturally there are going to be a variety of rule changes along the way. To see the full list, check out .eslintrc.json.

Require Node.js 10.x and up

Node.js 8.x is now end of life - this module now requires Ndoe.js 10.x and up.

Features

Bug Fixes

1.1.2 (2019-11-20)

Bug Fixes

  • deps: update to newest prettier (with support for optional chain) (#396) (ce8ad06)

1.1.1 (2019-11-11)

Bug Fixes

  • deps: update dependency chalk to v3 (#389) (1ce0f45)
  • deps: update dependency inquirer to v7 (#377) (bf2c349)
  • deps: update dependency rimraf to v3 (#374) (2058eaa)
  • deps: update dependency write-file-atomic to v3 (#353) (59e6aa8)