Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line exceeds 100 characters and arrow body style #1532

Open
gkatsanos opened this issue Aug 22, 2017 · 6 comments
Open

Line exceeds 100 characters and arrow body style #1532

gkatsanos opened this issue Aug 22, 2017 · 6 comments

Comments

@gkatsanos
Copy link

gkatsanos commented Aug 22, 2017

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?

@luftywiranda13
Copy link

luftywiranda13 commented Aug 22, 2017

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);
}

@gkatsanos
Copy link
Author

@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.

@ljharb
Copy link
Collaborator

ljharb commented Aug 22, 2017

@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.

@graingert
Copy link
Contributor

graingert commented Sep 2, 2017

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

@ljharb
Copy link
Collaborator

ljharb commented Sep 2, 2017

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.

@alhazmultani

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants