5

I am using combineReducer to combine reducers and reducer like this

const todo = (state = {}, action) => {
  switch (action.type) {
    //...

    case 'TOGGLE_TODO':
      if (state.id !== action.id) {
        return state
      }

      return Object.assign({}, state, {
        completed: !state.completed
      })

    default:
      return state
  }
}

My problem is if i am defining reducer like that i am getting sonar code smell

Function parameters with default values should be last1

but combine reducer pass argument in this sequence only how to work on this?

Sergeon
  • 6,638
  • 2
  • 23
  • 43
Roli Agrawal
  • 2,356
  • 3
  • 23
  • 28

4 Answers4

6

we did have the same issue within our project, and sonar allows you to define exclusions for rules and files in Administration -> Congifuration -> Analysis Scope.

you will find there a section called Ignore issues on Multiple Criteria and there you can enter the rule and a "file pattern" to exclude files from this rule.

like: enter image description here

Simon Schrottner
  • 4,146
  • 1
  • 24
  • 36
1

From the Sonarqube docs:

Function parameters with default values should be last:

...But all function parameters with default values should be declared after the function parameters without default values. Otherwise, it makes it impossible for callers to take advantage of defaults; they must re-specify the defaulted values or pass undefined in order to "get to" the non-default parameters.

This does, however, work with Redux as it calls your reducer for the first time with undefined as the first argument. If you want to continue using this pattern, you'll need to disable the rule or skip that line from analysis.

djfdev
  • 5,747
  • 3
  • 19
  • 38
1

What if you define a default value for the second arg?

const todo = (state = {}, action = null/undefined) => {
Falci
  • 1,823
  • 4
  • 29
  • 54
1

Set action with {}:

for example, changing the below code

const todo = (state = {}, action) => { }

to this

const todo = (state = {}, action = {}) => { }

Will be the safest way.

Aashay Amballi
  • 1,321
  • 3
  • 17
  • 39
Aljohn Yamaro
  • 2,629
  • 25
  • 22