# tslint-origin-ordered-imports-rule

> tslint rule to check order of imports

Latest version **2.0.0** (published 2021-08-17) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tslint-origin-ordered-imports-rule
pnpm add tslint-origin-ordered-imports-rule
yarn add tslint-origin-ordered-imports-rule
bun add tslint-origin-ordered-imports-rule
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-08-17 |
| First published | 2017-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 33.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | Oleg Krasavin |
| Maintainers | marcuzy |
| Keywords | tslint, rule, imports, imports origin, imports order, check imports, typescript |

## Links

- npm: https://www.npmjs.com/package/tslint-origin-ordered-imports-rule
- Repository: https://github.com/marcuzy/tslint-origin-ordered-imports-rule
- Homepage: https://github.com/marcuzy/tslint-origin-ordered-imports-rule#readme
- Issues: https://github.com/marcuzy/tslint-origin-ordered-imports-rule/issues
- npm.io page: https://npm.io/package/tslint-origin-ordered-imports-rule

## Dependencies (1)

- [tsutils](https://npm.io/package/tsutils.md) ^3.21.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2021-08-17
- 1.2.0-beta.3 (beta) — 2019-03-18
- 1.3.0-0 — 2020-05-05
- 1.2.2 — 2019-05-20
- 1.2.1 — 2019-04-22
- 1.2.0 — 2019-03-26
- 1.2.0-beta.1 — 2019-03-18
- 1.2.0-beta.0 — 2019-03-18
- 1.1.2 — 2018-06-13
- 1.1.1 — 2018-06-08
- 1.1.0 — 2018-06-08
- 1.0.4 — 2017-09-01
- 1.0.3 — 2017-07-16
- 1.0.2 — 2017-07-14
- 1.0.1 — 2017-02-22
- … 1 more at https://npm.io/package/tslint-origin-ordered-imports-rule/versions

## README

[![Build Status](https://travis-ci.com/marcuzy/tslint-origin-ordered-imports-rule.svg?branch=master)](https://travis-ci.com/marcuzy/tslint-origin-ordered-imports-rule)

# TSLint Origin Ordered Imports Rule
> Custom rule for tslint

Strict order for imports ("Lib import" must be higher than "User import") + your own import groups defined by regexps.

🚀 This plugin needs minimum configuration to start:

```shell
npm i -D tslint-origin-ordered-imports-rule
```

*tslint.json*
```json
"rulesDirectory": [
    "node_modules/tslint-origin-ordered-imports-rule/dist"
],
"rules": {
    "origin-ordered-imports": [ true ]
}
```

*Wrong:*
```ts
import MyClass from './my-class';
import * as _ from 'lodash';
```
*Right:*
```ts
import * as _ from 'lodash';
import MyClass from './my-class';
```

Then you might set `one-blank-line` option to require a blank line between import groups.
In such a case, the previous code becomes wrong.

*Right:*
```ts
import * as _ from 'lodash';

import MyClass from './my-class';
```
Apart from `one-blank-line`, there are a few other options:
* `no-blank-lines`
* `at-least-one-blank-line`
* `any-number-of-blank-lines`

This plugin was created to be as simple as possible, with zero-configuration. It could still be used in that way, but if you need more configurable tool just define the array which describes your own order.

*tsconfig.json*
```json
"rules": {
    "origin-ordered-imports": [ 
        true, 
        "one-blank-line",
        [
            "lib",
            "^@custom/.+",
            "user"
        ] 
    ]
}
```
*Wrong:*
```ts
import * as _ from 'lodash';
import * as moment from 'moment';

import MyClass from './my-class';
import MyClass2 from './my-class2';

import Foo from '@custom/foo';
import Bar from '@custom/bar';
```
*Right:*
```ts
import * as _ from 'lodash';
import * as moment from 'moment';

import Foo from '@custom/foo';
import Bar from '@custom/bar';

import MyClass from './my-class';
import MyClass2 from './my-class2';
```

Actually, you can omit `lib` and `user` items as they will be added automatically to the beginning and the ending respectively.

## Testing

To test the rule just run:

```sh
npm run compile
npm run test
```

## Licensing

The code in this project is licensed under MIT license.

---
_Source: https://npm.io/package/tslint-origin-ordered-imports-rule · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
