jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • Sonar
  • SONAR-257

Add the property 'tabWidth' to the checkstyle rule 'LineLength'

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.1, 1.2, 1.2.1, 1.3
  • Fix Version/s: 1.4, 1.4.1
  • Component/s: Rules
  • Labels:
    None

Description

The sonar web frontend lacks an option to set the tabWidth property for checkstyle.

Thus if you use the sonar generated checkstyle-rules with eclipse and have eclipse set to an tabwidth other than 8 (lets say 4) you will get prompted from checkstyle in eclipse that a line is too long for printing if it is (deeply) indented. The eclipse formatter calculates with ts=4 and won't split the lines up. The checkstyle format checker calculates with ts=8 and thus hits the maximum line length before eclipse does.

The exported checkstyle.xml should be looking like this:

---- 8< ----

Index: checkstyle.xml
===================================================================
— checkstyle.xml (revision 15445)
+++ checkstyle.xml (working copy)
@@ -6,6 +6,7 @@
<property name="fileExtensions" value="properties"/>
</module>
<module name="TreeWalker">
+ <property name="tabWidth" value="4"/>
<module name="ParenPad">
<property name="severity" value="warning"/>
<property name="tokens" value="CTOR_CALL,LPAREN,METHOD_CALL,RPAREN,SUPER_CTOR_CALL"/>

---- 8< ----

Maybe this feature already implemented in a higher version of sonar?
Is there an option to enable the export of tabWidth=4 without GUI in Sonar?

  • Options
    • Sort By Name
    • Sort By Date
    • Ascending
    • Descending
    • Download All

Attachments

  1. Text File
    003_populate_database.rb.patch
    04/Jun/08 8:22 AM
    2 kB
    Eris

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Eris added a comment - 04/Jun/08 8:22 AM

This is my patch for 1_3RC1. This is useful if you start with sonar from scratch, i.e. your database is empty.

Apply

patch -p0 <003_populate_database.rb.patch

when you are in the sonar root directory.

Show
Eris added a comment - 04/Jun/08 8:22 AM This is my patch for 1_3RC1. This is useful if you start with sonar from scratch, i.e. your database is empty. Apply patch -p0 <003_populate_database.rb.patch when you are in the sonar root directory.
Hide
Permalink
Eris added a comment - 04/Jun/08 8:34 AM

If you have sonar already running and are measuring projects, this option may help you:

1) Connect to your sonar database
2) Issue some commands to get the right ids:

– find rule_id, lets say the result is 52
select id as rule_id from rules where plugin_config_key like '%LineLength%';

– find profile_id, lets say the result is 3
– Attention repeat this for all your profiles
select id as profile_id from rules_profiles where name = 'Sun checks';

– find active_rule_id (result for example: 207), insert propper values for rule_id and profile_id from your queries above
select id as active_rule_id from active_rules where rule_id = 52 and profile_id=3;

3) Now comes the meat:
– this will create you a new rules_parameter_id (lets say: 192)
insert into rules_parameters (rule_id, name, description, param_type, default_value) values(52, 'tabWidth', 'Define the tab width used for line length calculation', 'i', '8');
– finally add it to your profile as active parameter, note that I have changed the tabWidth to 4 for the project.
insert into active_rule_parameters (active_rule_id, rules_parameter_id, value) values(207, 192, '4');

At least, this does the trick.
May be there is a more elegant solution.
Please let me know.

Show
Eris added a comment - 04/Jun/08 8:34 AM If you have sonar already running and are measuring projects, this option may help you: 1) Connect to your sonar database 2) Issue some commands to get the right ids: – find rule_id, lets say the result is 52 select id as rule_id from rules where plugin_config_key like '%LineLength%'; – find profile_id, lets say the result is 3 – Attention repeat this for all your profiles select id as profile_id from rules_profiles where name = 'Sun checks'; – find active_rule_id (result for example: 207), insert propper values for rule_id and profile_id from your queries above select id as active_rule_id from active_rules where rule_id = 52 and profile_id=3; 3) Now comes the meat: – this will create you a new rules_parameter_id (lets say: 192) insert into rules_parameters (rule_id, name, description, param_type, default_value) values(52, 'tabWidth', 'Define the tab width used for line length calculation', 'i', '8'); – finally add it to your profile as active parameter, note that I have changed the tabWidth to 4 for the project. insert into active_rule_parameters (active_rule_id, rules_parameter_id, value) values(207, 192, '4'); At least, this does the trick. May be there is a more elegant solution. Please let me know.
Hide
Permalink
Eris added a comment - 05/Jun/08 6:15 AM

Version 1.3 RC1 is also affected by this issue.

Show
Eris added a comment - 05/Jun/08 6:15 AM Version 1.3 RC1 is also affected by this issue.
Hide
Permalink
Simon Brandhof added a comment - 19/Jun/08 5:20 AM

Hi Eris, sorry for the delay.
Sonar does not manage global properties, but only properties for a given rule. It's an improvement that will be planned for next releases.
In the case of the 'tabWith' property, I don't understand why it's defined as a global property on the module TreeWalker. It seems be used only by the 'LineLength' rule. In such a case the workaround is rather simple and we could fix it for the 1.4 release.
Do you confirm it ?

Show
Simon Brandhof added a comment - 19/Jun/08 5:20 AM Hi Eris, sorry for the delay. Sonar does not manage global properties, but only properties for a given rule. It's an improvement that will be planned for next releases. In the case of the 'tabWith' property, I don't understand why it's defined as a global property on the module TreeWalker. It seems be used only by the 'LineLength' rule. In such a case the workaround is rather simple and we could fix it for the 1.4 release. Do you confirm it ?
Hide
Permalink
Eris added a comment - 19/Jun/08 5:36 AM

Thanks for the feedback, Simon.
At least the LineLength rule gets upset when using the exported checkstyle.xml in Eclipse.
Thus, from my understanding, it is sufficient to fix it in the LineLength rule and not in the general case (i.e. with a global property).

regards,
Eris

Show
Eris added a comment - 19/Jun/08 5:36 AM Thanks for the feedback, Simon. At least the LineLength rule gets upset when using the exported checkstyle.xml in Eclipse. Thus, from my understanding, it is sufficient to fix it in the LineLength rule and not in the general case (i.e. with a global property). regards, Eris
Hide
Permalink
Simon Brandhof added a comment - 19/Jun/08 5:46 AM

OK, so it will be fixed on the 1.4 release. I rename the title of this issue to be more precise. Thank you for your precious feedback.

Show
Simon Brandhof added a comment - 19/Jun/08 5:46 AM OK, so it will be fixed on the 1.4 release. I rename the title of this issue to be more precise. Thank you for your precious feedback.
Hide
Permalink
Simon Brandhof added a comment - 22/Aug/08 5:11 AM

The fix does not work when migrating from a 1.3 installation. The property appears only on fresh 1.4 installations.
We fix it again on 1.4.1.

Show
Simon Brandhof added a comment - 22/Aug/08 5:11 AM The fix does not work when migrating from a 1.3 installation. The property appears only on fresh 1.4 installations. We fix it again on 1.4.1.

People

  • Assignee:
    Simon Brandhof
    Reporter:
    Eris
Vote (0)
Watch (1)

Dates

  • Created:
    03/Jun/08 3:49 AM
    Updated:
    10/Jan/12 3:13 PM
    Resolved:
    22/Aug/08 10:28 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.