Skip to content

feat(#174660): add new code conventions rules - #1

Open
kirill-pyatunin wants to merge 6 commits into
clutcher:mainfrom
kirill-pyatunin:174660
Open

feat(#174660): add new code conventions rules#1
kirill-pyatunin wants to merge 6 commits into
clutcher:mainfrom
kirill-pyatunin:174660

Conversation

@kirill-pyatunin

Copy link
Copy Markdown

No description provided.


String getApplicationRoot();

default String getDomainModelPackageMatcher() {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

check. it should already exists in configs

.allowEmptyShould(true);
}

public static ArchRule ruleForCrossModuleDomainIsolation(String moduleBasePackage, HexagonalArchitectureSettings properties) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

remove

.allowEmptyShould(true);
}

public static ArchRule ruleForDomainModelNotExposedInDrivingAdapters(String moduleBasePackage, HexagonalArchitectureSettings properties) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Check rule *Test that domain.model is not used to be returned from in rest controller - only for controllers

@kirill-pyatunin kirill-pyatunin Apr 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

*Mapper class
mappers package?

.allowEmptyShould(true);
}

static DescribedPredicate<JavaClass> areNotAnnotatedWithAnyOf(String[] annotationNames) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

not arch rule - move

moduleBasePackage + properties.getDomainModelPackageMatcher(),
"java..",
"lombok..",
"org.springframework.stereotype..",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

    • too wide. component and service

};
}

public static ArchRule ruleForNoAutowiredInDomain(String moduleBasePackage, HexagonalArchitectureSettings properties) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

remove.

.allowEmptyShould(true);
}

public static ArchRule ruleForNoAutowiredFieldsInDomain(String moduleBasePackage, HexagonalArchitectureSettings properties) {

@kirill-pyatunin kirill-pyatunin Apr 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

!

.allowEmptyShould(true);
}

public static ArchRule ruleForDomainModelOnlyRecordsOrPojos(String moduleBasePackage, HexagonalArchitectureSettings properties) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

should check records or pojos

.allowEmptyShould(true);
}

public static ArchRule ruleForSpringAdapterNaming(String moduleBasePackage, HexagonalArchitectureSettings properties) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

!

}


// --- Custom ArchConditions ---

@kirill-pyatunin kirill-pyatunin Apr 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

move ArchConditions

import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses;

public class CodeConventionsRulesLibrary {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

create interface.
Create property to allow on/off or redefine rules, add rule

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

id rule = true / false, true by default (exmpl)

@@ -0,0 +1,24 @@
dev:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

remove

Comment thread build.gradle.kts
extra["springBootVersion"] = "3.5.3"
extra["springModulithVersion"] = "2.0.3"
extra["springBootVersion"] = "4.0.2"
extra["archUnitVersion"] = "1.4.1"

@kirill-pyatunin kirill-pyatunin Apr 23, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

142 ver

public static ArchRule ruleForNoDtoInClassNames(String domainPackage) {
return noClasses()
.that().resideInAPackage(domainPackage)
.should().haveSimpleNameContaining("Dto")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is it case sensitive? Suppose we should check DTO also? And what about Data? Suppose we should exclued that also.

return classes()
.that().resideInAPackage(moduleBasePackage + properties.getDomainModelPackageMatcher())
.should().onlyDependOnClassesThat()
.resideInAnyPackage(allPackages)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is it working properly? Does it allow to use domain classes inside domain itself?

String domainModelPackage = moduleBasePackage + properties.getDomainModelPackageMatcher();
return classes()
.that().areAnnotatedWith("org.springframework.web.bind.annotation.RestController")
.or().areAnnotatedWith("org.springframework.stereotype.Controller")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Does it also covers graphql controllers?

public static ArchRule ruleForDomainModelOnlyRecordsOrPojos(String moduleBasePackage, HexagonalArchitectureSettings properties) {
return classes()
.that().resideInAPackage(moduleBasePackage + properties.getDomainModelPackageMatcher())
.should().notBeInterfaces()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It is wrongly working. Pojo is a specific class with fields and getter/setter naming convention. Checkin on not interface is not enough.


ApiForCustomizingArchRuleCreation withDevStandardsRule(RuleProvider provider);

ApiForCustomizingArchRuleCreation withCodeConventionsRule(ApiForArchRuleCreation apiForArchRuleCreation);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can you remind me difference between dev standards rules and code convetion rules? Looks same for me.

Also we need to update both readme and claude with all new changes.

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.

2 participants