@carnesen/tslint-config

0.2.0 • Public • Published

@carnesen/tslint-config Build Status

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:

Related

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

Readme

Keywords

none

Package Sidebar

Install

npm i @carnesen/tslint-config

Weekly Downloads

10

Version

0.2.0

License

MIT

Unpacked Size

6.97 kB

Total Files

10

Last publish

Collaborators

  • carnesen