javascript icon indicating copy to clipboard operation
javascript copied to clipboard

Line exceeds 100 characters and arrow body style

Open gplusdotgr opened this issue 8 years ago • 6 comments

I have the following:

export const filteredItems = (state, filter, value) => state.items.filter(item => item.filter === value);

which gives the max-len (100) error.

When I rewrite it by changing the arrow function to the version with { } , naturally I get the error: https://github.com/airbnb/javascript#arrows--implicit-return .

What's the way around this?

gplusdotgr avatar Aug 22 '17 14:08 gplusdotgr

export const filteredItems = (state, filter, value) =>
  state.items.filter(item => item.filter === value); // new line

it looks worse but hmm yeah if you just wanna get rid of the error message

Edited: or maybe

export function filteredItems(state, filter, value) {
  return state.items.filter(item => item.filter === value);
}

luftywiranda13 avatar Aug 22 '17 14:08 luftywiranda13

@luftywiranda13 I'm definitely then disabling the rule manually.. in fact in that case I'd personally go with the arrow/brace syntax and not the one liner.

gplusdotgr avatar Aug 22 '17 14:08 gplusdotgr

@gkatsanos Here's a few options:

export const filteredItems = (state, filter, value) => (
  state.items.filter(item => item.filter === value),
);

export const filteredItems = (state, filter, value) => state.items.filter(
  item => item.filter === value,
);

export const filteredItems = ({ items }, _, value) => items.filter(({ filter }) => filter === value);

If you do have to disable a rule, disable max-len - line length limits are a really subpar proxy for managing complexity, so imo it's always ok to disable that rule.

ljharb avatar Aug 22 '17 16:08 ljharb

export const filteredItems =
  ({ items }, _, value) => items.filter(i => i.filter === value);

graingert avatar Sep 02 '17 10:09 graingert

Our style guide does not permit arbitrary linebreaks after assignment; it's always better to have too-long a line than to hit "enter" in a random place.

ljharb avatar Sep 02 '17 16:09 ljharb

Hello can you please assign it to me .i would like to work on it thankyou

alhazmultani avatar Nov 27 '23 08:11 alhazmultani