What is gts?
The gts (Google TypeScript Style) npm package is a toolkit for setting up and maintaining a consistent TypeScript code style in your projects. It includes configurations for TypeScript, ESLint, and Prettier, and provides scripts for formatting and linting your code.
What are gts's main functionalities?
Setup
Initializes a new TypeScript project with Google TypeScript Style configurations. This command sets up the necessary configuration files and dependencies.
npx gts init
Linting
Runs ESLint with the Google TypeScript Style configurations to check for code style issues and potential errors in your TypeScript code.
npx gts lint
Formatting
Formats your TypeScript code according to the Google TypeScript Style guidelines using Prettier. This command can also fix some linting issues automatically.
npx gts fix
TypeScript Compilation
Compiles your TypeScript code to JavaScript using the TypeScript compiler with the configurations provided by gts.
npx gts build
Other packages similar to gts
eslint
ESLint is a widely-used tool for identifying and fixing problems in JavaScript and TypeScript code. While gts uses ESLint under the hood, ESLint itself is more flexible and can be configured to use various style guides and rulesets.
prettier
Prettier is an opinionated code formatter that supports many languages, including TypeScript. gts uses Prettier for formatting, but Prettier can be used independently or with other style guides.
tslint
TSLint is a linter specifically for TypeScript. Although it has been deprecated in favor of ESLint, it was previously a popular choice for TypeScript projects. gts uses ESLint, which is now the recommended tool for linting TypeScript.
typescript-eslint
typescript-eslint is a set of tools that allows ESLint to run on TypeScript code. It provides the necessary parser and plugins to lint TypeScript effectively. gts uses typescript-eslint as part of its setup.
gts
Google TypeScript Style
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 tslint 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
:
check
: 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 check index.ts
gts check one.ts two.ts three.ts
gts check *.ts
Badge
Show your love for gts
and include a badge!
[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)
License
Apache-2.0
Made with ❤️ by the Google Node.js team.
NOTE: This is not an official Google product.