TSLint configurations for alwaysAI projects
These instructions assume that you're already using TypeScript and are now just adding tslint
.
Use npm
or yarn
to install this package:
npm install --save-dev tslint @alwaysai/tslint-config
Create a file tslint.json
at the root of your project with contents:
{
"extends": [
"@alwaysai/tslint-config"
]
}
That tells TSLint to use the "main" export of this package, its tslint.json
file. Add these lines to your package.json
's "scripts" field:
"lint": "tslint --project .",
"lint:fix": "npm run lint -- --fix",
Finally add && npm run lint
to your package's "test" script to make sure you don't forget to lint! I strongly recommend setting up your editor to automatically fix lint errors on save. That makes it so that the linter mostly stays out of your way. In Visual Studio Code, this plugin works great.
This package's rules extend those espoused by by AirBnB, consumed as tslint-config-airbnb. Those rules are mostly concerned with syntax. For code formatting, this package uses tslint-config-prettier
, which disables all rules that are unnecessary or might conflict with Prettier in conjunction with tslint-plugin-prettier
, which "runs Prettier as a TSLint rule and reports differences as individual TSLint issues". I wrote up some thoughts here on why that's a much better approach than using tslint
and prettier
separately. Finally this configuration also enables the dtslint "expect" rule, which allows you to make type assertions that are checked at the same time as the lint rules:
// $ExpectType "foo"
'foo';
// $ExpectType string[]
['foo', 'bar', 'baz'];
These are a nice way of writing programmatic tests for types beyond what you can achieve with unit testing alone.
- @alwaysai/tsconfig: TypeScript configurations for alwaysAI projects
If you encounter any bugs or have any questions or feature requests, please don't hesitate to file an issue or submit a pull request on this project's repository on GitHub.
MIT © alwaysAI, Inc.