Immer: react compiled with warnings: Expected a default case default-case

Created on 5 Feb 2018  路  2Comments  路  Source: immerjs/immer

immer is a very good library, but when combined with the create-react-app, it warning: Expected a default case default-case, is there a good solution? Of course, if you add a blank default-case can solve this problem.

function reducer(state = {}, action) {
  return produce(state, draft => {
    switch (action.type) {
      case ACTION_A:
        break
      case ACTION_B:
        break
//    default:
    }
  })
}

Most helpful comment

Nope, (I think it is a stupid rule in the first place :). Static type
checkers can perfectly assert whether a default cause can happen or not.). Adding default is the simplest solution here.

All 2 comments

Nope, (I think it is a stupid rule in the first place :). Static type
checkers can perfectly assert whether a default cause can happen or not.). Adding default is the simplest solution here.

For this craco (https://github.com/sharegate/craco) may be an "easy" solution. I just updated my package.json like this:

    "scripts": {
-       "start": "react-scripts start",
+       "start": "craco start",
-       "build": "react-scripts build",
+       "build": "craco build",
-       "test": "react-scripts test",
+       "test": "craco test",
-       "eject": "react-scripts eject",
+       "eject": "craco eject",

And used this craco.config.js:

module.exports = {
    eslint: {
        enable:    true,
        mode:      'extends',
        configure: {
            rules: {
                'default-case': 0
            }
        },
    },
};

This seems to work pretty well with create-react-app (https://github.com/facebook/create-react-app).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vidarc picture vidarc  路  3Comments

drcmda picture drcmda  路  6Comments

FredyC picture FredyC  路  4Comments

DanielRuf picture DanielRuf  路  5Comments

steida picture steida  路  4Comments