This package includes extended eslint rules for usage with Typescript.
Name | Description |
---|---|
array-type-spacing | Enforces correct spacing between type name and square brackets of array types. |
type-parameter-spacing | Enforces correct spacing between an identifier and type parameters. |
This rule enforces correct spacing between type name and square brackets of array types. It also enforces no spaces between the square brackets.
🔧 The --fix
option on the command line can automatically fix the problems reported by this rule.
This rule takes one option:
- "never" (default) enforces no space between type name and square brackets.
- "always" enforces exactly one space between type name and square brackets.
"array-type-spacing": ["warn", "never"]
never:
👎 Examples of incorrect code for this rule:
const myVar: string [] = [];
function myFunc (parameter: number []) {
// ...
}
👍 Examples of correct code for this rule:
const myVar: string[] = [];
function myFunc (parameter: number[]) {
// ...
}
always:
👎 Examples of incorrect code for this rule:
const myVar: string[] = [];
function myFunc (parameter: number[]) {
// ...
}
👍 Examples of correct code for this rule:
const myVar: string [] = [];
function myFunc (parameter: number []) {
// ...
}
There is an optional configuration object:
betweenDimensions:
- "never" (default) enforces no space between consecutive square brackets.
- "always" enforces exactly one space between consecutive square brackets.
{
"betweenDimensions": "never"
}
betweenDimensions: "never":
👎 Examples of incorrect code for this rule:
const myVar: string[] [] = [];
function myFunc (parameter: number[] []) {
// ...
}
👍 Examples of correct code for this rule:
const myVar: string [][] = [];
function myFunc (parameter: number [][]) {
// ...
}
betweenDimensions: "always":
👎 Examples of incorrect code for this rule:
const myVar: string[][] = [];
function myFunc (parameter: number[][]) {
// ...
}
👍 Examples of correct code for this rule:
const myVar: string [] [] = [];
function myFunc (parameter: number [] []) {
// ...
}
This rule enforces correct spacing between an identifier and type parameters.
🔧 The --fix
option on the command line can automatically fix the problems reported by this rule.
This rule takes one option:
- "never" (default) enforces no space between identifier and type parameters.
- "always" enforces exactly one space between identifier and type parameters.
"type-parameter-spacing": ["warn", "never"]
never:
👎 Examples of incorrect code for this rule:
function generic <TType> (parameter: TType) {
// ...
}
interface Generic <TType> {
value: TType,
}
const value: GenericType <number>;
👍 Examples of correct code for this rule:
function generic<TType> (parameter: TType) {
// ...
}
interface Generic<TType> {
value: TType,
}
const value: GenericType<number>;
always:
👎 Examples of incorrect code for this rule:
function generic<TType> (parameter: TType) {
// ...
}
interface Generic<TType> {
value: TType,
}
const value: GenericType<number>;
👍 Examples of correct code for this rule:
function generic <TType> (parameter: TType) {
// ...
}
interface Generic <TType> {
value: TType,
}
const value: GenericType <number>;