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.

Rule proposal: `space-ops`

See original GitHub issue

This proposal is continually edited. The evolution can be found here

As discussed earlier on #3587, #5553 and #3380, we need a new rule to replace space-infix-ops and space-unary-ops since it became harder to categorize new option requests as ‘infix’ or ‘unary’.

Please describe what the rule should do:

  • This rule should be the single, configurable replacement to space-infix-ops and space-unary-ops

  • This rule should be configured for each NodeType:

    ConditionalExpression, (Ternaries)

    UnaryExpression, (unary - | unary + | ! | ~ | typeof | void | delete)

    UpdateExpression, (++ | --)

    AssignmentPattern, (function(a=2) { ... })

    VariableDeclarator, (const a = 2)

    AssignmentExpression, (= | += | -= | *= | /= | %= | <<= | >>= | >>>= | |= | ^= | &=, **=)

    BinaryExpression, (== | != | === | !== | < | <= | > | >= | << | >> | >>> | + | - | * | / | % | | | ^ | & | in | instanceof, **)

    LogicalExpression, (|| | &&)

    NewExpression, (new Image(...))

    YieldExpression (function *foo () { yield (0) })

    AwaitExpression (async function foo() { await {bar: 2} })

  • The rule seems to need special cases and overrides for specific operators on top of NodeTypes. For instance we’d normally want typeof something and !someBool but since both are UnaryExpressions, it is impossible to enforce a single rule to both to achieve the desired output. For this reason the rule should also have per-operator overrides under a config key overrides: { operators: { or something.

for example:

"space-ops": ["error", {
  "AssignmentExpression": true,
  "BinaryExpression": {
    "before": true,
    "after": false
  },
  "UnaryExpression": {
    "words": true,
    "nonwords": false,
    "overrides": {
      "~": true
    }
  }
}]
  • Currently, space-infix-ops allows more than one space around operators. So this rule should also follow that.

  • While having extensive configuration options, this rule should also have at least one default configuration

Proposed Default Configuration

{
  "AssignmentExpression": true,
  "AssignmentPattern": false,
  "BinaryExpression": true,
  "ConditionalExpression": true,
  "LogicalExpression": true,
  "NewExpression": true,
  "UnaryExpression": {
    "words": true,
    "nonwords": false
  },
  "UpdateExpression": false,
  "YieldExpression": true,
  "AwaitExpression": true
}

What category of rule is this? (place an “X” next to just one item)

[x] Enforces code style

[ ] Warns about a potential error

[ ] Suggests an alternate way of doing something

[ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

Default parameter spacing: (This will add support for PEP8-style default parameter spacing, which is discussed at #3587)

"space-ops": ["error", {
  "AssignmentPattern": false
}]
// allowed
function foo(param=1) {
  /* ... */
}
// disallowed
function foo(param = 1) {
  /* ... */
}

Unary operators (UnaryExpressions / UpdateExpressions / NewExpressions / YieldExpressions / AwaitExpressions):

Non-word UnaryExpressions (!, ~, Unary + and Unary -) and Word UnaryExpressions (typeof, delete, void) can be configured explicitly.

"space-ops": ["error", {
  "UnaryExpression": {
      "words": true,
      "nonwords": false
    }
  }
]
// allowed
delete foo;
-bar

// disallowed
+ 3;
typeof!foo;

"space-ops": ["error", {
  "UpdateExpression": true
}]
// allowed
foo ++;

// disallowed
foo++;
--bar;

Infix operators (BinaryExpressions / AssignmentExpressions / Logical Expressions):

"space-ops": ["error", {
  "BinaryExpression": true,
}]
// allowed
foo + bar;
foo     + bar;

// disallowed
foo+bar;
foo +bar
foo  +bar

Both sides of infix operators can be configured explicitly

  "space-ops": ["error", {
    "LogicalExpression": {
      "before": false,
      "after": true
    }
  }]
// allowed
foo|| bar;
foo&&   bar;

// disallowed
foo     && bar;
foo||bar;
foo &&bar

Ternary operators

"space-ops": ["error", {
  "ConditionalExpression": true
}]
// allowed
foo ? "bar" : "baz";
foo   ? "bar" :     "baz";

// disallowed
foo? "bar"  : "baz";

Why should this rule be included in ESLint (instead of a plugin)?

It’s a replacement for two existing eslint core rules

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:14
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
BYKcommented, Nov 2, 2016

@not-an-aardvark okay this is a more actionable feedback so thanks a lot 😃 Now I and @onurtemizkan have some more work to make this better. 😉

2reactions
onurtemizkancommented, Jul 5, 2017

Thanks for feedbacks, @BYK @not-an-aardvark and @kaicataldo.

I have updated the proposal accordingly. This one has simpler configuration and a default configuration proposal.

Also in my opinion, with this configuration options, this rule source will probably be simpler and easier to extend than its predecessors, if we use ESQuery selectors while implementing it.

Note: I’m editing the first post but evolution of the proposal can be found here

Read more comments on GitHub >

github_iconTop Results From Across the Web

Award & Recognition Program Description - SpaceOps
Rules and Regulations for AOA, DSM, EAM, and LAM . ... The SpaceOps Secretariat shall administer the proposed SpaceOps Awards.
Read more >
Challenges and Opport - JPL Technical Report Server
temporal logic-based solution of expressing flight rules without ambiguity, and whose programmatic implementation can be automated, is proposed.
Read more >
FAA Sys Ops – Space Ops at the Command Center - FAA TV
Published on: February 9, 2018. FAA Sys Ops – Space Ops at the Command Center. Category: Aviation. Tags: airspace management plans,; ATO,; Command...
Read more >
the Tailoring of PUS-C for Future ESA Missions - AIAA ARC
One Standard to Rule Them All: the Tailoring of PUS-C for ... What is different this time, is that the GOIRD is a...
Read more >
SpaceOps-2021,13,x1234.pdf - ELIB-DLR
Instead, it was proposed to adapt the gliding windows concept ... voltage estimation, a new planning rule is defined to filter the SAR...
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