Re: [sonar-dev] [SONARJS] Avoid trailing whitespaces - False Positive in JS Doc comments

812 views
Skip to first unread message

Adam Gabryś

unread,
May 26, 2015, 6:59:27 AM5/26/15
to sona...@googlegroups.com
Hi,
This is not configurable, because “space after *” is a kind of standard for JSDoc, JavaDoc, etc. comments formatting.
 
 
Regards,
    Adam Gabryś
 
Sent: Tuesday, May 19, 2015 10:18 AM
To: dev
Subject: Re: [sonar-dev] [SONARJS] Avoid trailing whitespaces - False Positive in JS Doc comments
 
Hi Adam,
 
Sorry for the late reply. I don't see any reason here to make an exception for the space after the "*" in multiline comment.
Moreover, as it is configurable you could easily update the setting if this space has no specific reason to be there.
 
Best regards,
 
Linda.
 
On 18 March 2015 at 16:11, Adam Gabryś <adam....@live.com> wrote:
Hi,
Sorry, I use Eclipse formatter ;) All Eclipse formatters add space after * (Java too).
 
Regards,
    Adam Gabryś
 
Sent: Wednesday, March 18, 2015 3:04 PM
To: dev
Subject: Re: [sonar-dev] [SONARJS] Avoid trailing whitespaces - False Positive in JS Doc comments
 
Hello Adam,
 
What are you exactly talking about by "Standard JavaScript formatter"? Are you thinking about a specific tool ?
If yes which one ? Is there a specific reason why it is adding a trailing whitespace after all "*" ?
 
Thanks for your feedback,
 
Best regards,
 
Linda.
 
On 13 March 2015 at 17:56, Adam Gabryś <adam....@live.com> wrote:
Hi,
I have a block of code with JSDoc:
 
1.   /**
2.    * Method description.
3.    *
4.    * @param param1 param description.
5.    * @param param2 param description.
6.    */
7.    this.getSomething = function(param1, param2) {
8.        // body
9.    };
 
I have got an issue at the 3 line: Remove the useless trailing whitespaces at the end of this line. Standard JavaScript formatter add one space after all * (the same effects as in the JavaDoc). I think in this case it shouldn’t be markd as an issue.
 
Regards,
    Adam Gabryś
 


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

 
configuration-panel.png

Linda Martin

unread,
Jun 5, 2015, 12:43:18 PM6/5/15
to sona...@googlegroups.com
Hello Adam,


Also, I must miss something but I don't from the links you gave a mention where this space is part of the standard ?

Thank you,

Linda

Adam Gabryś

unread,
Jun 17, 2015, 9:33:59 AM6/17/15
to sona...@googlegroups.com
Hi,
Standard: “space after every star in content”:
 
/**<without space>
  *<space>text
  *<space>text
  *<space>
  *<space>text
  *<space>text
  *<space>
  *<space>@param text
  *<space>...
  */
 
I can configure formatter to remove empty lines, but then documentation is less readable (in source code).
 
Example:
/**
* Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor
* sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien
* ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros
* ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus,
* tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
*
* Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat.
*
* Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis,
* accumsan porttitor, facilisis luctus, metus.
*
* @param param Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
*/
 
is more redable than (formatter combines texts after removing empty lines):
 
/**
* Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor
* sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien
* ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros
* ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus,
* tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus.
* Morbi in sem quis dui placerat ornare. Pellentesque odio nisi, euismod in, pharetra a, ultricies in, diam. Sed arcu. Cras consequat. Praesent dapibus, neque
* id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis
* luctus, metus.
* @param param Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
*/
--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/8fb3f325-fcf9-437c-950b-41acfdb4f96d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Linda Martin

unread,
Jul 20, 2015, 11:52:44 AM7/20/15
to sona...@googlegroups.com, adam....@live.com
Hello,

In my previous answer I sent a screenshot with the eclipse configuration that allows you to remove trailing whitespace after "*" only on empty comment line and not on line of comments that contains text.

From my humble point of view I still have not seen any good reason to support this exception, so I will close this thread.

Thank you for your feedback,

Linda.

wsa...@gmail.com

unread,
Feb 4, 2016, 1:37:50 PM2/4/16
to SonarQube, adam....@live.com, linda....@sonarsource.com
Linda,

You are incorrect. Please go back and look at your screenshot. It does in fact still show that a trailing whitespace will be added on an empty block comment line. I am here facing the same issue. 

If it is going to be marked as just an eclipse issue, that is fine. But your screenshot, does not show a fix in Eclipse IDE.

Thanks in advance,
Bill

Elena Vilchik

unread,
Mar 4, 2016, 10:44:39 AM3/4/16
to SonarQube, adam....@live.com, wsa...@gmail.com
Hi Bill,

I hardly understand what you want to say: which screenshot are you talking about, what do you mean by "If it is going to be marked as just an eclipse issue"? 

Thanks

Elena VILCHIK | SonarSource
Language Team

William Santasiero

unread,
Mar 4, 2016, 12:30:44 PM3/4/16
to Elena Vilchik, SonarQube, adam....@live.com
If you go to the google group link, there is an embedded image that Linda added. The direct link to the image is here:

If you look closely, you will still see the white space after an empty *   

This is an open defect in eclipse stating that there is currently no way to get eclipse to quit adding the whitespace on jsdoc.

B

Pierre-Yves Nicolas

unread,
Mar 8, 2016, 7:22:45 AM3/8/16
to William Santasiero, Elena Vilchik, SonarQube, adam....@live.com
Hi,

I don't know how to prevent Eclipse from adding a whitespace in a jsdoc line.
However, Eclipse can be configured to automatically remove all trailing whitespaces when saving a file.
In Eclipse preferences, go to JavaScript -> Editor -> Save Actions, and in "Additional actions", check "Remove trailing whitespaces on all lines"

Inline images 1

Regards,
Pierre-Yves


wsa...@gmail.com

unread,
Mar 8, 2016, 7:49:51 AM3/8/16
to SonarQube, wsa...@gmail.com, elena....@sonarsource.com, adam....@live.com

Yes, I am familiar with that option. That option, however, still includes whitespaces in jsdoc and still causes Sonar to produce a trailing white spaces violation. 


The below image shows the whitespace still being included, even when remove trailing spaces is on. This is from Mars 4.5.1

Want to explicitly point out this is a conflict with Eclipse and the trailing whitespaces Sonar rule.

So unless you do some post processing with another tool to remove these before Sonar scans or a better IDE that handles the situation properly, this will be a hit against the rule.
-B





Pierre-Yves Nicolas

unread,
Mar 8, 2016, 11:30:04 AM3/8/16
to William Santasiero, SonarQube, Elena Vilchik, Adam Gabryś
I use Eclipse Mars 4.5.2 with JavaScript Development Tools 1.6.201.v201512010225.
When I add a new line in a jsdoc comment, a whitespace is added after the '*'.
Then, as soon as I save the file, the trailing whitespace is removed.

In the settings screen for "Additional Save Actions", I see the same "Preview" as you do, with the trailing whitespace in the jsdoc comment.
However, this "Preview" seems to be wrong: it's not consistent with the behavior I see.
I don't care about this "Preview" if the real behavior is correct.

Pierre-Yves

wsa...@gmail.com

unread,
Mar 8, 2016, 1:34:37 PM3/8/16
to SonarQube, wsa...@gmail.com, elena....@sonarsource.com, adam....@live.com
I just downloaded the latest Eclipse Mars2 J2EE distribution from the website. It has JavaScript Development Tools 1.6.201

Commented section before formatting:

/**
 * 
 * This is to test the whitespace removal in Mars2.
 * 
 * This has 5 whitespaces after     
 * This has 2 tabs after
 * 
 * 
 */

Post JS formatting with the remove whitespaces option selected
/**
 * 
 * This is to test the whitespace removal in Mars2.
 * 
 * This has 5 whitespaces after This has 2 tabs after
 * 
 * 
 */

You will notice the single whitespace are still after the *

I really have no skin in this game, so I'm going to bow out of the discussion. Hopefully others behind me won't waste too much time if they encounter said issue.

-B

wsa...@gmail.com

unread,
Mar 8, 2016, 1:38:05 PM3/8/16
to SonarQube, wsa...@gmail.com, elena....@sonarsource.com, adam....@live.com
What I found out just now, is the option alone of removing whitespaces works, if you do not have the javascript formatter enabled.  If you have a formatter enabled, the whitespaces come back.

I would need to see if fixing the formatter is an option as most want to run both options.

wsa...@gmail.com

unread,
Mar 8, 2016, 1:49:07 PM3/8/16
to SonarQube, wsa...@gmail.com, elena....@sonarsource.com, adam....@live.com
Quick glance shows no way to remove whitespaces with a JS formatter in place, fyi. JSDoc formatting in eclipse appears to add a whitespace on blank lines. One way around it is to check the remove blank lines option from the JSDoc section, but this affects readability. 

Take care, B

Pierre-Yves Nicolas

unread,
Mar 8, 2016, 4:21:55 PM3/8/16
to William Santasiero, SonarQube, Elena Vilchik, Adam Gabryś
You're right: the problem appears when "Format source code" is checked in the "Save Actions" settings.
A workaround could be to uncheck this option and manually call the formatter (ctrl+shift+F). That's not ideal.

Thank you for the investigation!

Pierre-Yves

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages