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

object-formatting.mddocs/

Object Formatting

Rules for consistent object literal formatting, including curly brace positioning, property spacing, and multiline object handling.

object-curly-newline

Enforces consistent line breaks after opening and before closing braces.

const objectCurlyNewline: Rule.RuleModule;

// Rule options
type ObjectCurlyNewlineOptions =
  | 'always'
  | 'never'
  | {
      ObjectExpression?: 'always' | 'never' | ObjectCurlyNewlineConfig;
      ObjectPattern?: 'always' | 'never' | ObjectCurlyNewlineConfig;
      ImportDeclaration?: 'always' | 'never' | ObjectCurlyNewlineConfig;
      ExportDeclaration?: 'always' | 'never' | ObjectCurlyNewlineConfig;
    };

interface ObjectCurlyNewlineConfig {
  multiline?: boolean;
  minProperties?: number;
  consistent?: boolean;
}

Usage Examples:

// ✓ Good with "always"
const obj = {
  name: 'John',
  age: 30
};

// ✓ Good with "never"
const obj = { name: 'John', age: 30 };

// ✓ Good with { minProperties: 2 }
const small = { name: 'John' };
const large = {
  name: 'John',
  age: 30
};

Configuration:

rules: {
  '@stylistic/js/object-curly-newline': ['error', { multiline: true, minProperties: 3 }]
}

object-curly-spacing

Enforces consistent spacing inside braces.

const objectCurlySpacing: Rule.RuleModule;

// Rule options
type ObjectCurlySpacingOptions = 
  | 'always'
  | 'never'
  | ['always' | 'never', {
      arraysInObjects?: boolean;
      objectsInObjects?: boolean;
    }];

Usage Examples:

// ✓ Good with "never" (default)
const obj = {name: 'John', age: 30};

// ✓ Good with "always"
const obj = { name: 'John', age: 30 };

// ✓ Good with custom options
const obj = {items: ['a', 'b']}; // arraysInObjects: false
const nested = {user: {name: 'John'}}; // objectsInObjects: false

Configuration:

rules: {
  '@stylistic/js/object-curly-spacing': ['error', 'always']
}

object-property-newline

Enforces placing object properties on separate lines.

const objectPropertyNewline: Rule.RuleModule;

// Rule options
type ObjectPropertyNewlineOptions = {
  allowAllPropertiesOnSameLine?: boolean;
  allowMultiplePropertiesPerLine?: boolean;
};

Usage Examples:

// ✓ Good with default settings
const obj = {
  name: 'John',
  age: 30,
  city: 'New York'
};

// ✓ Good with { allowAllPropertiesOnSameLine: true }
const obj = { name: 'John', age: 30 }; // all on same line OK
const obj = {
  name: 'John',
  age: 30
}; // or separate lines OK

// ✗ Bad mixing styles
const obj = { name: 'John',
  age: 30 }; // inconsistent

Configuration:

rules: {
  '@stylistic/js/object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }]
}

computed-property-spacing

Enforces consistent spacing inside computed property brackets.

const computedPropertySpacing: Rule.RuleModule;

// Rule options
type ComputedPropertySpacingOptions = 
  | 'always'
  | 'never'
  | ['always' | 'never', {
      enforceForClassMembers?: boolean;
    }];

Usage Examples:

// ✓ Good with "never" (default)
const value = obj[key];
const obj = { [key]: value };

// ✓ Good with "always"
const value = obj[ key ];
const obj = { [ key ]: value };

// Class members with enforceForClassMembers: true
class MyClass {
  [ key ]() {} // follows same spacing rule
}

Configuration:

rules: {
  '@stylistic/js/computed-property-spacing': ['error', 'never']
}

key-spacing

Enforces consistent spacing between keys and values in object literals.

const keySpacing: Rule.RuleModule;

// Rule options
type KeySpacingOptions = {
  beforeColon?: boolean;
  afterColon?: boolean;
  mode?: 'strict' | 'minimum';
  align?: 'value' | 'colon' | {
    beforeColon?: boolean;
    afterColon?: boolean;
    on?: 'value' | 'colon';
    mode?: 'strict' | 'minimum';
  };
  singleLine?: KeySpacingConfig;
  multiLine?: KeySpacingConfig;
};

Usage Examples:

// ✓ Good with default settings
const obj = {
  name: 'John',
  age: 30
};

// ✓ Good with { align: 'value' }
const obj = {
  name    : 'John',
  age     : 30,
  address : '123 Main St'
};

// ✓ Good with { beforeColon: true, afterColon: true }
const obj = {
  name : 'John',
  age : 30
};

Configuration:

rules: {
  '@stylistic/js/key-spacing': ['error', { beforeColon: false, afterColon: true }]
}

Common Object Formatting Combinations

Compact Objects

rules: {
  '@stylistic/js/object-curly-spacing': ['error', 'never'],
  '@stylistic/js/object-curly-newline': ['error', 'never'],
  '@stylistic/js/key-spacing': ['error', { beforeColon: false, afterColon: true }]
}

// Result:
const obj = {name: 'John', age: 30};

Spaced Objects

rules: {
  '@stylistic/js/object-curly-spacing': ['error', 'always'],
  '@stylistic/js/object-curly-newline': ['error', { multiline: true }],
  '@stylistic/js/object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }]
}

// Result:
const obj = { name: 'John', age: 30 };
const large = {
  name: 'John',
  age: 30,
  address: '123 Main St'
};

Type Definitions

interface ObjectFormattingRules {
  'object-curly-newline': Rule.RuleModule;
  'object-curly-spacing': Rule.RuleModule;
  'object-property-newline': Rule.RuleModule;
  'computed-property-spacing': Rule.RuleModule;
  'key-spacing': Rule.RuleModule;
}

interface KeySpacingConfig {
  beforeColon?: boolean;
  afterColon?: boolean;
  mode?: 'strict' | 'minimum';
}

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