|
Sonar 3.2 (javascript plugin) doesn't detect duplicated code in the following 2 javascript functions which are very similar except for variable names. Shouldn't Sonar detect this situation (same code but with different variable names) ? What do you think? Cheers File
1: this.finaliza = function(){ nombre_llistat = 0; codi_llistat = "<ul>"; fets_llistat_elm.find("li").each(function(i) { li_elm = $(this); input_elm = li_elm.find("input"); if (input_elm.is(":checked")) { codi_llistat += "<li><input type=\"hidden\" value=\"" + input_elm.val() + "\" />" + li_elm.find("span").text() + "</li>"; nombre_llistat++; input_elm.addClass(fetVitalDefaultClass); } else { input_elm.removeClass(fetVitalDefaultClass); }
}); codi_llistat += "</ul>"; codi_fet_txt = (nombre_llistat == 1) ? txtFet : txtFets; codi_info = (nombre_llistat == 0) ? txtNoHiHaFets + "." : "Hi ha <strong>" + nombre_llistat + " " + codi_fet_txt + "</strong>."; fets_seleccionats_elm.find("p.info").html(codi_info); fets_seleccionats_elm.find(".listaOrdenable").html(codi_llistat); fets_seleccionats_elm.slideDown(300); fets_llistat_elm.slideUp(300); // Marcamos el módulo como
modificado. this.modificado(); } File 2: this.finaliza = function(){ nombre_llistat = 0; codi_llistat = "<ul>"; materies_llistat_elm.find("li").each(function(i) { li_elm = $(this); input_elm = li_elm.find("input"); if (input_elm.attr("checked") == "checked") { codi_llistat += "<li><input type=\"hidden\" value=\"" + input_elm.val() + "\" />" + li_elm.find("span").text() + "</li>"; nombre_llistat++; input_elm.addClass(materiaDefaultClass); } else {
input_elm.removeClass(materiaDefaultClass); } }); codi_llistat += "</ul>"; codi_materia_txt = (nombre_llistat == 1) ? txtMateria : txtMateries; codi_info = (nombre_llistat == 0) ? txtNoHiHaMateries + "." : "Hi ha <strong>" + nombre_llistat + " " + codi_materia_txt + "</strong>."; materies_seleccionats_elm.find("p.info").html(codi_info); materies_seleccionats_elm.find(".listaOrdenable").html(codi_llistat); materies_seleccionats_elm.slideDown(300); materies_llistat_elm.slideUp(300); } |
|
Indeed Jaen, only literal values are anonymized but not identifiers. In your case anonymization of identifiers would be valuable but the side effect would be to generate some false positives. For instance if you anonymize all identifiers (and so also method names) the following code would also be considered as a duplication whereas this is not the case :
File 1 : a.call1(); a.call2(); a.call3(); File 2 : c.doSomething1(); c.doSomething2(); c.doSomething3();
@Evgeny, in fact if we don't anonymize method names I don't see any possible side effect. Do you share the same feeling and do you think this could be something valuable to implement ?
-----
Sonar for Continuous Inspection ---------- Forwarded message ---------- From: Enric Jaen <[hidden email]> Date: Tue, Sep 11, 2012 at 2:01 PM Subject: [sonar-user] duplication not detected To: sonar users <[hidden email]>
Sonar 3.2 (javascript plugin) doesn't detect duplicated code in the following 2 javascript functions which are very similar except for variable names.
Shouldn't Sonar detect this situation (same code but with different variable names) ? What do you think? Cheers
File
1: this.finaliza = function(){
nombre_llistat = 0;
codi_llistat = "<ul>";
fets_llistat_elm.find("li").each(function(i) {
li_elm = $(this); input_elm = li_elm.find("input"); if (input_elm.is(":checked")) {
codi_llistat += "<li><input type=\"hidden\" value=\"" + input_elm.val() + "\" />" + li_elm.find("span").text() + "</li>";
nombre_llistat++; input_elm.addClass(fetVitalDefaultClass);
} else { input_elm.removeClass(fetVitalDefaultClass);
}
}); codi_llistat += "</ul>";
codi_fet_txt = (nombre_llistat == 1) ? txtFet : txtFets;
codi_info = (nombre_llistat == 0) ? txtNoHiHaFets + "." : "Hi ha <strong>" + nombre_llistat + " " + codi_fet_txt + "</strong>.";
fets_seleccionats_elm.find("p.info").html(codi_info);
fets_seleccionats_elm.find(".listaOrdenable").html(codi_llistat); fets_seleccionats_elm.slideDown(300);
fets_llistat_elm.slideUp(300); // Marcamos el módulo como
modificado. this.modificado(); }
File 2:
this.finaliza = function(){
nombre_llistat = 0;
codi_llistat = "<ul>";
materies_llistat_elm.find("li").each(function(i) {
li_elm = $(this); input_elm = li_elm.find("input"); if (input_elm.attr("checked") == "checked") {
codi_llistat += "<li><input type=\"hidden\" value=\"" + input_elm.val() + "\" />" + li_elm.find("span").text() + "</li>";
nombre_llistat++;
input_elm.addClass(materiaDefaultClass); } else {
input_elm.removeClass(materiaDefaultClass); } });
codi_llistat += "</ul>";
codi_materia_txt = (nombre_llistat == 1) ? txtMateria : txtMateries; codi_info = (nombre_llistat == 0) ? txtNoHiHaMateries + "." : "Hi ha <strong>" + nombre_llistat + " " + codi_materia_txt + "</strong>.";
materies_seleccionats_elm.find("p.info").html(codi_info);
materies_seleccionats_elm.find(".listaOrdenable").html(codi_llistat); materies_seleccionats_elm.slideDown(300);
materies_llistat_elm.slideUp(300); }
|
|
Hi Freddy, If I correctly understand, then you want to anonymize only local identifiers (i.e. without names of methods and fields) ? If so, then indeed - it might be interesting, however hard to estimate impact without POC implementation. And of course it will mean that we would not be able to use just a tokenizer for CPD as it is now.
On Thu, Sep 13, 2012 at 1:40 AM, Freddy Mallet <[hidden email]> wrote: Indeed Jaen, only literal values are anonymized but not identifiers. In your case anonymization of identifiers would be valuable but the side effect would be to generate some false positives. For instance if you anonymize all identifiers (and so also method names) the following code would also be considered as a duplication whereas this is not the case : Best regards, Evgeny Mandrikov aka Godin <http://godin.net.ru> http://twitter.com/_godin_ |
|
Hi Evgeny,
Yep
Indeed
Yes but as performances of SSLR parsers are pretty good, parsing the source code to detect duplications is perhaps no more a blocker issue. Let's keep this idea somewhere in mind
Freddy
|
|
See my comments below:
On Wed, Sep 19, 2012 at 3:09 PM, Freddy Mallet <[hidden email]> wrote: Hi Evgeny, Just couple of months ago this wasn't the case. Moreover - SSLR wasn't used everywhere ;)
Sure.
Best regards, Evgeny Mandrikov aka Godin <http://godin.net.ru> http://twitter.com/_godin_ |
|
Should I open a jira ticket? De: Evgeny Mandrikov <[hidden email]> Para: [hidden email] Enviado: Miércoles 19 de septiembre de 2012 11:16 Asunto: Re: [sonar-user] duplication not detected See my comments below: On Wed, Sep 19, 2012 at 3:09 PM, Freddy Mallet <[hidden email]> wrote: Hi Evgeny, Just couple of months ago this wasn't the case. Moreover - SSLR wasn't used everywhere ;)
Sure.
Best regards, Evgeny Mandrikov aka Godin <http://godin.net.ru> http://twitter.com/_godin_ |
|
FYI Enric, ticket has been created : http://jira.codehaus.org/browse/SONAR-3935.
Kind regards -----
Sonar for Continuous Inspection
On Tue, Oct 30, 2012 at 3:19 PM, Enric Jaen <[hidden email]> wrote:
|
| Powered by Nabble | Edit this page |
