babel / eslint-plugin-babel

An ESlint rule plugin companion to babel-eslint
https://github.com/babel/babel-eslint
Other
389 stars 62 forks source link

No unused expressions fails with pipeline operator #174

Closed jhpratt closed 4 years ago

jhpratt commented 5 years ago

I have the following code which triggers the lint, but shouldn't.

sections_elem.requestUpdate() |> promises.push

I believe it's referring to the promises.push. It is used, as it's implicitly called with the pipeline operator.

ljharb commented 5 years ago

The result of the pipeline isn't used, though?

jhpratt commented 5 years ago

Not entirely sure what you mean. The result is being pushed onto the array, which is later awaited. This is no different than calling promises.push(sections _elem.requestUpdate()), aside from the order of execution (which is irrelevant here). As far as I'm aware, this is a perfectly valid use under the proposal.

mikestopcontinues commented 4 years ago

Here's another example, from React:

useEffect(() => {
    getAllNodes()
    |> R.filter(({meta: {type}}) => type === 'post', #)
    |> R.sortWith([R.descend(R.path(['meta', 'date']))], #)
    |> setState;
  }, []);

I think the logic should be: if the end of a pipeline is a function call, then the value is used.

MikeMcElroy commented 4 years ago

When we evaluated the pipeline operator for use on our team, we scrapped the idea because of this broken rule. It'd be awesome to see the PR above get finessed and accepted so we can start using it.

kaicataldo commented 4 years ago

Thank you for the issue. Now that @babel/eslint-plugin has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.