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.

`space-infix-ops`: add option for PEP8-style default parameters?

See original GitHub issue

Would it be possible to add an option to space-infix-ops to allow or enforce assignment without spaces for ES6 default parameters?

The use case for the rule - what is it trying to prevent or flag?

As of ESLint 1.2.0, space-infix-ops also applies to assignments. As such, developers who prefer to enforce spaces around assignments as per other ops but wish to omit them only in default function parameters will now receive an unwanted warning or error.

Whether the rule is trying to prevent an error or is purely stylistic

Purely stylistic, but intended to remove a false positive.

Why you believe this rule is generic enough to be included

Default parameter value assignments are different from other types of variable assignments, in that they are part of a function’s definition. This has different implications for how you read them as you scan through code. As such, developers may wish to apply different formatting rules to them according to their preferred style.

For an example from a community where this feature already exists, Python’s Style Guide (PEP8) recommends spaces around all binary operators except for when assigning default parameter values. It’s likely that developers with Python experience who are using default parameters will already be using this style.

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:6
  • Comments:36 (21 by maintainers)

github_iconTop GitHub Comments

9reactions
BYKcommented, Apr 10, 2016

Sigh, I should start working on this as a new rule as agreed above: space-ops. I’m a bit swamped but I think this belongs to core.

7reactions
insincommented, Aug 30, 2015

With ESLint 1.3.1:

Config (via eslint-config-standard):

"space-infix-ops": 2,

Code (where the function is defined on line 14):

function screen(state='search', action) {
  switch (action.type) {
    case LOGOUT:
      window.location.hash = ''
      return getDefaultSlug()
    case CHANGE_SCREEN:
      return action.slug
  }
  return state
}

Current error message:

app\ducks\screen.js
  14:22  error  Infix operators must be spaced  space-infix-ops

Naming things, that will required a sleep and/or a shower 😄 How about compactDefaultParams as an initial suggestion?

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 8 – Style Guide for Python Code
The 4-space rule is optional for continuation lines. Optional: ... Acceptable options in this situation include, but are not limited to:.
Read more >
PEP 8, why no spaces around '=' in keyword argument or a ...
I guess that it is because a keyword argument is essentially different than a variable assignment. For example, there is plenty of code...
Read more >
pep8 documentation - Read the Docs
Plugin architecture: Adding new checks is easy. ... The project options are read from the [pep8] section of the tox.ini ... pep8style =...
Read more >
autopep8 - PyPI
Automatically formats Python code to conform to the PEP 8 style guide. positional arguments: files files to format or '-' for standard in...
Read more >
How to Write Beautiful Python Code With PEP 8 - Real Python
You'll know that you've added enough whitespace so it's easier to follow logical ... PEP 8 provides two options for the position of...
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