question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'max-len' conflict with 'function-paren-newline'

See original GitHub issue

There currently appears to be no way to use function-paren-newline in a way that takes account of maximum line length. With the default multiline option and a function with a single long parameter name, there is no way to format the code without violating either function-paren-newline or max-len. Examples:

  1. This snippet:
export default connect(mapStateToProps, mapDispatchToProps)(
  generateDndContextWithBackend(SiteEditorContainer));

triggers the error Unexpected newline after "(".

  1. Reformatting to:
export default connect(mapStateToProps, mapDispatchToProps)(
  generateDndContextWithBackend(SiteEditorContainer),
);

triggers the error twice:

Unexpected newline after "("
Unexpected newline before ")"

  1. Removing all the newlines:
export default connect(mapStateToProps, mapDispatchToProps)(generateDndContextWithBackend(SiteEditorContainer));

Triggers the max-len error. If there is an error-free formatting solution given the current defaults, please educate me!

If this is a bug, one possibility could be to make the existing multiline option sensitive to max line length. Another could be to create a new option.

ESLint Version: 4.8.0 Node Version: 6.11.1 npm Version: 5.2.0

eslintrc

{

  "extends": "airbnb",
  "plugins": [
    "react"
  ],
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaFeatures": {
        "jsx": true
    }
  },
  "rules": {
    "jsx-a11y/click-events-have-key-events": "off",
    "jsx-a11y/anchor-is-valid": "off",
    "react/display-name": 0,
    "react/require-default-props": 0,
    "indent": ["error", 2, {"SwitchCase": 1}],
    "no-mixed-operators": ["error", {
      "groups": [
        ["+", "-", "*", "/", "%", "**"],
        ["&", "|", "^", "~", "<<", ">>", ">>>"],
        ["==", "!=", "===", "!==", ">", ">=", "<", "<="],
        ["&&", "||"],
        ["in", "instanceof"]
      ],
      allowSamePrecedence: true
    }],
    "object-curly-newline": "off"
  },
  "env": {
    "browser": true,
    "node": true,
    "es6": true,
    "amd" : true,
    "mocha": true,
    "jest": true
  }
}

This issue originally raised at https://github.com/airbnb/javascript/issues/1584

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
the-noobcommented, Nov 2, 2017

I have this bit from a create-react-app install and after upgrading to 4.10 this fails with multiline

const isLocalhost = Boolean(
  window.location.hostname === 'localhost' ||
  // [::1] is the IPv6 localhost address.
  window.location.hostname === '[::1]' ||
  // 127.0.0.1/8 is considered localhost for IPv4.
  window.location.hostname.match(
    /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/,
  ),
);
1reaction
noahgrantcommented, Jan 19, 2018

thanks, @not-an-aardvark. for posterity, i did implement my versions of the rules i commented about (array-element-newline and function-paren-newline) in a custom plugin eslint-plugin-sift.

Read more comments on GitHub >

github_iconTop Results From Across the Web

https://itacademy.mu/wp-content/plugins/svg-suppor...
... "babelUseBuiltInsType" : 0, "bowerAbbreviatedPath" : "bower_components", "bowerForceLatestOnConflict" : 1, "bowerTargetDependencyListType" : 1, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found