JavaScript stylistic rules for ESLint that enforce code formatting and style consistency without changing code logic.
—
Rules that enforce consistent formatting for function declarations, calls, and parameters, including parentheses and argument positioning.
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']
}Deprecated alias for function-call-spacing. Use function-call-spacing instead.
const funcCallSpacing: Rule.RuleModule; // @deprecatedEnforces 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 linesConfiguration:
rules: {
'@stylistic/js/function-call-argument-newline': ['error', 'consistent']
}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 thresholdConfiguration:
rules: {
'@stylistic/js/function-paren-newline': ['error', 'multiline']
}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'
}]
}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 requiredConfiguration:
rules: {
'@stylistic/js/new-parens': ['error', 'always']
}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 emptyConfiguration:
rules: {
'@stylistic/js/space-in-parens': ['error', 'never']
}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);
}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 );
}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