-
Notifications
You must be signed in to change notification settings - Fork 176
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
"Source files should not have any duplicated blocks": what about property values of object arrays? #717
Comments
@sebsnake I can't reproduce the duplication. |
Hi, thanks for your answer. createTaskListModified() {
return [{
value: 'DemoApp-Task1',
text: translate('translationPrefix.menuItems.task1'),
route: 'DemoApp_Task1',
visible: User.hasRole('ROLE_ACCESS_TASK1')
}, {
value: 'DemoApp-Task2',
text: translate('translationPrefix.menuItems.task2'),
route: 'DemoApp_Task2',
visible: User.hasRole('ROLE_ACCESS_TASK2')
}, {
value: 'DemoApp-Task3',
text: translate('translationPrefix.menuItems.task3'),
route: 'DemoApp_Task3',
visible: User.hasRole('ROLE_ACCESS_TASK3')
}, {
value: 'DemoApp-Task4',
text: translate('translationPrefix.menuItems.task4'),
route: 'DemoApp_Task4',
visible: User.hasRole('ROLE_ACCESS_TASK4')
}, {
value: 'DemoApp-Task5',
text: translate('translationPrefix.menuItems.task5'),
route: 'DemoApp_Task5',
visible: User.hasRole('ROLE_ACCESS_TASK5')
}, {
value: 'DemoApp-Task6',
text: translate('translationPrefix.menuItems.task6'),
route: 'DemoApp_Task6',
visible: User.hasRole('ROLE_ACCESS_TASK6') && this.taskIsEnabled(6)
}, {
value: 'DemoApp-Task7',
text: translate('translationPrefix.menuItems.task7'),
route: 'DemoApp_Task7',
visible: User.hasRole('ROLE_ACCESS_TASK7')
}, {
value: 'DemoApp-Task8',
text: translate('translationPrefix.menuItems.task8'),
route: 'DemoApp_Task8',
visible: User.hasRole('ROLE_ACCESS_TASK8')
}];
} Sonar tells me, that the lines 3 to 7 are duplicated by the lines 8 to 30. |
No, it's an expected behaviour. Indeed, sometimes you prefer to avoid factory functions and want to keep such object literals as they are. In this case you could ignore specific files from duplication detection. See https://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus -> "Ignore Duplications". Or you just mark issue as "won't fix" (but then duplication metric will be still the same). |
Ok, thats good to know. |
Let's assume I have something like the following JS code somewhere in my applications source files:
Sonar won't stop telling me, that (in this example) the lines starting with 'prop' are duplicated code, because it seems to ignore the values. This is just a simple example, I fairly often use these object lists, e.g. showing/hiding menu items based on given rights and so on.
So, if this IS an issue, could you please adjust it to look for values as well?
But if this is NOT an issue, please tell me, what sonars official solution for this type of problem is.
The text was updated successfully, but these errors were encountered: