Set of TSLint rules that help validate proper imports.
Inspired by eslint-plugin-import
- Install package:
npm i --save-dev tslint-import-rules
- Update your tslint.json:
{
"rulesDirectory": ["node_modules/tslint-import-rules/dist/rules"]
}
All rules start from the prefix tir-
(TSLint Import Rules) to prevent name collisions.
Controls spaces within import clauses
{
"tir-spaces-within-import": [true, "never"]
}
Valid:
import {bar} from 'bar';
import {
foo1,
foo2
} from 'foo';
Invalid:
import { bar } from 'bar';
{
"tir-spaces-within-import": [true]
}
Valid:
import { bar } from 'bar';
import {
foo1,
foo2
} from 'foo';
Invalid:
import {bar} from 'bar';
{
"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';
Prevents having empty lines between import declarations.
This rule has one option, count
which sets the number of spaces.
This option defaults to 1.
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';
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.
{
"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';
{
"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';
{
"tir-newline-after-import": [true, "always", {"count": 3}]
}
Valid:
import * as bar from 'bar';
import * as foo from 'foo';
const FOO = 'BAR';