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

function-formatting.mddocs/

Function Formatting

Rules that enforce consistent formatting for function declarations, calls, and parameters, including parentheses and argument positioning.

function-call-spacing

Requires or disallows spacing between function identifiers and their invocations.

const functionCallSpacing: Rule.RuleModule;

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

Usage Examples:

// ✓ Good with "never" (default)
const result = myFunction();
const result = myFunction(arg1, arg2);

// ✓ Good with "always"
const result = myFunction ();
const result = myFunction (arg1, arg2);

// ✓ Good with { allowNewlines: true }
const result = myFunction
();

Configuration:

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

func-call-spacing

Deprecated alias for function-call-spacing. Use function-call-spacing instead.

const funcCallSpacing: Rule.RuleModule; // @deprecated

function-call-argument-newline

Enforces line breaks between arguments of a function call.

const functionCallArgumentNewline: Rule.RuleModule;

// Rule options
type FunctionCallArgumentNewlineOptions = 
  | 'always'
  | 'never'
  | 'consistent';

Usage Examples:

// ✓ Good with "always"
myFunction(
  arg1,
  arg2,
  arg3
);

// ✓ Good with "never"
myFunction(arg1, arg2, arg3);

// ✓ Good with "consistent"
myFunction(arg1, arg2); // all same line
myFunction(
  arg1,
  arg2,
  arg3
); // all separate lines

Configuration:

rules: {
  '@stylistic/js/function-call-argument-newline': ['error', 'consistent']
}

function-paren-newline

Enforces consistent line breaks inside function parentheses.

const functionParenNewline: Rule.RuleModule;

// Rule options
type FunctionParenNewlineOptions = 
  | 'always'
  | 'never'
  | 'consistent'
  | 'multiline'
  | 'multiline-arguments'
  | {
      minItems?: number;
    };

Usage Examples:

// ✓ Good with "multiline"
function short(a, b) {} // single line OK

function long(
  parameterOne,
  parameterTwo,
  parameterThree
) {} // multiline parameters require newlines

// ✓ Good with { minItems: 3 }
function few(a, b) {} // under threshold
function many(
  a,
  b,
  c
) {} // meets threshold

Configuration:

rules: {
  '@stylistic/js/function-paren-newline': ['error', 'multiline']
}

space-before-function-paren

Enforces consistent spacing before function definition opening parentheses.

const spaceBeforeFunctionParen: Rule.RuleModule;

// Rule options  
type SpaceBeforeFunctionParenOptions =
  | 'always'
  | 'never'
  | {
      anonymous?: 'always' | 'never' | 'ignore';
      named?: 'always' | 'never' | 'ignore';
      asyncArrow?: 'always' | 'never' | 'ignore';
    };

Usage Examples:

// ✓ Good with "never" (default)
function foo() {}
const bar = function() {};
const baz = () => {};

// ✓ Good with "always"
function foo () {}
const bar = function () {};
const baz = () => {};

// ✓ Good with custom config
function foo() {} // named: 'never'
const bar = function () {}; // anonymous: 'always'
const baz = async () => {}; // asyncArrow: 'never'

Configuration:

rules: {
  '@stylistic/js/space-before-function-paren': ['error', {
    anonymous: 'always',
    named: 'never',
    asyncArrow: 'always'
  }]
}

new-parens

Enforces or disallows parentheses when invoking a constructor with no arguments.

const newParens: Rule.RuleModule;

// Rule options
type NewParensOptions = 
  | 'always'
  | 'never';

Usage Examples:

// ✓ Good with "always" (default)
const person = new Person();
const date = new Date();

// ✓ Good with "never"
const person = new Person;
const date = new Date;

// Constructor with arguments always requires parens
const person = new Person('John', 30); // always required

Configuration:

rules: {
  '@stylistic/js/new-parens': ['error', 'always']
}

space-in-parens

Enforces consistent spacing inside parentheses.

const spaceInParens: Rule.RuleModule;

// Rule options
type SpaceInParensOptions = 
  | 'always'
  | 'never'
  | ['always' | 'never', {
      exceptions?: string[];
    }];

Usage Examples:

// ✓ Good with "never" (default)
function foo(arg1, arg2) {}
const result = foo(a, b);

// ✓ Good with "always"
function foo( arg1, arg2 ) {}
const result = foo( a, b );

// ✓ Good with exceptions
const result = foo(a, b); // normal call
const empty = foo(); // exception for empty

Configuration:

rules: {
  '@stylistic/js/space-in-parens': ['error', 'never']
}

Common Function Formatting Combinations

Compact Function Style

rules: {
  '@stylistic/js/function-call-spacing': ['error', 'never'],
  '@stylistic/js/space-before-function-paren': ['error', 'never'],
  '@stylistic/js/space-in-parens': ['error', 'never'],
  '@stylistic/js/function-call-argument-newline': ['error', 'consistent']
}

// Result:
function myFunction(a, b) {
  return myOtherFunction(a, b);
}

Spaced Function Style

rules: {
  '@stylistic/js/function-call-spacing': ['error', 'never'],
  '@stylistic/js/space-before-function-paren': ['error', 'always'],
  '@stylistic/js/space-in-parens': ['error', 'always'],
  '@stylistic/js/function-paren-newline': ['error', 'multiline']
}

// Result:
function myFunction ( a, b ) {
  return myOtherFunction( a, b );
}

Type Definitions

interface FunctionFormattingRules {
  'function-call-spacing': Rule.RuleModule;
  'func-call-spacing': Rule.RuleModule; // deprecated
  'function-call-argument-newline': Rule.RuleModule;
  'function-paren-newline': Rule.RuleModule;
  'space-before-function-paren': Rule.RuleModule;
  'new-parens': Rule.RuleModule;
  'space-in-parens': Rule.RuleModule;
}

interface FunctionSpacingConfig {
  anonymous?: 'always' | 'never' | 'ignore';
  named?: 'always' | 'never' | 'ignore';
  asyncArrow?: 'always' | 'never' | 'ignore';
}

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