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.

no-nil doesn't seem to understand default switch case

See original GitHub issue
const reducer = (state = {}, action) => {
  switch (action.type) {
    case 'CHANGE_TEXT':
      return { text: action.payload };
    default:
      return state;
  }
};

This function will always return something, but sadly I get the error Function must end with a return statement, so that it doesn't return undefined fp/no-nil.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:7
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
kevinrenskerscommented, Oct 20, 2016

I found another construct to support: try/catch.

2reactions
vyorkincommented, Nov 2, 2016

I get this error (and fp/no-nil too) for class constructors also, .e.g:

  constructor(props) {  // <- fp/no-nil error
    super(props);
    this.state = { display: 'static' }; // <- fp/no-mutation error
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

What if I don't write default in switch case? - Stack Overflow
The code is valid. If there is no default: label and none of the case labels match the "switched" value, then none of...
Read more >
Don't Understand Default Case in Switch Statement - Activities
I don't understand how the default activity is supposed to work in Switch. My statement returns a string. I made sure that the...
Read more >
switch Statement (C) - Microsoft Learn
The default statement is executed if no case constant-expression value is equal to the value of expression . If there's no default statement, ......
Read more >
Switch statements: `default` doesn't have to be the last case
This idea is from an SO answer by JaredPar. He continues to clarify: "This means default will run if, and only if, the...
Read more >
Is it necessary to add the default case while using switch cases?
It seems there are three cases when a default statement is not necessary: no other cases are left, because there is a limited...
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