Aliaksei
Aliaksei

Reputation: 1457

CheckStyle comments

In Idea I turn options "Comment at first column"

CheckStyle throws an error How to solve it

 Comment has incorrect indentation level 0, expected is 10, indentation should be the same level as line 139. [CommentsIndentation]

EDIT 28.06.2019

checkstyle.xml

Idea Preference

enter image description here

If block

148:            CompletableFuture.allOf(terminateEnvironmentResponseCompletableFuture, checkInvoicePaidResponseCompletableFuture,
149:                inactiveUserResponseCompletableFuture).whenComplete((v, th) -> {
151:              if (th != null) {
152:                log.error(th.getMessage(), th);
153:              }
154:              finishDelete(userDto);
155:            });

Errors:

....java:150: 'if' has incorrect indentation level 14, expected level should be 18. [Indentation]
....java:151: 'if' child has incorrect indentation level 16, expected level should be 20. [Indentation]
....java:152: 'if rcurly' has incorrect indentation level 14, expected level should be 18. [Indentation]
....java:153: 'block' child has incorrect indentation level 14, expected level should be 18. [Indentation]
....java:154: 'block rcurly' has in*correct indentation level 12, expected level should be 16. [Indentation]

Comments

108:          .withIdentity("ServicesTrigger", "TriggerGroup")
109://           is fired every day at 3:00 am
110:          .withSchedule(cronSchedule("0 0 3 * * ?"))
111://          .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(12).repeatForever())
112:          .forJob(_servicesJob)
113:          .build();
114:      _scheduler.scheduleJob(_servicesJob, serviceTrigger);

Errors:

....java:110: Comment has incorrect indentation level 0, expected is 10, indentation should be the same level as line 111. [CommentsIndentation]
....java:112: Comment has incorrect indentation level 0, expected is 10, indentation should be the same level as line 113. [CommentsIndentation]

Upvotes: 0

Views: 3779

Answers (2)

Witold Krzemiński
Witold Krzemiński

Reputation: 33

You can put comment slashes "//" right on front of commenting line text. That can fix your problem.

Your example:

108:          .withIdentity("ServicesTrigger", "TriggerGroup")
109:          //is fired every day at 3:00 am
110:          .withSchedule(cronSchedule("0 0 3 * * ?"))
111:          //.withSchedule(SimpleScheduleBuilder. etc...

Upvotes: 0

rveach
rveach

Reputation: 2201

In Idea I turn options "Comment at first column"
CheckStyle throws an error How to solve it

CommentsIndentation doesn't currently support comments being required at the first column. The default behavior is comments must be at the same indentation as the surrounding code.

If you want to see that kind of behavior from CommentsIndentation you will need to create an issue at checkstyle on github. For now, I recommend disabling the check. Either remove it from the configuration or comment it out.

Upvotes: 3

Related Questions