JavaScript stylistic rules for ESLint that enforce code formatting and style consistency without changing code logic.
—
Rules for consistent object literal formatting, including curly brace positioning, property spacing, and multiline object handling.
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 }]
}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: falseConfiguration:
rules: {
'@stylistic/js/object-curly-spacing': ['error', 'always']
}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 }; // inconsistentConfiguration:
rules: {
'@stylistic/js/object-property-newline': ['error', { allowAllPropertiesOnSameLine: true }]
}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']
}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 }]
}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};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'
};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