@carnesen/tslint-config
v0.2.0
Published
tslint sharable config for carnesen projects
Downloads
17
Readme
@carnesen/tslint-config
TSLint configurations for @carnesen
projects
Install
These instructions assume that you're already using TypeScript and are now just adding tslint
.
npm install --save-dev tslint @carnesen/tslint-config
Usage
Create a file tslint.json
at the root of your project with contents:
{
"extends": [
"@carnesen/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.
Rules
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.
Here are some projects that make use of this one if you want to see some code looks like that adhere to these rules:
- @carnesen/bitcoin-config: Constants, utilities, and TypeScript types for bitcoin server software configuration with Node.js
- @carnesen/cli: A library for building Node.js command-line interfaces
- @carnesen/coded-error: An enhanced
Error
class with additional properties "code" and "data"
Related
- @carnesen/tsconfig: TypeScript configurations for @carnesen projects
More information
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.
License
MIT © Chris Arnesen