TypeScript stylistic rules for ESLint providing comprehensive code style enforcement for modern ESLint configurations.
—
Collection of 25 TypeScript-specific formatting and style rules for comprehensive code style enforcement. These rules cover spacing, indentation, quotes, semicolons, object/array formatting, and TypeScript-specific constructs.
Rules that enforce consistent spacing in TypeScript code.
Disallow or enforce spaces inside of blocks after opening block and before closing block.
/**
* Disallow or enforce spaces inside of blocks after opening block and before closing block
* @see https://eslint.style/rules/ts/block-spacing
*/
"block-spacing": BlockSpacingRuleOptions;
type BlockSpacingRuleOptions = ["always" | "never"];Enforce consistent spacing before and after commas.
/**
* Enforce consistent spacing before and after commas
* @see https://eslint.style/rules/ts/comma-spacing
*/
"comma-spacing": CommaSpacingRuleOptions;
interface CommaSpacingRuleOptions {
before?: boolean;
after?: boolean;
}Require or disallow spacing between function identifiers and their invocations.
/**
* Require or disallow spacing between function identifiers and their invocations
* @see https://eslint.style/rules/ts/function-call-spacing
*/
"func-call-spacing": FunctionCallSpacingRuleOptions;
"function-call-spacing": FunctionCallSpacingRuleOptions; // Alias
type FunctionCallSpacingRuleOptions =
| ["never"]
| ["always", { allowNewlines?: boolean }];Enforce consistent spacing between property names and type annotations in types and interfaces.
/**
* Enforce consistent spacing between property names and type annotations
* @see https://eslint.style/rules/ts/key-spacing
*/
"key-spacing": KeySpacingRuleOptions;
interface KeySpacingRuleOptions {
beforeColon?: boolean;
afterColon?: boolean;
mode?: "strict" | "minimum";
align?: "value" | "colon";
}Enforce consistent spacing before and after keywords.
/**
* Enforce consistent spacing before and after keywords
* @see https://eslint.style/rules/ts/keyword-spacing
*/
"keyword-spacing": KeywordSpacingRuleOptions;
interface KeywordSpacingRuleOptions {
before?: boolean;
after?: boolean;
overrides?: Record<string, { before?: boolean; after?: boolean }>;
}Enforce consistent spacing before and after semicolons.
/**
* Enforce consistent spacing before and after semicolons
* @see https://eslint.style/rules/ts/semi-spacing
*/
"semi-spacing": SemiSpacingRuleOptions;
interface SemiSpacingRuleOptions {
before?: boolean;
after?: boolean;
}Enforce consistent spacing before blocks.
/**
* Enforce consistent spacing before blocks
* @see https://eslint.style/rules/ts/space-before-blocks
*/
"space-before-blocks": SpaceBeforeBlocksRuleOptions;
type SpaceBeforeBlocksRuleOptions =
| "always"
| "never"
| {
functions?: "always" | "never";
keywords?: "always" | "never";
classes?: "always" | "never";
};Enforce consistent spacing before function parenthesis.
/**
* Enforce consistent spacing before function parenthesis
* @see https://eslint.style/rules/ts/space-before-function-paren
*/
"space-before-function-paren": SpaceBeforeFunctionParenRuleOptions;
type SpaceBeforeFunctionParenRuleOptions =
| "always"
| "never"
| {
anonymous?: "always" | "never" | "ignore";
named?: "always" | "never" | "ignore";
asyncArrow?: "always" | "never" | "ignore";
};Require spacing around infix operators.
/**
* Require spacing around infix operators
* @see https://eslint.style/rules/ts/space-infix-ops
*/
"space-infix-ops": SpaceInfixOpsRuleOptions;
interface SpaceInfixOpsRuleOptions {
int32Hint?: boolean;
}Require consistent spacing around type annotations.
/**
* Require consistent spacing around type annotations
* @see https://eslint.style/rules/ts/type-annotation-spacing
*/
"type-annotation-spacing": TypeAnnotationSpacingRuleOptions;
interface TypeAnnotationSpacingRuleOptions {
before?: boolean;
after?: boolean;
overrides?: {
colon?: { before?: boolean; after?: boolean };
arrow?: { before?: boolean; after?: boolean };
variable?: { before?: boolean; after?: boolean };
parameter?: { before?: boolean; after?: boolean };
property?: { before?: boolean; after?: boolean };
returnType?: { before?: boolean; after?: boolean };
};
}Rules that enforce consistent code style and formatting.
Enforce consistent brace style for blocks.
/**
* Enforce consistent brace style for blocks
* @see https://eslint.style/rules/ts/brace-style
*/
"brace-style": BraceStyleRuleOptions;
type BraceStyleRuleOptions =
| ["1tbs", { allowSingleLine?: boolean }]
| ["stroustrup", { allowSingleLine?: boolean }]
| ["allman", { allowSingleLine?: boolean }];Require or disallow trailing commas.
/**
* Require or disallow trailing commas
* @see https://eslint.style/rules/ts/comma-dangle
*/
"comma-dangle": CommaDangleRuleOptions;
type CommaDangleRuleOptions =
| "never"
| "always"
| "always-multiline"
| "only-multiline"
| {
arrays?: "never" | "always" | "always-multiline" | "only-multiline";
objects?: "never" | "always" | "always-multiline" | "only-multiline";
imports?: "never" | "always" | "always-multiline" | "only-multiline";
exports?: "never" | "always" | "always-multiline" | "only-multiline";
functions?: "never" | "always" | "always-multiline" | "only-multiline";
enums?: "never" | "always" | "always-multiline" | "only-multiline";
generics?: "never" | "always" | "always-multiline" | "only-multiline";
tuples?: "never" | "always" | "always-multiline" | "only-multiline";
};Enforce consistent indentation.
/**
* Enforce consistent indentation
* @see https://eslint.style/rules/ts/indent
*/
"indent": IndentRuleOptions;
type IndentRuleOptions = [
number | "tab",
{
SwitchCase?: number;
VariableDeclarator?: number | { var?: number; let?: number; const?: number };
outerIIFEBody?: number;
MemberExpression?: number | "off";
FunctionDeclaration?: { parameters?: number | "first" | "off"; body?: number };
FunctionExpression?: { parameters?: number | "first" | "off"; body?: number };
CallExpression?: { arguments?: number | "first" | "off" };
ArrayExpression?: number | "first" | "off";
ObjectExpression?: number | "first" | "off";
ImportDeclaration?: number | "first" | "off";
flatTernaryExpressions?: boolean;
offsetTernaryExpressions?: boolean;
ignoredNodes?: string[];
ignoreComments?: boolean;
}?
];Require a specific member delimiter style for interfaces and type literals.
/**
* Require a specific member delimiter style for interfaces and type literals
* @see https://eslint.style/rules/ts/member-delimiter-style
*/
"member-delimiter-style": MemberDelimiterStyleRuleOptions;
interface MemberDelimiterStyleRuleOptions {
multiline?: {
delimiter?: "none" | "semi" | "comma";
requireLast?: boolean;
};
singleline?: {
delimiter?: "semi" | "comma";
requireLast?: boolean;
};
overrides?: {
interface?: MemberDelimiterConfig;
typeLiteral?: MemberDelimiterConfig;
};
multilineDetection?: "brackets" | "last-member";
}
interface MemberDelimiterConfig {
multiline?: {
delimiter?: "none" | "semi" | "comma";
requireLast?: boolean;
};
singleline?: {
delimiter?: "semi" | "comma";
requireLast?: boolean;
};
}Require quotes around object literal, type literal, interfaces and enums property names.
/**
* Require quotes around object literal property names
* @see https://eslint.style/rules/ts/quote-props
*/
"quote-props": QuotePropsRuleOptions;
type QuotePropsRuleOptions =
| ["always"]
| ["as-needed", { keywords?: boolean; unnecessary?: boolean; numbers?: boolean }]
| ["consistent"]
| ["consistent-as-needed", { keywords?: boolean }];Enforce the consistent use of either backticks, double, or single quotes.
/**
* Enforce the consistent use of quotes
* @see https://eslint.style/rules/ts/quotes
*/
"quotes": QuotesRuleOptions;
type QuotesRuleOptions = [
"single" | "double" | "backtick",
{
avoidEscape?: boolean;
allowTemplateLiterals?: boolean;
}?
];Require or disallow semicolons instead of ASI.
/**
* Require or disallow semicolons instead of ASI
* @see https://eslint.style/rules/ts/semi
*/
"semi": SemiRuleOptions;
type SemiRuleOptions =
| ["always", { omitLastInOneLineBlock?: boolean; omitLastInOneLineClassBody?: boolean }]
| ["never", { beforeStatementContinuationChars?: "always" | "any" | "never" }];Rules for formatting objects and arrays.
Enforce consistent line breaks after opening and before closing braces.
/**
* Enforce consistent line breaks after opening and before closing braces
* @see https://eslint.style/rules/ts/object-curly-newline
*/
"object-curly-newline": ObjectCurlyNewlineRuleOptions;
type ObjectCurlyNewlineRuleOptions =
| "always"
| "never"
| {
ObjectExpression?: "always" | "never" | { multiline?: boolean; minProperties?: number; consistent?: boolean };
ObjectPattern?: "always" | "never" | { multiline?: boolean; minProperties?: number; consistent?: boolean };
ImportDeclaration?: "always" | "never" | { multiline?: boolean; minProperties?: number; consistent?: boolean };
ExportDeclaration?: "always" | "never" | { multiline?: boolean; minProperties?: number; consistent?: boolean };
};Enforce consistent spacing inside braces.
/**
* Enforce consistent spacing inside braces
* @see https://eslint.style/rules/ts/object-curly-spacing
*/
"object-curly-spacing": ObjectCurlySpacingRuleOptions;
type ObjectCurlySpacingRuleOptions = [
"always" | "never",
{
arraysInObjects?: boolean;
objectsInObjects?: boolean;
}?
];Enforce placing object properties on separate lines.
/**
* Enforce placing object properties on separate lines
* @see https://eslint.style/rules/ts/object-property-newline
*/
"object-property-newline": ObjectPropertyNewlineRuleOptions;
interface ObjectPropertyNewlineRuleOptions {
allowAllPropertiesOnSameLine?: boolean;
allowMultiplePropertiesPerLine?: boolean;
}Rules for handling parentheses usage.
Disallow unnecessary parentheses.
/**
* Disallow unnecessary parentheses
* @see https://eslint.style/rules/ts/no-extra-parens
*/
"no-extra-parens": NoExtraParensRuleOptions;
type NoExtraParensRuleOptions =
| ["all"]
| ["all", {
conditionalAssign?: boolean;
returnAssign?: boolean;
nestedBinaryExpressions?: boolean;
ignoreJSX?: "none" | "all" | "single-line" | "multi-line";
enforceForArrowConditionals?: boolean;
enforceForSequenceExpressions?: boolean;
enforceForNewInMemberExpressions?: boolean;
enforceForFunctionPrototypeMethods?: boolean;
}]
| ["functions"];Disallow unnecessary semicolons.
/**
* Disallow unnecessary semicolons
* @see https://eslint.style/rules/ts/no-extra-semi
*/
"no-extra-semi": NoExtraSemiRuleOptions;
type NoExtraSemiRuleOptions = [];Rules for managing line breaks and spacing between statements.
Require empty lines around comments.
/**
* Require empty lines around comments
* @see https://eslint.style/rules/ts/lines-around-comment
*/
"lines-around-comment": LinesAroundCommentRuleOptions;
interface LinesAroundCommentRuleOptions {
beforeBlockComment?: boolean;
afterBlockComment?: boolean;
beforeLineComment?: boolean;
afterLineComment?: boolean;
allowBlockStart?: boolean;
allowBlockEnd?: boolean;
allowObjectStart?: boolean;
allowObjectEnd?: boolean;
allowArrayStart?: boolean;
allowArrayEnd?: boolean;
allowClassStart?: boolean;
allowClassEnd?: boolean;
ignorePattern?: string;
applyDefaultIgnorePatterns?: boolean;
}Require or disallow an empty line between class members.
/**
* Require or disallow an empty line between class members
* @see https://eslint.style/rules/ts/lines-between-class-members
*/
"lines-between-class-members": LinesBetweenClassMembersRuleOptions;
type LinesBetweenClassMembersRuleOptions = [
"always" | "never",
{
exceptAfterSingleLine?: boolean;
exceptAfterOverload?: boolean;
}?
];Require or disallow padding lines between statements.
/**
* Require or disallow padding lines between statements
* @see https://eslint.style/rules/ts/padding-line-between-statements
*/
"padding-line-between-statements": PaddingLineBetweenStatementsRuleOptions;
type PaddingLineBetweenStatementsRuleOptions = Array<{
blankLine: "always" | "never" | "any";
prev: StatementType | StatementType[];
next: StatementType | StatementType[];
}>;
type StatementType =
| "block-like"
| "exports"
| "require"
| "directive"
| "expression"
| "iife"
| "multiline-block-like"
| "multiline-expression"
| "multiline-const"
| "multiline-let"
| "multiline-var"
| "singleline-const"
| "singleline-let"
| "singleline-var"
| "block"
| "empty"
| "function"
| "break"
| "case"
| "class"
| "const"
| "continue"
| "debugger"
| "default"
| "do"
| "export"
| "for"
| "if"
| "import"
| "let"
| "return"
| "switch"
| "throw"
| "try"
| "var"
| "while"
| "with"
| "interface"
| "type";import stylistic from "@stylistic/eslint-plugin-ts";
export default [
{
plugins: {
"@stylistic/ts": stylistic,
},
rules: {
// Spacing rules
"@stylistic/ts/block-spacing": "error",
"@stylistic/ts/comma-spacing": ["error", { before: false, after: true }],
"@stylistic/ts/key-spacing": ["error", { beforeColon: false, afterColon: true }],
// Style rules
"@stylistic/ts/brace-style": ["error", "1tbs", { allowSingleLine: true }],
"@stylistic/ts/comma-dangle": ["error", "always-multiline"],
"@stylistic/ts/indent": ["error", 2],
"@stylistic/ts/quotes": ["error", "single"],
"@stylistic/ts/semi": ["error", "always"],
// TypeScript specific
"@stylistic/ts/member-delimiter-style": ["error", {
multiline: { delimiter: "semi", requireLast: true },
singleline: { delimiter: "semi", requireLast: false },
}],
"@stylistic/ts/type-annotation-spacing": ["error", {
before: false,
after: true,
}],
},
},
];import stylistic from "@stylistic/eslint-plugin-ts";
export default [
{
plugins: {
"@stylistic/ts": stylistic,
},
rules: {
// Object/Array formatting
"@stylistic/ts/object-curly-spacing": ["error", "always"],
"@stylistic/ts/object-curly-newline": ["error", {
ObjectExpression: { multiline: true, consistent: true },
ObjectPattern: { multiline: true, consistent: true },
}],
"@stylistic/ts/object-property-newline": ["error", {
allowAllPropertiesOnSameLine: false,
}],
// Function spacing
"@stylistic/ts/function-call-spacing": ["error", "never"],
"@stylistic/ts/space-before-function-paren": ["error", {
anonymous: "always",
named: "never",
asyncArrow: "always",
}],
// Line management
"@stylistic/ts/lines-between-class-members": ["error", "always", {
exceptAfterSingleLine: true,
exceptAfterOverload: true,
}],
"@stylistic/ts/padding-line-between-statements": ["error",
{ blankLine: "always", prev: "import", next: "*" },
{ blankLine: "never", prev: "import", next: "import" },
{ blankLine: "always", prev: "*", next: "export" },
],
// Parentheses
"@stylistic/ts/no-extra-parens": ["error", "all", {
ignoreJSX: "multi-line",
enforceForArrowConditionals: false,
}],
"@stylistic/ts/no-extra-semi": "error",
},
},
];Install with Tessl CLI
npx tessl i tessl/npm-stylistic--eslint-plugin-ts