function-paren-newline

The --fix option on the command line can automatically fix some of the problems reported by this rule.

Enforces consistent line breaks inside function parentheses.

Many style guides require or disallow newlines inside of function parentheses.

Rule Details

This rule enforces consistent line breaks inside parentheses of function parameters or arguments.

Options

This rule has a single option, which can either be a string or an object.

Example configurations:

{
  "rules": {
    "function-paren-newline": ["error", "never"]
  }
}
{
  "rules": {
    "function-paren-newline": ["error", { "minItems": 3 }]
  }
}

Examples of incorrect code for this rule with the "always" option:

/* eslint function-paren-newline: ["error", "always"] */

function foo(bar, baz) {}

var foo = function(bar, baz) {};

var foo = (bar, baz) => {};

foo(bar, baz);

Examples of correct code for this rule with the "always" option:

/* eslint function-paren-newline: ["error", "always"] */

function foo(
  bar,
  baz
) {}

var foo = function(
  bar, baz
) {};

var foo = (
  bar,
  baz
) => {};

foo(
  bar,
  baz
);

Examples of incorrect code for this rule with the "never" option:

/* eslint function-paren-newline: ["error", "never"] */

function foo(
  bar,
  baz
) {}

var foo = function(
  bar, baz
) {};

var foo = (
  bar,
  baz
) => {};

foo(
  bar,
  baz
);

Examples of correct code for this rule with the "never" option:

/* eslint function-paren-newline: ["error", "never"] */

function foo(bar, baz) {}

function foo(bar,
             baz) {}

var foo = function(bar, baz) {};

var foo = (bar, baz) => {};

foo(bar, baz);

foo(bar,
  baz);

Examples of incorrect code for this rule with the default "multiline" option:

/* eslint function-paren-newline: ["error", "multiline"] */

function foo(bar,
  baz
) {}

var foo = function(
  bar, baz
) {};

var foo = (
  bar,
  baz) => {};

foo(bar,
  baz);

foo(
  function() {
    return baz;
  }
);

Examples of correct code for this rule with the default "multiline" option:

/* eslint function-paren-newline: ["error", "multiline"] */

function foo(bar, baz) {}

var foo = function(
  bar,
  baz
) {};

var foo = (bar, baz) => {};

foo(bar, baz, qux);

foo(
  bar,
  baz,
  qux
);

foo(function() {
  return baz;
});

Examples of incorrect code for this rule with the "consistent" option:

/* eslint function-paren-newline: ["error", "consistent"] */

function foo(bar,
  baz
) {}

var foo = function(bar,
  baz
) {};

var foo = (
  bar,
  baz) => {};

foo(
  bar,
  baz);

foo(
  function() {
    return baz;
  });

Examples of correct code for this rule with the "consistent" option:

/* eslint function-paren-newline: ["error", "consistent"] */

function foo(bar,
  baz) {}

var foo = function(bar, baz) {};

var foo = (
  bar,
  baz
) => {};

foo(
  bar, baz
);

foo(
  function() {
    return baz;
  }
);

Examples of incorrect code for this rule with the "multiline-arguments" option:

/* eslint function-paren-newline: ["error", "multiline-arguments"] */

function foo(bar,
  baz
) {}

var foo = function(bar,
  baz
) {};

var foo = (
  bar,
  baz) => {};

foo(
  bar,
  baz);

foo(
  bar, qux,
  baz
);

Examples of correct code for this rule with the consistent "multiline-arguments" option:

/* eslint function-paren-newline: ["error", "multiline-arguments"] */

function foo(
  bar,
  baz
) {}

var foo = function(bar, baz) {};

var foo = (
  bar
) => {};

foo(
  function() {
    return baz;
  }
);

Examples of incorrect code for this rule with the { "minItems": 3 } option:

/* eslint function-paren-newline: ["error", { "minItems": 3 }] */

function foo(
  bar,
  baz
) {}

function foo(bar, baz, qux) {}

var foo = function(
  bar, baz
) {};

var foo = (bar,
  baz) => {};

foo(bar,
  baz);

Examples of correct code for this rule with the { "minItems": 3 } option:

/* eslint function-paren-newline: ["error", { "minItems": 3 }] */

function foo(bar, baz) {}

var foo = function(
  bar,
  baz,
  qux
) {};

var foo = (
  bar, baz, qux
) => {};

foo(bar, baz);

foo(
  bar, baz, qux
);

When Not To Use It

If don't want to enforce consistent linebreaks inside function parentheses, do not turn on this rule.

Version

This rule was introduced in ESLint 4.6.0.

Resources