https://github.com/webschik/tslint-import-rules
Set of TSLint rules that help validate proper imports.
https://github.com/webschik/tslint-import-rules
import tslint tslint-rules
Last synced: 10 months ago
JSON representation
Set of TSLint rules that help validate proper imports.
- Host: GitHub
- URL: https://github.com/webschik/tslint-import-rules
- Owner: webschik
- License: mit
- Created: 2018-06-02T11:57:46.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-27T13:31:21.000Z (almost 7 years ago)
- Last Synced: 2025-03-23T13:36:50.533Z (10 months ago)
- Topics: import, tslint, tslint-rules
- Language: TypeScript
- Size: 22.5 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# tslint-import-rules
Set of TSLint rules that help validate proper imports.
[](https://travis-ci.org/webschik/tslint-import-rules)
[](https://www.npmjs.com/package/tslint-import-rules)
[](https://www.npmjs.com/package/tslint-import-rules)
[](https://www.npmjs.com/package/tslint-import-rules)
Inspired by [eslint-plugin-import](https://github.com/benmosher/eslint-plugin-import)
## How to use
* Install package:
```
npm i --save-dev tslint-import-rules
```
* Update your tslint.json:
```json
{
"rulesDirectory": ["node_modules/tslint-import-rules/dist/rules"]
}
```
## Rules
All rules start from the prefix `tir-` (TSLint Import Rules) to prevent name collisions.
### `tir-spaces-within-import`
Controls spaces within import clauses
#### Usage
##### Disable spaces within import
```json
{
"tir-spaces-within-import": [true, "never"]
}
```
**Valid:**
```js
import {bar} from 'bar';
import {
foo1,
foo2
} from 'foo';
```
**Invalid:**
```js
import { bar } from 'bar';
```
##### Enable spaces within import
```json
{
"tir-spaces-within-import": [true]
}
```
**Valid:**
```js
import { bar } from 'bar';
import {
foo1,
foo2
} from 'foo';
```
**Invalid:**
```js
import {bar} from 'bar';
```
##### Enable custom spaces count within import
```json
{
"tir-spaces-within-import": [true, "always", {"count": 2}]
}
```
**Valid:**
```js
import { bar } from 'bar';
import {
foo1,
foo2
} from 'foo';
```
**Invalid:**
```js
import {foo} from 'foo';
import { bar } from 'bar';
```
### `tir-no-empty-line-between-imports`
Prevents having empty lines between import declarations.
This rule has one option, `count` which sets the number of spaces.
This option defaults to 1.
#### Valid
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
#### Invalid
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
### `tir-newline-after-import`
Enforces having one or more empty lines after the last top-level import statement.
This rule has one option, `count` which sets the number of newlines that are enforced after the last top-level import statement or require call.
This option defaults to 1.
#### Usage
##### Disable empty lines after import
```json
{
"tir-newline-after-import": [true, "never"]
}
```
**Valid:**
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
**Invalid:**
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
##### Force 1 empty line after import
```json
{
"tir-newline-after-import": [true]
}
```
**Valid:**
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
**Invalid:**
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```
##### Force 3 empty lines after import
```json
{
"tir-newline-after-import": [true, "always", {"count": 3}]
}
```
**Valid:**
```js
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
```