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

array-formatting.mddocs/

Array Formatting

Rules that control the formatting and styling of JavaScript arrays, including bracket spacing, newlines, and element positioning.

array-bracket-newline

Enforces linebreaks after opening and before closing array brackets.

const arrayBracketNewline: Rule.RuleModule;

// Rule options
type ArrayBracketNewlineOptions = 
  | 'always' 
  | 'never' 
  | 'consistent'
  | {
      multiline?: boolean;
      minItems?: number | null;
    };

Usage Examples:

// ✓ Good with "always"
const items = [
  'apple',
  'banana'
];

// ✓ Good with "never"
const items = ['apple', 'banana'];

// ✓ Good with { multiline: true }
const items = ['apple', 'banana']; // single line ok
const items = [
  'apple',
  'banana'
]; // multiline requires brackets on new lines

Configuration:

rules: {
  '@stylistic/js/array-bracket-newline': ['error', 'consistent']
}

array-bracket-spacing

Enforces consistent spacing inside array brackets.

const arrayBracketSpacing: Rule.RuleModule;

// Rule options
type ArrayBracketSpacingOptions = 
  | 'always'
  | 'never'
  | ['always' | 'never', {
      singleValue?: boolean;
      objectsInArrays?: boolean;
      arraysInArrays?: boolean;
    }];

Usage Examples:

// ✓ Good with "never" (default)
const items = ['apple', 'banana'];

// ✓ Good with "always"
const items = [ 'apple', 'banana' ];

// ✓ Good with custom options
const items = ['apple', 'banana']; // singleValue: false
const nested = [[ 'nested' ]]; // arraysInArrays: false

Configuration:

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

array-element-newline

Enforces line breaks after each array element.

const arrayElementNewline: Rule.RuleModule;

// Rule options
type ArrayElementNewlineOptions =
  | 'always'
  | 'never'
  | 'consistent'
  | {
      multiline?: boolean;
      minItems?: number | null;
    };

Usage Examples:

// ✓ Good with "always"
const items = [
  'apple',
  'banana',
  'cherry'
];

// ✓ Good with "never"
const items = ['apple', 'banana', 'cherry'];

// ✓ Good with { minItems: 3 }
const small = ['a', 'b']; // under threshold, no newlines required
const large = [
  'apple',
  'banana', 
  'cherry'
]; // meets threshold, newlines required

Configuration:

rules: {
  '@stylistic/js/array-element-newline': ['error', { minItems: 3 }]
}

Common Array Formatting Combinations

Here are some popular combinations for array formatting:

Compact Arrays

rules: {
  '@stylistic/js/array-bracket-spacing': ['error', 'never'],
  '@stylistic/js/array-bracket-newline': ['error', 'never'],
  '@stylistic/js/array-element-newline': ['error', 'never']
}

// Result:
const items = ['apple', 'banana', 'cherry'];

Multiline Arrays

rules: {
  '@stylistic/js/array-bracket-spacing': ['error', 'never'],
  '@stylistic/js/array-bracket-newline': ['error', { multiline: true }],
  '@stylistic/js/array-element-newline': ['error', { minItems: 3 }]
}

// Result:
const short = ['a', 'b'];
const long = [
  'apple',
  'banana',
  'cherry'
];

Type Definitions

// Complete type definitions for array rules
interface ArrayBracketNewlineRule {
  meta: {
    type: 'layout';
    docs: { description: string };
    fixable: 'whitespace';
    schema: JSONSchema4[];
  };
  create(context: Rule.RuleContext): Rule.RuleListener;
}

interface ArrayFormattingRules {
  'array-bracket-newline': ArrayBracketNewlineRule;
  'array-bracket-spacing': Rule.RuleModule;
  'array-element-newline': Rule.RuleModule;
}

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