JavaScript stylistic rules for ESLint that enforce code formatting and style consistency without changing code logic.
—
Rules that control line breaks, empty lines, and multiline formatting for better code organization and readability.
Requires or disallows newline at the end of files.
const eolLast: Rule.RuleModule;
// Rule options
type EolLastOptions = 'always' | 'never' | 'unix' | 'windows';Usage Examples:
// ✓ Good with "always" (default)
const name = 'John';
const age = 30;
↵ // newline at end of file
// ✓ Good with "never"
const name = 'John';
const age = 30; // no newline at end
// ✓ Good with "unix"
const name = 'John';↵ // LF line ending
// ✓ Good with "windows"
const name = 'John';↵↩ // CRLF line endingConfiguration:
rules: {
'@stylistic/js/eol-last': ['error', 'always']
}Disallows multiple empty lines.
const noMultipleEmptyLines: Rule.RuleModule;
// Rule options
type NoMultipleEmptyLinesOptions = {
max: number;
maxEOF?: number;
maxBOF?: number;
};Usage Examples:
// ✓ Good with { max: 1 }
const first = 'value';
const second = 'value'; // one empty line OK
// ✗ Bad with { max: 1 }
const first = 'value';
const second = 'value'; // two empty lines not allowed
// ✓ Good with { max: 2, maxEOF: 0 }
const code = 'here';
const more = 'content'; // up to 2 empty lines in code
// end of file with no empty lines (maxEOF: 0)Configuration:
rules: {
'@stylistic/js/no-multiple-empty-lines': ['error', { max: 1, maxEOF: 1 }]
}Requires or disallows padding lines between statements.
const paddingLineBetweenStatements: Rule.RuleModule;
// Rule options
type PaddingLineBetweenStatementsOptions = 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'
| 'const'
| 'let'
| 'var'
| 'any'
| '*';Usage Examples:
// ✓ Good with padding between var declarations and other statements
const name = 'John';
const age = 30;
if (condition) {
doSomething();
}
return result;
// ✓ Good with no padding between similar statement types
const first = 'value';
const second = 'value';
const third = 'value';Configuration:
rules: {
'@stylistic/js/padding-line-between-statements': ['error',
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] }
]
}Requires empty lines around comments.
const linesAroundComment: Rule.RuleModule;
// Rule options
type LinesAroundCommentOptions = {
beforeBlockComment?: boolean;
afterBlockComment?: boolean;
beforeLineComment?: boolean;
afterLineComment?: boolean;
allowBlockStart?: boolean;
allowBlockEnd?: boolean;
allowObjectStart?: boolean;
allowObjectEnd?: boolean;
allowArrayStart?: boolean;
allowArrayEnd?: boolean;
allowClassStart?: boolean;
allowClassEnd?: boolean;
applyDefaultIgnorePatterns?: boolean;
ignorePattern?: string;
};Usage Examples:
// ✓ Good with beforeBlockComment: true, afterBlockComment: true
const value = 'test';
/*
* Block comment
*/
const other = 'value';
// ✓ Good with beforeLineComment: true
const first = 'value';
// Line comment
const second = 'value';
// ✓ Good with allowBlockStart: true
function example() {
// Comment allowed at block start
const value = 'test';
}Configuration:
rules: {
'@stylistic/js/lines-around-comment': ['error', {
beforeBlockComment: true,
afterBlockComment: true,
beforeLineComment: true,
allowBlockStart: true,
allowObjectStart: true
}]
}Requires or disallows an empty line between class members.
const linesBetweenClassMembers: Rule.RuleModule;
// Rule options
type LinesBetweenClassMembersOptions =
| 'always'
| 'never'
| ['always' | 'never', {
exceptAfterSingleLine?: boolean;
}];Usage Examples:
// ✓ Good with "always" (default)
class Example {
constructor() {
this.value = 0;
}
method1() {
return this.value;
}
method2() {
return this.value * 2;
}
}
// ✓ Good with { exceptAfterSingleLine: true }
class Example {
value = 0; // single line
name = 'test'; // single line, no padding needed
method() { // padding required before multiline members
return this.value;
}
}Configuration:
rules: {
'@stylistic/js/lines-between-class-members': ['error', 'always', {
exceptAfterSingleLine: true
}]
}Enforces consistent linebreak style.
const linebreakStyle: Rule.RuleModule;
// Rule options
type LinebreakStyleOptions = 'unix' | 'windows';Usage Examples:
// ✓ Good with "unix" (LF)
const name = 'John';↵
const age = 30;↵
// ✓ Good with "windows" (CRLF)
const name = 'John';↵↩
const age = 30;↵↩Configuration:
rules: {
'@stylistic/js/linebreak-style': ['error', 'unix']
}Requires a newline after each call in a method chain.
const newlinePerChainedCall: Rule.RuleModule;
// Rule options
type NewlinePerChainedCallOptions = {
ignoreChainWithDepth?: number;
};Usage Examples:
// ✓ Good with default settings
api
.get('/users')
.then(response => response.json())
.then(data => process(data))
.catch(handleError);
// ✓ Good with short chains
api.get('/users').then(process); // short chain OK
// ✓ Good with { ignoreChainWithDepth: 3 }
api.get('/users').then(process).catch(handleError); // under threshold
api
.get('/users')
.then(process)
.then(validate)
.catch(handleError); // meets thresholdConfiguration:
rules: {
'@stylistic/js/newline-per-chained-call': ['error', { ignoreChainWithDepth: 2 }]
}Enforces a particular style for multiline comments.
const multilineCommentStyle: Rule.RuleModule;
// Rule options
type MultilineCommentStyleOptions =
| 'starred-block'
| 'separate-lines'
| 'bare-block';Usage Examples:
// ✓ Good with "starred-block" (default)
/*
* This is a multiline comment
* with stars on each line
*/
// ✓ Good with "separate-lines"
// This is a multiline comment
// using separate line comments
// ✓ Good with "bare-block"
/*
This is a multiline comment
without stars on each line
*/Configuration:
rules: {
'@stylistic/js/multiline-comment-style': ['error', 'starred-block']
}Enforces consistent spacing after the // or /* in a comment.
const spacedComment: Rule.RuleModule;
// Rule options
type SpacedCommentOptions =
| 'always'
| 'never'
| ['always' | 'never', {
line?: {
markers?: string[];
exceptions?: string[];
};
block?: {
markers?: string[];
exceptions?: string[];
balanced?: boolean;
};
}];Usage Examples:
// ✓ Good with "always" (default)
// This is a line comment
/* This is a block comment */
// ✓ Good with "never"
//This is a line comment
/*This is a block comment*/
// ✓ Good with exceptions
//----- Section Header ----- (exception for dashes)
//TODO: Fix this (marker allowed)Configuration:
rules: {
'@stylistic/js/spaced-comment': ['error', 'always', {
markers: ['TODO', 'FIXME'],
exceptions: ['-', '=', '*']
}]
}Requires or disallows padding within blocks.
const paddedBlocks: Rule.RuleModule;
// Rule options
type PaddedBlocksOptions =
| 'always'
| 'never'
| {
blocks?: 'always' | 'never';
classes?: 'always' | 'never';
switches?: 'always' | 'never';
};Usage Examples:
// ✓ Good with "always"
function example() {
const value = 'test';
return value;
}
// ✓ Good with "never" (default)
function example() {
const value = 'test';
return value;
}
// ✓ Good with custom config
if (condition) {
doSomething(); // blocks: 'always'
}
class Example { // classes: 'never'
method() {
return true;
}
}Configuration:
rules: {
'@stylistic/js/padded-blocks': ['error', 'never']
}Enforces newlines between operands of ternary expressions.
const multilineTernary: Rule.RuleModule;
// Rule options
type MultilineTernaryOptions = 'always' | 'always-multiline' | 'never';Usage Examples:
// ✓ Good with "always-multiline"
const result = condition ? 'yes' : 'no'; // single line OK
const result = longConditionExpression
? 'yes'
: 'no'; // multiline requires newlines
// ✓ Good with "always"
const result = condition
? 'yes'
: 'no';
// ✓ Good with "never"
const result = condition ? 'yes' : 'no';
const result = longConditionExpression ? 'yes' : 'no'; // no newlinesConfiguration:
rules: {
'@stylistic/js/multiline-ternary': ['error', 'always-multiline']
}rules: {
'@stylistic/js/eol-last': ['error', 'always'],
'@stylistic/js/no-multiple-empty-lines': ['error', { max: 1, maxEOF: 0 }],
'@stylistic/js/padding-line-between-statements': ['error',
{ blankLine: 'always', prev: ['const', 'let', 'var'], next: '*' },
{ blankLine: 'any', prev: ['const', 'let', 'var'], next: ['const', 'let', 'var'] }
],
'@stylistic/js/lines-between-class-members': ['error', 'always']
}rules: {
'@stylistic/js/eol-last': ['error', 'never'],
'@stylistic/js/no-multiple-empty-lines': ['error', { max: 0 }],
'@stylistic/js/lines-around-comment': ['error', {
beforeBlockComment: false,
beforeLineComment: false
}],
'@stylistic/js/lines-between-class-members': ['error', 'never']
}interface LineBreakRules {
'eol-last': Rule.RuleModule;
'no-multiple-empty-lines': Rule.RuleModule;
'padding-line-between-statements': Rule.RuleModule;
'lines-around-comment': Rule.RuleModule;
'lines-between-class-members': Rule.RuleModule;
'linebreak-style': Rule.RuleModule;
'newline-per-chained-call': Rule.RuleModule;
'multiline-ternary': Rule.RuleModule;
}
interface PaddingRule {
blankLine: 'always' | 'never' | 'any';
prev: StatementType | StatementType[];
next: StatementType | StatementType[];
}
interface LinesAroundCommentConfig {
beforeBlockComment?: boolean;
afterBlockComment?: boolean;
beforeLineComment?: boolean;
afterLineComment?: boolean;
allowBlockStart?: boolean;
allowBlockEnd?: boolean;
allowObjectStart?: boolean;
allowObjectEnd?: boolean;
allowArrayStart?: boolean;
allowArrayEnd?: boolean;
allowClassStart?: boolean;
allowClassEnd?: boolean;
applyDefaultIgnorePatterns?: boolean;
ignorePattern?: string;
}Install with Tessl CLI
npx tessl i tessl/npm-stylistic--eslint-plugin-js