CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-stylistic--eslint-plugin-js

JavaScript stylistic rules for ESLint that enforce code formatting and style consistency without changing code logic.

Pending
Overview
Eval results
Files

line-breaks-newlines.mddocs/

Line Breaks and Newlines

Rules that control line breaks, empty lines, and multiline formatting for better code organization and readability.

eol-last

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 ending

Configuration:

rules: {
  '@stylistic/js/eol-last': ['error', 'always']
}

no-multiple-empty-lines

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 }]
}

padding-line-between-statements

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'] }
  ]
}

lines-around-comment

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
  }]
}

lines-between-class-members

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 
  }]
}

linebreak-style

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']
}

newline-per-chained-call

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 threshold

Configuration:

rules: {
  '@stylistic/js/newline-per-chained-call': ['error', { ignoreChainWithDepth: 2 }]
}

multiline-comment-style

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']
}

spaced-comment

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: ['-', '=', '*']
  }]
}

padded-blocks

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']
}

multiline-ternary

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 newlines

Configuration:

rules: {
  '@stylistic/js/multiline-ternary': ['error', 'always-multiline']
}

Common Line Break Combinations

Clean Code Style

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']
}

Compact Style

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']
}

Type Definitions

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

docs

array-formatting.md

code-quality-consistency.md

function-formatting.md

index.md

line-breaks-newlines.md

modern-javascript.md

object-formatting.md

plugin-configuration.md

punctuation-operators.md

spacing-indentation.md

tile.json