0.3.0 • Published 6 years ago

tslint-import-rules v0.3.0

Weekly downloads
72
License
MIT
Repository
github
Last release
6 years ago

tslint-import-rules

Set of TSLint rules that help validate proper imports.

Build Status npm npm npm

Inspired by eslint-plugin-import

How to use

  • Install package:
npm i --save-dev tslint-import-rules
  • Update your tslint.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
    {
      "tir-spaces-within-import": [true, "never"]
    }

Valid:

import {bar} from 'bar';
import {
    foo1,
    foo2
} from 'foo';

Invalid:

import { bar } from 'bar';
Enable spaces within import
    {
      "tir-spaces-within-import": [true]
    }

Valid:

import { bar } from 'bar';
import {
    foo1,
    foo2
} from 'foo';

Invalid:

import {bar} from 'bar';
Enable custom spaces count within import
    {
      "tir-spaces-within-import": [true, "always", {"count": 2}]
    }

Valid:

import {  bar  } from 'bar';
import {
    foo1,
    foo2
} from 'foo';

Invalid:

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

import * as bar from 'bar';
import * as foo from 'foo';

const FOO = 'BAR';

Invalid

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
    {
      "tir-newline-after-import": [true, "never"]
    }

Valid:

import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';

Invalid:

import * as bar from 'bar';
import * as foo from 'foo';

const FOO = 'BAR';
Force 1 empty line after import
    {
      "tir-newline-after-import": [true]
    }

Valid:

import * as bar from 'bar';
import * as foo from 'foo';

const FOO = 'BAR';

Invalid:

import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';
import * as bar from 'bar';
import * as foo from 'foo';


const FOO = 'BAR';
Force 3 empty lines after import
    {
      "tir-newline-after-import": [true, "always", {"count": 3}]
    }

Valid:

import * as bar from 'bar';
import * as foo from 'foo';



const FOO = 'BAR';