Skip to content

Issue #21160: Add indentation support for module declarations - #21280

Open
sahitya0xsingh wants to merge 1 commit into
checkstyle:masterfrom
sahitya0xsingh:issue-21160-clean
Open

Issue #21160: Add indentation support for module declarations#21280
sahitya0xsingh wants to merge 1 commit into
checkstyle:masterfrom
sahitya0xsingh:issue-21160-clean

Conversation

@sahitya0xsingh

@sahitya0xsingh sahitya0xsingh commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #21160

Reason for Change:
The Indentation check currently does not provide support for enforcing indentation within Java 9 module declarations (module-info.java). Directives inside a module body (requires, exports, opens, etc.) were completely skipped because HandlerFactory had no registered handlers for MODULE_DEF and DIRECTIVE_BLOCK.

Implementation Details:

  • Created a new ModuleDirectiveHandler extending BlockParentHandler to correctly enforce standard block indentation for module body directives.
  • Registered the new handler in HandlerFactory for TokenTypes.MODULE_DEF and TokenTypes.DIRECTIVE_BLOCK.
  • Refactored ClassDefHandler to slightly reduce complexity and ensure it cleanly processes class and record structures without interfering with module definitions.
  • Added comprehensive unit tests in IndentationCheckTest.java and a corresponding InputIndentationModuleInfo.java resource file containing various correct and incorrect module indentation scenarios.
  • Updated checkstyle-resources-suppressions.xml to suppress the PackageDeclarationCheck for the new InputIndentationModuleInfo.java test file, as module-info files intentionally do not contain package declarations.

All existing and new tests pass, and full branch coverage is maintained.

Regression Test Config

Diff Regression config: https://gist.githubusercontent.com/sahitya0xsingh/09550ca20fed731f3038fbc66a61b63c/raw/regression-config.xml

@sahitya0xsingh
sahitya0xsingh force-pushed the issue-21160-clean branch 10 times, most recently from f47f59e to 9a68e36 Compare August 21, 2026 06:54
@romani

romani commented Aug 24, 2026

Copy link
Copy Markdown
Member

@vivek-0509 , please help to review .

Comment thread .ci/validation.sh Outdated
Comment on lines +1118 to +1127
PROP_CS_VERSION="checkstyleVersion"
REQ="java.util.Objects.requireNonNull"
JMS_PATH="spring-integration-jms/src/main/java/org/springframework/integration/jms"
sed -i'' "s/withPayload(converted)/withPayload($REQ(converted))/" \
$JMS_PATH/channel/AbstractJmsChannel.java
sed -i'' "s/withPayload(object)/withPayload($REQ(object))/" \
$JMS_PATH/inbound/JmsDestinationPollingSource.java
sed -i'' "s/withPayload(result)/withPayload($REQ(result))/" \
$JMS_PATH/outbound/JmsOutboundGateway.java
sed -i'' "s/withPayload(result)/withPayload($REQ(result))/" \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert unrelated changes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Thanks!

@vivek-0509

Copy link
Copy Markdown
Member

please rebase the pr

@sahitya0xsingh
sahitya0xsingh force-pushed the issue-21160-clean branch 2 times, most recently from fcff972 to 9cb28f1 Compare August 25, 2026 08:29
@sahitya0xsingh

Copy link
Copy Markdown
Contributor Author

Rebased. Ready for review. Thanks!

register(TokenTypes.OBJBLOCK, ObjectBlockHandler.class);
register(TokenTypes.INTERFACE_DEF, ClassDefHandler.class);
register(TokenTypes.IMPORT, ImportHandler.class);
register(TokenTypes.MODULE_DEF, ClassDefHandler.class);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reusing ClassDefHandler for MODULE_DEF gives wrong violation text. getHandlerName has no MODULE_DEF case and falls into default -> "interface def".

Reproduced on this branch

    module com.example.app {
        requires java.base;
    }

1:5: 'interface def ident' has incorrect indentation level 4, expected level should be 0.
3:5: 'interface def rcurly' has incorrect indentation level 4, expected level should be 0.

Please add a dedicated handler for MODULE_DEF and leave ClassDefHandler untouched, the same way PackageDefHandler and ImportHandler are separate.

@vivek-0509

Copy link
Copy Markdown
Member

False negative... when an annotation is on its own line, the line with the module keyword is never checked

@Deprecated
    module com.example.app {   // no violation on this branch

@vivek-0509

Copy link
Copy Markdown
Member

Github, generate report for Indentation/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

Report generation failed. Please check the logs for more details.

Link: https://github.com/checkstyle/checkstyle/actions/runs/33264495000

@sahitya0xsingh
sahitya0xsingh force-pushed the issue-21160-clean branch 3 times, most recently from 7cbbbb2 to 9cf9efa Compare August 30, 2026 11:37
@vivek-0509

Copy link
Copy Markdown
Member

Github, generate report for Indentation/all-examples-in-one

@github-actions

Copy link
Copy Markdown
Contributor

Report generation failed. Please check the logs for more details.

Link: https://github.com/checkstyle/checkstyle/actions/runs/33310257886

@sahitya0xsingh
sahitya0xsingh force-pushed the issue-21160-clean branch 3 times, most recently from 3d84f45 to 13e6c80 Compare August 31, 2026 05:43
@vivek-0509

Copy link
Copy Markdown
Member

@sahitya0xsingh Always run mvn clean verify do not push before running this locally to avoid CI failures

@vivek-0509

Copy link
Copy Markdown
Member

Please generate the regression report to test your changes create the config that test your changes and than generate the report

@sahitya0xsingh
sahitya0xsingh force-pushed the issue-21160-clean branch 3 times, most recently from a63fd29 to 266fc19 Compare August 31, 2026 09:28
@sahitya0xsingh

Copy link
Copy Markdown
Contributor Author

GitHub, generate report for configs in PR description

@github-actions

Copy link
Copy Markdown
Contributor

Report generation failed. Please check the logs for more details.

Link: https://github.com/checkstyle/checkstyle/actions/runs/33378028027

@github-actions

Copy link
Copy Markdown
Contributor

Failed to parse comment command.

Please ensure you've used one of the valid command formats.

Link: https://github.com/checkstyle/checkstyle/actions/runs/33380815462

@sahitya0xsingh
sahitya0xsingh marked this pull request as draft August 31, 2026 11:46
@sahitya0xsingh
sahitya0xsingh force-pushed the issue-21160-clean branch 4 times, most recently from 1aec557 to e5f77a0 Compare September 1, 2026 04:01
@sahitya0xsingh

Copy link
Copy Markdown
Contributor Author

GitHub, generate report for configs in PR description

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Report generation failed. Please check the logs for more details.

Link: https://github.com/checkstyle/checkstyle/actions/runs/33487835826

@sahitya0xsingh

Copy link
Copy Markdown
Contributor Author

GitHub, generate report for configs in PR description

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Report generation failed. Please check the logs for more details.

Link: https://github.com/checkstyle/checkstyle/actions/runs/33501128089

@sahitya0xsingh

Copy link
Copy Markdown
Contributor Author

GitHub, generate report for configs in PR description

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

@sahitya0xsingh
sahitya0xsingh marked this pull request as ready for review September 1, 2026 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indentation: no support for module declarations

3 participants