admin管理员组文章数量:1296317
I am using bineReducer to bine 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, {
pleted: !statepleted
})
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 bine reducer pass argument in this sequence only how to work on this?
I am using bineReducer to bine 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, {
pleted: !state.pleted
})
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 bine reducer pass argument in this sequence only how to work on this?
Share Improve this question edited Dec 5, 2018 at 9:14 Sergeon 6,7882 gold badges27 silver badges44 bronze badges asked Dec 5, 2018 at 9:10 Roli AgrawalRoli Agrawal 2,4663 gold badges24 silver badges29 bronze badges4 Answers
Reset to default 6we 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:
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.
What if you define a default value for the second arg?
const todo = (state = {}, action = null/undefined) => {
Set action with {}
:
for example, changing the below code
const todo = (state = {}, action) => { }
to this
const todo = (state = {}, action = {}) => { }
Will be the safest way.
本文标签: javascriptsonar code smell for reducer used in combineReducerStack Overflow
版权声明:本文标题:javascript - sonar code smell for reducer used in combineReducer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741633711a2389515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论